document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. %{
  2. Perform grayscale slicing , keeping the background preserved
  3.  
  4. %}
  5. im=imread(\'penguins.jpg\');
  6. %step 1: convert to grayscale
  7. gray=rgb2gray(im);
  8. copy=gray;
  9. [m,n]=size(gray);
  10. %let us slice between the range 150-200
  11. for i=1:m
  12.     for j=1:n
  13.         if gray(i,j)>=180 && gray(i,j)<=200
  14.            gray(i,j)=255;
  15.         end
  16.     end
  17. end
  18. subplot(2,2,[1 2]),imshow(copy),title(\'Original\');
  19. subplot(2,2,[3 4]),imshow(gray),title(\'Greyscale sliced keeping background\');
');