Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.32 KB | None | 0 0
  1. clc;
  2. clear ;
  3. tic;
  4. input_image=imread('test3.bmp');
  5. input_image = rgb2gray(input_image);
  6. %input_image = double(input_image);
  7. a=uint8(2);
  8. beta=uint8(2);
  9. sum1=0;
  10. cnt = uint8(0);
  11. difference = uint64(0);
  12. histogram_of_image = zeros(1,256); %creata an array for histogram
  13. [width,height] = size(input_image); %width and heigth of image
  14.  
  15. figure;
  16. plot(imhist(input_image));
  17. title('Original Histogram');
  18. histogram_of_image = imhist(input_image);
  19.  
  20. modified_histogram = zeros(1,256);
  21.  
  22. for i=1:256
  23.   modified_histogram(i)  = (log( histogram_of_image(i)+double(a)))^double(beta);
  24. end
  25.  
  26. figure('Name','Modified Histogram');
  27. plot(modified_histogram);
  28.  
  29.  
  30. for i=1:256
  31.     if(modified_histogram(i)~=0)
  32.         sum1 = sum1 + (modified_histogram(i));
  33.         cnt = cnt + 1;
  34.     end
  35. end
  36.  
  37. tcl = sum1/cnt;
  38.  
  39. clipped_histogram = zeros(1,256);
  40. for i=1:256
  41.     if((modified_histogram(i)) >= tcl)
  42.     clipped_histogram(i) = tcl;    
  43.     else
  44.     clipped_histogram(i) = (modified_histogram(i));  
  45.    end
  46. end
  47.  
  48.    figure('Name','Clipped Modified Histogram');
  49.    plot(clipped_histogram);
  50.  
  51. PDa = zeros(1,256);
  52. for i=1:256
  53.  PDa(i) = clipped_histogram(i) / (sum(clipped_histogram));
  54. end
  55.  
  56. CDa = zeros(1,256);  %create CDa in formula
  57. CDa(1) = PDa(1) ;
  58. for i=2:256
  59.      CDa(i) =  PDa(i) +  CDa(i-1);  
  60. end
  61.  
  62.  
  63. value_after_enhancement =  zeros(1,256);
  64. for i=1:256
  65.      value_after_enhancement(i) = (255 * CDa(i));
  66. end
  67.  
  68.  
  69. b=uint8(0);
  70. output_image=zeros(width,height);
  71. for i=1:width %map new value
  72.     for j=1:height
  73.             b = input_image(i,j);
  74.             output_image(i,j) =   value_after_enhancement(b);
  75.     end
  76. end
  77.  
  78.  
  79. original_result=imread('testsonuc3.bmp');
  80. original_result=double(rgb2gray(original_result));
  81. image_of_dif= zeros(width,height);
  82. for i=1:width %map new value
  83.     for j=1:height
  84.         d = (output_image(i,j));
  85.         e = (original_result(i,j));
  86.         difference = difference + uint64(abs(d-e));
  87.        piksel_farki=e-d;
  88.         %i has casted to uint64, because type of difference is also uint64    
  89.         image_of_dif(i,j)= abs(d-e);  
  90.        
  91.     end
  92. end
  93.  
  94. figure;
  95. imshow(uint8(output_image));
  96. title('My Result');
  97.  
  98.  
  99. figure;
  100. imshow(uint8(original_result));
  101. title('Original Result');
  102.  
  103. figure;
  104. imshow(uint8(image_of_dif));
  105. title('Difference of original result and my result');
  106. toc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement