document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. %% loading an image
  2. real = imread(\'x.jpg\');
  3. real1=real;
  4. %%showing the image
  5. figure,imshow(real),title(\'Original Image\');
  6. %%showing in m*n*3 format
  7. [m,n,shape]= size(real);
  8. %%slicing the matrices to get the individual planes
  9. red=real(:,:,1);
  10. green=real(:,:,2);
  11. blue=real(:,:,3);
  12.  
  13. %%creating a canvas :
  14. canvas=zeros(m,n);
  15. array=zeros(256,1);
  16.  
  17. %%now looping to get the maximum from the planes
  18. for i=1:m
  19.     for j=1:n
  20.         for k=1:3
  21.             val=max(real(i,j,k));
  22.         end
  23.         canvas(i,j)= val; %inserting the max val in the new canvas
  24.     end
  25. end
  26. %uint8 was used to convert it to a specific type for displaying
  27. figure,imshow(uint8(canvas)),title(\'Greyscale\');
  28. histo = uint8(canvas);
  29.  
  30.  
  31.  
  32. for i=0:255
  33.     for j=1:m
  34.         for k=1:n
  35.            if i==histo(j,k)
  36.                array(i+1)=array(i+1)+1;
  37.            end
  38.         end
  39.     end
  40. end
  41. disp(array);
  42. figure,plot(array),title(\'Our Histogram\');
  43. % h contains the histogram created by the inbuilt function
  44. h=imhist(histo);
  45. figure,plot(h),title(\'Histogram using imhist\');
');