Size of Images varying

조회 수: 1 (최근 30일)
FIR
FIR 2012년 7월 28일
Input = imread('baby1.jpeg') ;
size(Input)
P=rgb2gray(Input);
image= im2double(P);
[m n ] = size(A);
Med = [];
%Modified filter
for i=2:m-1
for j=2:n-1
Med(1) = image(i,j);
Med(2) =image(i-1,j) ;
Med(3) = image(i-1,j+1);
Med(4) = image(i,j-1);
Med(5) = image(i,j+1);
Med(6) = image(i+1, j-1);
Med(7) = image(i+1,j);
Med(8) = image(i+1,j+1);
Afilteres(i, j) = median(Med(:));
end
end
imshow(Af);
In this the size of image varies
size(P)=201 300
size(Af)
200 299
PLease help
  댓글 수: 2
Sean de Wolski
Sean de Wolski 2012년 7월 30일
In reponse to the flags and requests for deletion. I will not delete this question since Andrei, Wayne and IA all put effort into helping you.
FIR
FIR 2012년 7월 31일
ok Sean thank u

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 7월 28일
편집: Andrei Bobrov 2012년 7월 28일
m = size(A);
A1 = zeros([m(1:2) + 2,m(3)]);
A1(2:end-1,2:end-1,:) = A;
Af = zeros(m);
for ii = 1:m(1)
for jj = 1:m(2)
k = reshape(A1(ii:ii+2,jj:jj+2,:),[],1,3);
Af(ii,jj,:) = median(k([1:4,6:9],:,:)); % EDIT
end
end
  댓글 수: 2
Image Analyst
Image Analyst 2012년 7월 28일
You forgot to exclude the middle pixel when taking the median, like he did. Though I don't know what the use of this strange type of median filter would be. Maybe he can explain that.
Andrei Bobrov
Andrei Bobrov 2012년 7월 28일
Thank you Image, I corrected my answer.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Wayne King
Wayne King 2012년 7월 28일
The Image Processing Toolbox has medfilt2
  댓글 수: 3
Wayne King
Wayne King 2012년 7월 28일
The file exchange appears to have median filter implementations, but I'm guessing if you're not allowed to use medfilt2, then you're not supposed to use those either
Image Analyst
Image Analyst 2012년 7월 28일
편집: Image Analyst 2012년 7월 28일
If the built-in function must not be used, then it must be some kind of homework assignment, which means that code solutions provided by Answers must not be used either. Too bad because I have a nice demo using blockproc that I could have given you. However it's strange that median(), the 1D version, can be used while medfilt2(), the sliding 2D version, cannot be used.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2012년 7월 28일
Of course the image sizes are different, because you're sliding a window along, and you have it so that when the edge of the window touches the edge of the image, it stops. So of course the output image will not be as big as the input image.
Again, I have demo code but since you said you're not allowed to use built in functions, and probably not code handed over to you in Answers or code you got from the File Exchange, I won't post it. Yeah, sometimes instructors/professors are picky about doing your own work.
  댓글 수: 4
FIR
FIR 2012년 7월 30일
any code is suggested without using medfilt2
Image Analyst
Image Analyst 2012년 7월 30일
편집: Image Analyst 2012년 7월 30일
Well then you're all set, because Andrei gave you code that used median() (and you've already accepted his answer), and I suggested using sort() and taking the middle element. So I'm assuming that you're done now.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by