Advertisement
iampiergiu

negative.m

Oct 1st, 2011
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.77 KB | None | 0 0
  1. %Nioi Pier Giuliano
  2. %creates negative of grayscale image
  3. %
  4. %function usage
  5. %    imshow(negative(imread('cameraman.tif')));
  6. %
  7. %
  8.  
  9. function immNeg=negative(image)
  10. %create output image of the same size as the input image
  11. [rows,cols]=size(image);
  12. immNeg=zeros(rows,cols);
  13.  
  14. %conversion for working double
  15. %values range in [0,1] , instead of [0,255]
  16. image=im2double(image);
  17.  
  18. %finding max and min gray level value
  19. max_gray=max(max(image));
  20.  
  21. %We must do the mapping keeping in mind to consider also graylevels not
  22. %used in the image
  23. %In this way we are sure to have a completely reversed histogram
  24. %trasformation
  25. for i=1:rows
  26.     for j=1:cols
  27.         immNeg(i,j)=max_gray - image(i,j)  + (1.0-max_gray);
  28.     end
  29. end
  30.  
  31. %conversion back to uint8
  32. immNeg=im2uint8(immNeg);
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement