Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 1.59 KB | None | 0 0
  1. function Histogram = MakeHistogramRGB(InputImage, n)
  2.     [height width] = size(InputImage);
  3.     Histogram = zeros(1, 255);
  4.  
  5.     for i = 1 : height
  6.         for j = 1 : width
  7.             Start = 0;
  8.             End = 255 / n;
  9.             for k = 1 : n
  10.                 for l = 1 : 3
  11.                     tmp = InputImage(i, j) - 1;
  12.                     if (tmp >= Start & tmp <= End)
  13.                         avg = ((Start + End) / 2);
  14.                         uint8(avg);
  15.                         Histogram(avg) = Histogram(avg) + 1;
  16.                     end
  17.                     Start = Start + End;
  18.                     End = End + End;
  19.                 end
  20.             end
  21.         end
  22.         printf("%d\n",double(i/height)*100);
  23.     end
  24. endfunction
  25.  
  26. function Histogram = MakeHistogramGray(InputImage, n)
  27.     [height width] = size(InputImage);
  28.     Histogram = zeros(1, 255);
  29.  
  30.     for i = 1 : height
  31.         for j = 1 : width
  32.             Start = 0;
  33.             End = 255 / n;
  34.             for k = 1 : n
  35.                 tmp = InputImage(i, j) - 1;
  36.                 if (tmp >= Start & tmp <= End)
  37.                     avg = ((Start + End) / 2);
  38.                     uint8(avg);
  39.                     Histogram(avg) = Histogram(avg) + 1;
  40.                 end
  41.                 Start = Start + End;
  42.                 End = End + End;
  43.             end
  44.         end
  45.         printf("%d\n",double(i/height)*100);
  46.     end
  47. endfunction
  48.  
  49. global IPD_PATH;
  50. RGB = ReadImage(IPD_PATH + 'demos\teaset.png');
  51. Gray = RGB2Gray(RGB);
  52. scf(1); ShowImage(Gray, 'RGB');
  53.  
  54. hist=MakeHistogramGray(Gray,100);
  55. scf(2);plot(hist);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement