Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Image linear interpolation with Matlab. I am attempting to reconstruct a down sa

ID: 3863616 • Letter: I

Question

Image linear interpolation with Matlab.

I am attempting to reconstruct a down sampled grayscale image using interp1. I have this code but I am confused to why it is not working. I am getting an error on line 4. Basically, what do I need to put in place of the image name in line 4?

[r_L,col_L]=size(image); %generalize so it works for any image
r3i = 1:(1/3):r_L; % locations between the row indices are created
c3i = 1:(1/3):col_L; %-- locations between the column indices are created

%Error occurs here
xxrowi=interp1(1:1:r_L,image,r3i);%interpolation on image width
xxlinear=interp1(1:1:col_L,xxrowi',c3i);
%transposing allows one to interpolate on a length
xxlinear=xxlinear'; %retransposing image vector
show_img(xxlinear)

It can work with any image but first we need to change it to grayscale and downsample by a factor of 3.

image_bw=rgb2gray(image);

image_DS=downsample(image,3);

Explanation / Answer

Your code is not working beccause image is 2D array, but interp1 works with 1D array. I have written a sample prog. This will show you how to remove the errors.

[r_L,col_L]=size(image); %generalize so it works for any image
r3i = 1:(1/3):r_L; % locations between the row indices are created
c3i = 1:(1/3):col_L; %-- locations between the column indices are created

xxrowi = rand(r_L,col_L*3-2);
%Error occured here
for i = 1:r_L
xxrowi(i,:)=interp1(1:1:r_L,image(i,:),c3i);%interpolation on image width
end
xxlinear=rand(r_L*3-2,col_L*3-2);
for i = 1:col_L*3-2
xxlinear(:,i)=(interp1(1:1:col_L,xxrowi(:,i)',r3i))';
end
%transposing allows one to interpolate on a length
xxlinear=xxlinear'; %retransposing image vector
show_img(xxlinear)