Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.37 KB | None | 0 0
  1. close all, clear all;
  2. x = imread('obraz.jpeg');
  3. xcr = x(:,:,1);
  4. xcg = x(:,:,2);
  5. xcb = x(:,:,3);
  6.  
  7. [histr,a,b] = ihist(xcr,150,100);
  8. gr = a*xcr+b;
  9. [histg,a,b] = ihist(xcg,150,100);
  10. gg = a*xcg+b;
  11. [histb,a,b] = ihist(xcb,150,100);
  12. gb = a*xcb+b;
  13.  
  14. [hist2r,a2,b2] = ihist(gr,256,1);
  15. g2r = uint8(a2*double(gr)+double(b2));
  16. [hist2g,a2,b2] = ihist(gg,256,1);
  17. g2g = uint8(a2*double(gg)+double(b2));
  18. [hist2b,a2,b2] = ihist(gb,256,1);
  19. g2b = uint8(a2*double(gb)+double(b2));
  20.  
  21. [hist3r,a,b] = ihist(g2r,256,1);
  22. g3r = uint8(a2*double(g2r)+double(b2));
  23. [hist3g,a,b] = ihist(g2g,256,1);
  24. g3g = uint8(a2*double(g2g)+double(b2));
  25. [hist3b,a,b] = ihist(g2b,256,1);
  26. g3b = uint8(a2*double(g2b)+double(b2));
  27.  
  28.  
  29. [xr, hist4r, vc]=jmequal(g2r);
  30. [xg, hist4g, vc]=jmequal(g2g);
  31. [xb, hist4b, vc]=jmequal(g2b);
  32.  
  33. figure();
  34. subplot(4,1,1);
  35. hold on;
  36. plot(histr,'r');
  37. plot(histg,'g');
  38. plot(histb,'b');
  39. title('Histogram oryginalnego obrazu')
  40.  
  41. subplot(4,1,2);
  42. hold on;
  43. plot(hist2r,'r');
  44. plot(hist2g,'g');
  45. plot(hist2b,'b');
  46. title('Histogram zwezonego obrazu')
  47. subplot(4,1,3);
  48. hold on;
  49. plot(hist3r,'r');
  50. plot(hist3g,'g');
  51. plot(hist3b,'b');
  52. title('Histogram rozciagnietego obrazu')
  53. subplot(4,1,4);
  54. hold on;
  55. plot(hist4r,'r');
  56. plot(hist4g,'g');
  57. plot(hist4b,'b');
  58. title('Histogram wyrownanego obrazu')
  59.  
  60. figure()
  61. imagesc(x);
  62. title('obraz oryginalny')
  63. figure()
  64. g(:,:,1)=gr;
  65. g(:,:,2)=gg;
  66. g(:,:,3)=gb;
  67. title('obraz ze zwezonym histogramem')
  68. imagesc(g);
  69. figure()
  70. g2(:,:,1)=g2r;
  71. g2(:,:,2)=g2g;
  72. g2(:,:,3)=g2b;
  73. imagesc(g2);
  74. title('obraz z rozciagnietym histogramem')
  75.  
  76. figure()
  77. x(:,:,1)=xr;
  78. x(:,:,2)=xg;
  79. x(:,:,3)=xb;
  80. imagesc(x);
  81. title('obraz z wyrownanym histogramem')
  82.  
  83. x = g;%imread('obraz.jpeg');
  84. hsv = rgb2ycbcr(x);
  85. hsvl = hsv(:,:,1);
  86. hsvcr = hsv(:,:,2);
  87. hsvcb = hsv(:,:,3);
  88. [hsvl,histr1,vc] = jmequal(hsvl);
  89.  
  90. %
  91. % [hsvcr,histr2,vc] = jmequal(hsvcr);
  92. %
  93. % [hsvcb,histr3,vc] = jmequal(hsvcb);
  94.  
  95. hold on;
  96. %x = uint8(x);
  97. % hsv = double(hsv);
  98. hsv = hsv;
  99. x(:,:,3)=hsvcb;
  100. x(:,:,2)=hsvcr;
  101. x(:,:,1)=hsvl;
  102. result = ycbcr2rgb(x);
  103. %result = uint8(result);
  104. figure()
  105. xcr = result(:,:,1);
  106. xcg = result(:,:,2);
  107. xcb = result(:,:,3);
  108. imagesc(result)
  109. figure()
  110. [histr,a,b] = ihist(xcr,256,1);
  111. [histg,a,b] = ihist(xcg,256,1);
  112. [histb,a,b] = ihist(xcb,256,1);
  113. hold on;
  114. plot(histr,'r');
  115. plot(histg,'g');
  116. plot(histb,'b');
  117. title('Histogram wyrównanego obrazu w przestrzeni kolorow YCbCr')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement