purxiz

Untitled

Oct 22nd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.50 KB | None | 0 0
  1. % equalize takes an image, displays it's histogram, generates a transform,
  2. % transforms (and outputs) the equalized image, and displays it's
  3. % histogram, and it's mean and Standard Deviation
  4. %
  5. % Syntax:
  6. % equalize(image)
  7. %
  8. % Input: an mxn grayscale image as a uint8 matrix
  9. %
  10. % Output:
  11. % an image of size mxn and type uint8
  12. %
  13. % History:
  14. % Nikolai Norona created and finished 10/22
  15. function equalize = equalize(image)
  16.     M = size(image,1);
  17.     N = size(image,2);
  18.     %plots hist of input image
  19.     hist = compute_histogram(image);
  20.     plot_histogram(hist);
  21.     figure();
  22.     T = histogram_transform(hist);
  23.     %round T because it needs to represent real pixel values, not doubles
  24.     T = round(T);
  25.     equalize = zeros([M N],'uint8');
  26.     %iterate through old image, using T to assign values to new image
  27.     for i = 1:M
  28.         for j = 1:N
  29.             equalize(i,j) = T(image(i,j)+1);
  30.         end
  31.     end
  32.     %display histogram of new image
  33.     hist2 = compute_histogram(equalize);
  34.     plot_histogram(hist2);
  35.     %mean and standard deviation of equalized image
  36.     %code section written in collaboration with Jonathan Garache
  37.     equalizedImage = double(equalize(:));
  38.     inputImage = double(image(:));
  39.     A = ['mean: ', num2str(mean(inputImage)), ' standard deviation: ', num2str(std(inputImage))];
  40.     B = ['mean: ', num2str(mean(equalizedImage)), ' standard deviation: ', num2str(std(equalizedImage))];
  41.     disp('orignal image:');
  42.     disp(A);
  43.     disp('new image:');
  44.     disp(B);
  45. end
Advertisement
Add Comment
Please, Sign In to add comment