From: shilpa khinvasara on 4 Aug 2010 05:59 sir i am trying to write the following code to find the mean of quantized image in this code i am replicating the sides,but there i some error [m n]=size(q); % We need to be able to apply MEAN filter at the boundary pixels. % The easiest way to handle this is to set up a matrix A2 that has % the original image A in the center and copies the adjacent % pixel value around the edges. k = 3; % How far we need to extend border. A2 = zeros(m+2*k,n+2*k); A2(k+1:m+k,k+1:n+k) = q; % Original image in center. % Extend border pixels. % Handle the 4 corners first. A2(1:k,1:k) = q(1,1); % Upper left corner. A2(1:k,n+k+1:n+2*k) = q(1,n); % Upper right corner. A2(m+k+1:m+2*k,n+k+1:n+2*k) = q(m,n); % Lower right corner. A2(m+k+1:m+2*k,1:k) = q(m,1); % Lower left corner. % To handle the sides, we need to copy 1 row/column at a time. for i = 1:k A2(i,k+1:n+k) = q(1,1:n); % Upper. A2(k+1:m+k,n+k+i) = q(1:m,n); % Right. A2(m+k+i,k+1:n+k) = q(m,1:n); % Lower. A2(k+1:m+k,i) = q(1:m,1); % Left. end; q=double(q); y(1,: )=q(1,: ); y(1:166,1)=q(1:166,1); y(166,: )=q(166,: ); y(1:166,359)=q(1:166,359); for k=1:3 for j=1:3 y(k,j)=(x(k+1,j+1)+x(k,j+1)+.... x(k+1,j+1)+x(k-1,j)+x(k,j)+.... x(k+1,j)+x(k-1,j-1)+x(k,j-1)+.... x(k+1,j-1))*(1/9); end end figure; hist(y(:),max(y(:)));
From: ImageAnalyst on 4 Aug 2010 09:45 Why are you enlarging the image by replicating the sides? That is not necessary to get the mean of the image. You can just do meanOfImage = mean(q(:)); or meanOfImage = mean2(q); If you want a local mean, you can use conv2 blurredImage = conv2(q, ones(3,3)/9, 'same');
|
Pages: 1 Prev: Simhydraulics ( Next: Problem using the 'lecroy_basic_driver'! |