Question

When images are scaled or resized, the values between pixels need to be guessed/interpolated in order to fill in the missingclear all: clc: img1-double (imread (rice.jpg)) img1-mat2gray(img1); %convert to grayscale imshow (imgl) scale-1.7; % speci

Whats wrong with my code? Please use MATLAB and can you answer the questions too.

When images are scaled or resized, the values between pixels need to be guessed/interpolated in order to fill in the missing gaps. Write a function that takes a grayscale image (pick your own image) and a scaling factor (any positive decimal value) as input and resizes the image using the following methods; a) Nearest neighbouring pixel b) Linear interpolation (in x-direction first, then y-direction) c) Bilinear interpolation Output the resulting image for each of the three methods. Test out your function with x2 scaling, x5.8 scaling, and for x0.3 scaling (9 images total). You are not allowed to use the built-in
clear all: clc: img1-double (imread ('rice.jpg")) img1-mat2gray(img1); %convert to grayscale imshow (imgl) scale-1.7; % specify the required scale [rows, cols-size (ingl ); % determine size of the image nrow3=round (rows. *scale); % determines the number of new rows ncol3=round (cols. *scale); % determines the number of new columns [x,y]=meshgrid ( 1: rows, 1: cols); % determines coordinates of image xx-linspace (1, rows, nrows); % divide the original image using the new rows yy=linspace (1, cols, ncols); % divide the original image using the new columns [xnew, ynew]=meshgrid (xx,yy); % find the coordinates using the new rows & co13 img1-splin-interp2(x, y, img1, xnew, ynew, 'spline') % interpolate the new image imshow (img1 spline) 10 - 12 13 14 15 16 Command Window Error using Transpose on ND array is not defined. Use PERMUTE instead. Error in interp2 (line 130) Error in test (line 15) ing 1 3pline-interp2(x, y, img 1, xnew, ynew, 'spline') % interpolate the new image
1 0
Add a comment Improve this question Transcribed image text
Answer #1

a) Nearest Neighbouring pixel

MATLAB function for Nearest Neighbouring Pixel where image and scale are considered as input.

Save the file name as rice_Scale.m

function rice_Scale(file, scale)  

A=imread(file); %READ THE INPUT IMAGE

%OBTAIN THE INTERPOLATED POSITIONS

IR = ceil([1:(size(A,1)*scale)]./(scale));

IC = ceil([1:(size(A,2)*scale)]./(scale));

%ROW_WISE INTERPOLATION

B = A(:,IR);

%COLUMN-WISE INTERPOLATION

B = B(IC,:);

imshow(B)

end

b) Linear Interpolation (In x-direction first the y-direction)

MATLAB function for Linear Interpolation (In x-direction first and the y-direction) where image and scale are considered as input.

Save the file name as rice_Scale.m

function rice_Scale(file, scale)
a=imread(file); %import image"y.jpg"
[row col d] = size(a); %3 dimentional array
zr=scale*row;
zc=scale*col;

for i=1:zr
x=i/scale;
x1=floor(x);
x2=ceil(x);
if x1==0
x1=1;
end
xint=rem(x,1);
for j=1:zc
y=j/scale;
y1=floor(y);
y2=ceil(y);
if y1==0
y1=1;
end
yint=rem(y,1);

BL=a(x1,y1,:);
TL=a(x1,y2,:);
BR=a(x2,y1,:);
TR=a(x2,y2,:);

R1=BR*yint+BL*(1-yint);
R2=TR*yint+TL*(1-yint);

im_zoom(i,j,:)=R1*xint+R2*(1-xint);
end
end
imshow(im_zoom);
end

Add a comment
Know the answer?
Add Answer to:
When images are scaled or resized, the values between pixels need to be guessed/interpolated in o...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The ACME Manufacturing Company has hired you to help automate their production assembly line. Cameras have...

    The ACME Manufacturing Company has hired you to help automate their production assembly line. Cameras have been placed above a conveyer belt to enables parts on the belt to be photographed and analyzed. You are to augment the system that has been put in place by writing C code to detect the number of parts on the belt, and the positions of each object. The process by which you will do this is called Connected Component Labeling (CCL). These positions...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT