Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Nihal Noor - Lab 2 4146
- clc
- clear all
- close all
- %%
- % Define Array parameters
- i_width = 1800;
- i_height = 1100;
- CyclesPerWidth = 450;
- PixelsPerCycle = i_width/CyclesPerWidth;
- Amplitude=5;
- % Set up Array
- i_Array = zeros(i_height, i_width, 'uint8');
- for i=1:i_height
- for j=1:i_width
- i_Array(i,j) = 128 + Amplitude*cos(2*pi*j/PixelsPerCycle);
- end
- end
- imwrite(i_Array,'TestArray.bmp','bmp');
- imshow(i_Array);
- %% 6c
- im = imread('BowlCrowd_640.bmp');
- figure;
- imshow(im)
- YCBCR = rgb2ycbcr(im);
- % Find dimensions
- ImageDim=size(im);
- % Extract Y component only
- Y=YCBCR(:,:,1);
- % Create target matrix
- YCBCRblur=zeros(ImageDim(1),ImageDim(2),ImageDim(3));
- % Define blurring filter
- % An FSize x FSize array of filter coefficients defined in array "Fweight".
- % Note: This is a "brute force" way of doing the blurring. We could have used
- % "IntegralKernel", etc. as described in the Matlab documentation for
- % blurring an image, but the change in size of the resulting array makes it
- % tricky to align the colour components again at the end.
- FSize=7; % Should be odd
- FSpan=floor(FSize/2);
- 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 ];
- SumWeights=sum(sum(Fweight));
- % Blur Y component
- for i=1+FSpan : ImageDim(1)-FSpan;
- for j=1+FSpan : ImageDim(2)-FSpan;
- for k=-FSpan : FSpan;
- for l=-FSpan : FSpan;
- YCBCRblur(i,j,1)=YCBCRblur(i,j,1)+double(YCBCR(i+k,j+l,1))*Fweight(k+FSpan+1,l+FSpan+1);
- end
- end
- YCBCRblur(i,j,1)=YCBCRblur(i,j,1)/SumWeights;
- end
- end
- % Replace Y component with blurred version
- YCBCR(:,:,1)=uint8(YCBCRblur(:,:,1));
- im_Yblur = ycbcr2rgb(YCBCR);
- figure;
- imshow(im_Yblur);
- %% blur CB
- YCBCR = rgb2ycbcr(im);
- % Find dimensions
- ImageDim=size(im);
- % Extract CB component only
- CB=YCBCR(:,:,2);
- % Create target matrix
- YCBCRblur=zeros(ImageDim(1),ImageDim(2),ImageDim(3));
- FSize=7; % Should be odd
- FSpan=floor(FSize/2);
- 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 ];
- SumWeights=sum(sum(Fweight));
- % Blur CBCR components
- for i=1+FSpan : ImageDim(1)-FSpan;
- for j=1+FSpan : ImageDim(2)-FSpan;
- for k=-FSpan : FSpan;
- for l=-FSpan : FSpan;
- YCBCRblur(i,j,2)=YCBCRblur(i,j,2)+double(YCBCR(i+k,j+l,2))*Fweight(k+FSpan+1,l+FSpan+1);
- end
- end
- YCBCRblur(i,j,2)=YCBCRblur(i,j,2)/SumWeights;
- end
- end
- % Replace CR component with blurred version
- YCBCR(:,:,2)=uint8(YCBCRblur(:,:,2));
- % im_CBblur = ycbcr2rgb(YCBCR);
- % figure;
- % imshow(im_CBblur);
- %% blur CR
- % Extract CR component only
- CR=YCBCR(:,:,3);
- % Create target matrix
- YCBCRblur=zeros(ImageDim(1),ImageDim(2),ImageDim(3));
- FSize=7; % Should be odd
- FSpan=floor(FSize/2);
- 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 ];
- SumWeights=sum(sum(Fweight));
- % Blur CBCR components
- for i=1+FSpan : ImageDim(1)-FSpan;
- for j=1+FSpan : ImageDim(2)-FSpan;
- for k=-FSpan : FSpan;
- for l=-FSpan : FSpan;
- YCBCRblur(i,j,3)=YCBCRblur(i,j,3)+double(YCBCR(i+k,j+l,3))*Fweight(k+FSpan+1,l+FSpan+1);
- end
- end
- YCBCRblur(i,j,3)=YCBCRblur(i,j,3)/SumWeights;
- end
- end
- % Replace CR component with blurred version
- YCBCR(:,:,3)=uint8(YCBCRblur(:,:,3));
- im_CBCRblur = ycbcr2rgb(YCBCR);
- figure;
- imshow(im_CBCRblur);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement