b) Write a c that will drop every second pixel. Row-wise: you retain one pixel,
ID: 3561469 • Letter: B
Question
b) Write a c that will drop every second pixel. Row-wise: you retain one pixel, and then you drop the next pixel, until you reach the end of that row. Column-wise: you retain one pixel, and you drop the next pixel, until you reach the end of that column. Your image should therefore be a quarter of its original size. [NOTE: Take the grayscale image obtained from Q1. If the last digit of your student ID number is odd, please drop the odd pixel locations; otherwise drop the even pixels] [Display the new quarter image].
Explanation / Answer
MAtlab code save the following code as a name drop_pixel.m
------------------------------------------------------------------------------------------------
function drop_pixel(image)
im=imread(image);
s=size(im);
x=0;
y=0;
if mod(s(1),2)==0
x=s(1)/2;
else
x=(s(1)+1)/2;
end
if mod(s(2),2)==0
y=s(2)/2;
else
y=(s(2)+1)/2;
end
drop_im=im(1:2:x,1:2:y);
imshow(drop_im)
end
-----------------------------------------------------------------------------
call the programme from command window. for example-
>> drop_pixel('picture.jpg')
% note the input image should be grayscale image.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.