%{
Perform grayscale slicing , keeping the background preserved
%}
im=imread(\'penguins.jpg\');
%step 1: convert to grayscale
gray=rgb2gray(im);
copy=gray;
[m,n]=size(gray);
%let us slice between the range 150-200
for i=1:m
for j=1:n
if gray(i,j)>=180 && gray(i,j)<=200
gray(i,j)=255;
end
end
end
subplot(2,2,[1 2]),imshow(copy),title(\'Original\');
subplot(2,2,[3 4]),imshow(gray),title(\'Greyscale sliced keeping background\');