Advertisement
nihalnoor

Untitled

Aug 7th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. %% Nihal Noor - Lab 2 4146
  2. clc
  3. clear all
  4. close all
  5.  
  6. %%
  7. % Define Array parameters
  8. i_width = 1800;
  9. i_height = 1100;
  10.  
  11. CyclesPerWidth = 450;
  12.  
  13. PixelsPerCycle = i_width/CyclesPerWidth;
  14.  
  15. Amplitude=5;
  16.  
  17. % Set up Array
  18. i_Array = zeros(i_height, i_width, 'uint8');
  19.  
  20. for i=1:i_height
  21. for j=1:i_width
  22. i_Array(i,j) = 128 + Amplitude*cos(2*pi*j/PixelsPerCycle);
  23. end
  24. end
  25.  
  26. imwrite(i_Array,'TestArray.bmp','bmp');
  27. imshow(i_Array);
  28.  
  29.  
  30. %% 6c
  31. im = imread('BowlCrowd_640.bmp');
  32. figure;
  33. imshow(im)
  34.  
  35. YCBCR = rgb2ycbcr(im);
  36.  
  37. % Find dimensions
  38. ImageDim=size(im);
  39.  
  40. % Extract Y component only
  41. Y=YCBCR(:,:,1);
  42. % Create target matrix
  43. YCBCRblur=zeros(ImageDim(1),ImageDim(2),ImageDim(3));
  44.  
  45. % Define blurring filter
  46. % An FSize x FSize array of filter coefficients defined in array "Fweight".
  47. % Note: This is a "brute force" way of doing the blurring. We could have used
  48. % "IntegralKernel", etc. as described in the Matlab documentation for
  49. % blurring an image, but the change in size of the resulting array makes it
  50. % tricky to align the colour components again at the end.
  51.  
  52. FSize=7; % Should be odd
  53. FSpan=floor(FSize/2);
  54. Fweight=[ 0 1 1 1 1 1 0 ; 1 2 2 3 2 2 1 ; 1 2 3 4 3 2 1 ; 1 3 4 5 4 3 1 ; 1 2 3 4 3 2 1 ; 1 2 2 3 2 2 1 ; 0 1 1 1 1 1 0 ];
  55. SumWeights=sum(sum(Fweight));
  56.  
  57. % Blur Y component
  58. for i=1+FSpan : ImageDim(1)-FSpan;
  59. for j=1+FSpan : ImageDim(2)-FSpan;
  60. for k=-FSpan : FSpan;
  61. for l=-FSpan : FSpan;
  62. YCBCRblur(i,j,1)=YCBCRblur(i,j,1)+double(YCBCR(i+k,j+l,1))*Fweight(k+FSpan+1,l+FSpan+1);
  63. end
  64. end
  65. YCBCRblur(i,j,1)=YCBCRblur(i,j,1)/SumWeights;
  66. end
  67. end
  68.  
  69. % Replace Y component with blurred version
  70. YCBCR(:,:,1)=uint8(YCBCRblur(:,:,1));
  71. im_Yblur = ycbcr2rgb(YCBCR);
  72. figure;
  73. imshow(im_Yblur);
  74.  
  75. %% blur CB
  76.  
  77. YCBCR = rgb2ycbcr(im);
  78.  
  79. % Find dimensions
  80. ImageDim=size(im);
  81.  
  82. % Extract CB component only
  83. CB=YCBCR(:,:,2);
  84. % Create target matrix
  85. YCBCRblur=zeros(ImageDim(1),ImageDim(2),ImageDim(3));
  86.  
  87. FSize=7; % Should be odd
  88. FSpan=floor(FSize/2);
  89. Fweight=[ 0 1 1 1 1 1 0 ; 1 2 2 3 2 2 1 ; 1 2 3 4 3 2 1 ; 1 3 4 5 4 3 1 ; 1 2 3 4 3 2 1 ; 1 2 2 3 2 2 1 ; 0 1 1 1 1 1 0 ];
  90. SumWeights=sum(sum(Fweight));
  91.  
  92. % Blur CBCR components
  93. for i=1+FSpan : ImageDim(1)-FSpan;
  94. for j=1+FSpan : ImageDim(2)-FSpan;
  95. for k=-FSpan : FSpan;
  96. for l=-FSpan : FSpan;
  97. YCBCRblur(i,j,2)=YCBCRblur(i,j,2)+double(YCBCR(i+k,j+l,2))*Fweight(k+FSpan+1,l+FSpan+1);
  98. end
  99. end
  100. YCBCRblur(i,j,2)=YCBCRblur(i,j,2)/SumWeights;
  101. end
  102. end
  103.  
  104. % Replace CR component with blurred version
  105. YCBCR(:,:,2)=uint8(YCBCRblur(:,:,2));
  106. % im_CBblur = ycbcr2rgb(YCBCR);
  107.  
  108. % figure;
  109. % imshow(im_CBblur);
  110.  
  111. %% blur CR
  112.  
  113. % Extract CR component only
  114. CR=YCBCR(:,:,3);
  115. % Create target matrix
  116. YCBCRblur=zeros(ImageDim(1),ImageDim(2),ImageDim(3));
  117.  
  118. FSize=7; % Should be odd
  119. FSpan=floor(FSize/2);
  120. Fweight=[ 0 1 1 1 1 1 0 ; 1 2 2 3 2 2 1 ; 1 2 3 4 3 2 1 ; 1 3 4 5 4 3 1 ; 1 2 3 4 3 2 1 ; 1 2 2 3 2 2 1 ; 0 1 1 1 1 1 0 ];
  121. SumWeights=sum(sum(Fweight));
  122.  
  123. % Blur CBCR components
  124. for i=1+FSpan : ImageDim(1)-FSpan;
  125. for j=1+FSpan : ImageDim(2)-FSpan;
  126. for k=-FSpan : FSpan;
  127. for l=-FSpan : FSpan;
  128. YCBCRblur(i,j,3)=YCBCRblur(i,j,3)+double(YCBCR(i+k,j+l,3))*Fweight(k+FSpan+1,l+FSpan+1);
  129. end
  130. end
  131. YCBCRblur(i,j,3)=YCBCRblur(i,j,3)/SumWeights;
  132. end
  133. end
  134.  
  135. % Replace CR component with blurred version
  136. YCBCR(:,:,3)=uint8(YCBCRblur(:,:,3));
  137. im_CBCRblur = ycbcr2rgb(YCBCR);
  138.  
  139. figure;
  140. imshow(im_CBCRblur);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement