Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. //////////////////cumulatedHist//////////////////////
  2. function [H, x, C] = cumulatedHist(hist)
  3. [H, x] = imhist(hist);
  4. tmpC = cumsum(H);
  5. k = max(tmpC)/max(H);
  6. C = tmpC/k;
  7. end
  8.  
  9. ///////////////////zA//////////////////////////////
  10. clearvars;
  11. close all;
  12. clc;
  13.  
  14. %% Read images
  15. lena1 = imread("lena1.bmp");
  16. lena2 = imread("lena2.bmp");
  17. lena3 = imread("lena3.bmp");
  18. lena4 = imread("lena4.bmp");
  19.  
  20. %% create histograms
  21. hist1 = imread('hist1.bmp');
  22. hist2 = imread('hist2.bmp');
  23. hist3 = imread('hist3.bmp');
  24. hist4 = imread('hist4.bmp');
  25.  
  26. %% formatted images
  27. figure(1);
  28. subplot(2,4,1);
  29. imshow(lena1);
  30. subplot(2,4,5);
  31. imhist(lena1, 256);
  32.  
  33. subplot(2,4,2);
  34. imshow(lena2);
  35. subplot(2,4,6);
  36. imhist(lena2, 256);
  37.  
  38. subplot(2,4,3);
  39. imshow(lena3);
  40. subplot(2,4,7);
  41. imhist(lena3, 256);
  42.  
  43. subplot(2,4,4);
  44. imshow(lena4);
  45. subplot(2,4,8);
  46. imhist(lena4, 256);
  47.  
  48. %% histogram 1
  49.  
  50. figure(2);
  51. subplot(2, 1, 1);
  52. imshow(hist1)
  53. subplot(2, 1, 2);
  54. imhist(hist1, 256);
  55.  
  56. %% adjusted histogram 1
  57.  
  58. figure(3);
  59. adjustedHist1 = imadjust(hist1);
  60. subplot(2,1,1);
  61. imshow(adjustedHist1);
  62. subplot(2,1,2);
  63. imhist(adjustedHist1, 256);
  64. title("adjusted histogram 1");
  65.  
  66. %% cumulated histogram
  67.  
  68. [H, x, C2] = cumulatedHist(hist1);
  69. figure(4);
  70. subplot(1,2,1);
  71. imshow(hist1);
  72. subplot(1,2,2);
  73. plot(x,H);
  74. hold on;
  75. plot(x, C2);
  76. title('cumulated histogram');
  77.  
  78. %% LUT
  79.  
  80. lut = uint8(255*(C2/max(C2)));
  81. [Hlut, xlut] = imhist(intlut(hist1, lut),256);
  82. tmpC = cumsum(Hlut);
  83. k = max(tmpC) / max(Hlut);
  84. Clut = tmpC / k;
  85.  
  86. figure(4);
  87. subplot(4, 1, 1);
  88. imshow(intlut(hist1, lut));
  89. title('LUT converted');
  90.  
  91. subplot(4,1,2);
  92. histeq(hist1, 256);
  93. title('histeq treated');
  94.  
  95. subplot(4,1,3);
  96. plot(xlut, Hlut);
  97. title('histogram');
  98.  
  99. subplot(4,1,4);
  100. plot(xlut, Clut);
  101. title('cumulated histogram');
  102.  
  103. % hist2 image
  104. figure(5);
  105. subplot(4,4,1); imshow(hist2);
  106. title('null');
  107. subplot(4,4,2); imshow(imadjust(hist2));
  108. title('adjusted');
  109. subplot(4,4,3); imshow(histeq(hist2));
  110. title('histeq treated');
  111. subplot(4,4,4); imshow(adapthisteq(hist2));
  112. title('adapthisteq treated');
  113. %%
  114. % hist3 image
  115. subplot(4,4,5); imshow(hist3);
  116. subplot(4,4,6); imshow(imadjust(hist3));
  117. subplot(4,4,7); imshow(histeq(hist3));
  118. subplot(4,4,8); imshow(adapthisteq(hist3));
  119. %%
  120. % hist4 image
  121. subplot(4,4,9); imshow(hist4);
  122. subplot(4,4,10); imshow(imadjust(hist4));
  123. subplot(4,4,11); imshow(histeq(hist4));
  124. subplot(4,4,12); imshow(adapthisteq(hist4));
  125.  
  126. //////////////////////zB////////////////////////////////////
  127. clearvars;
  128. close all;
  129. clc;
  130.  
  131. %% Reading images
  132. lena1 = imread('lena1.bmp');
  133. lena2 = imread('lena2.bmp');
  134. lena3 = imread('lena3.bmp');
  135. lena4 = imread('lena4.bmp');
  136. phobos = imread('phobos.bmp');
  137.  
  138. image = phobos;
  139.  
  140. load("histogramZadany");
  141.  
  142. figure(1);
  143. plot(histogramZadany);
  144.  
  145. eqImage = histeq(image, histogramZadany);
  146.  
  147. figure(2);
  148. subplot(1,3,1);
  149. imshow(eqImage);
  150. title('hiteqd image');
  151.  
  152. subplot(1,3,2);
  153. imhist(image, 256);
  154. title('histogram');
  155.  
  156. subplot(1,3,3);
  157. adjustedImage = imadjust(eqImage);
  158. adapted = adapthisteq(adjustedImage, 'clipLimit', 0.02, 'Distribution', 'rayleigh');
  159. imshow(adapted);
  160. title('rozciaganie oraz adaptacyjne wyrownanie CLAHE');
  161.  
  162. ////////////////////////zC////////////////////////////////////
  163. clearvars;
  164. close all;
  165. clc;
  166.  
  167. %% reading images
  168. lena = imread("lenaRGB.bmp");
  169. jezioro = imread("jezioro.jpg");
  170.  
  171. image = jezioro;
  172.  
  173. %% extract rgb
  174. red = image(:,:,1);
  175. green = image(:,:,2);
  176. blue = image(:,:,3);
  177.  
  178. figure(1);
  179. subplot(1,3,1);
  180. imhist(red, 256);
  181. title('Red');
  182.  
  183. subplot(1,3,2);
  184. imhist(green, 256);
  185. title('Green');
  186.  
  187. subplot(1,3,3);
  188. imhist(blue, 256);
  189. title('Blue');
  190.  
  191.  
  192. %% adjust
  193. eqImage = image;
  194.  
  195. eqImage(:,:,1) = histeq(red, 256);
  196. eqImage(:,:,2) = histeq(green, 256);
  197. eqImage(:,:,3) = histeq(blue, 256);
  198.  
  199. figure(2);
  200. imshow(eqImage);
  201.  
  202. %% HSV
  203.  
  204. hsvImage = rgb2hsv(image);
  205.  
  206. h = hsvImage(:,:,1);
  207. s = hsvImage(:,:,2);
  208. v = hsvImage(:,:,3);
  209.  
  210. figure(3);
  211. subplot(1,3,1);
  212. imhist(h, 256);
  213. title('H');
  214.  
  215. subplot(1,3,2);
  216. imhist(s, 256);
  217. title('S');
  218.  
  219. subplot(1,3,3);
  220. imhist(v, 256);
  221. title('V');
  222.  
  223. % brightness
  224. hsvImage(:,:,3) = histeq(v, 256);
  225.  
  226. hsvImage = hsv2rgb(hsvImage);
  227. figure(4);
  228. subplot(1,2,1);
  229. imshow(hsvImage);
  230. title('manipulated');
  231. subplot(1,2,2);
  232. imshow(image);
  233. title('original');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement