how can i solve median filter 5x5 on image on lena?

3 次查看(过去 30 天)
hello,i have a project of image processing,it is a median filter 5x5 ,i have to use it on standart pictures like lena etc, without using toolbox coding as medfilter,etc,i have to write an algorithm for that,i am new on matlab and still have a problem on Subscripted assignment dimension mismatch. i didnt remove it , please contact with me, because i have a little time to submit it.
for i=(a+1)/2:height-((a-1)/2)
for j=(a+1)/2: height-((a-1)/2)
templena =lena(i-(a-1)/2:i+(a-1)/2,j-(a-1)/2:j+(a-1)/2);
x=median(templena);
lenaoutput(i,j)=x;
end
end
i will appreciate you , if i can solve it. thank you again
  1 个评论
Geoff Hayes
Geoff Hayes 2014-5-19
What is a? What is height defined to be, and should there be a width as well? Ideally, the code should process each pixel and consider the 5x5 neighbourhood around it taking care when the neighbourhood runs outside of the image.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2014-5-19
You need to have the outer loops scan over rows and columns, then extract a subimage and call median (if you're allowed to use that function).
windowHeight = 5;
windowWidth= 5;
[rows, columns, numberOfColorChannels] = size(grayImage);
for c = ceil(windowWidth/2) : columns - ceil(windowWidth/2)
for r = ceil(windowHeight/2) : rows - ceil(windowHeight/2)
subimage = grayImage(..............
end
end
Try to finish it.
  2 个评论
fatma
fatma 2014-5-19
编辑:fatma 2014-5-19
my code is like this. >> uiopen('C:\Users\LG\Desktop\lena.pgm',1)
lena1=imread('C:\Users\LG\Desktop\lena.pgm');
>> lena=imnoise(lena1,'salt & pepper',0.01);
>> imshow(lena)
lena=double(lena);
>> height=size(lena,1);
>> width=size(lena,2);
>> lenaoutput=zeros(size(lena));
>> for i=3 :height-2
for j=3 :height-2
templena=lena(i-1: i+3,j-1:j+3);
w=[lena(i-1,j-1) lena(i,j-1) lena(i+1,j-1) lena(i+2,j-1) lena(i+3,j-1) lena(i-1,j) lena(i,j) lena(i+1,j) lena(i+2,j) lena(i+3,j) lena(i-1,j+1) lena(i,j+1) lena(i+1,j+1) lena(i+2,j+1) lena(i+3,j+1) lena(i-1,j+2) lena(i,j+2) lena(i+1,j+2) lena(i+2,j+2) lena(i+3,j+2) lena(i-1,j+3) lena(i,j+3) lena(i+1,j+3) lena(i+2,j+3) lena(i+3,j+3)]
m=median(w);
pixvalue=m;
lenaoutput(i,j)=pixvalue;
lenaoutput(1,j)=lenaoutput(2,j);
for i=1 :2
for j=1 :256
lenaoutput(i,j)=lenaoutput(3,j);
end;
end;
for i=1 : 256
for j=1 :2
lenaoutput(i,j)=lenaoutput(i,3);
end
end;
for i=255: 256
for j=1:256
lenaoutput(i,j)=lenaoutput(254,j);
end
end;
for i=1 :256
for j=255 :256
lenaoutput(i,j)=lenaoutput(i,254);
end
end;
lenaoutput=uint8(lenaoutput);
imshow(lenaoutput)
but i couldnt see the lenaoutput image , there is no result.please help me to solve it because i dont know where i did a mistake.i have little time to submit it,and still couldnt see the results.
Image Analyst
Image Analyst 2014-5-19
Learn how to write a script instead of doing everything on the command line. Also learn to format your code by watching this: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Also if I take time to give you good advice, it might be good if you followed it, because there may be reasons why I didn't try to fix your existing code (like it's so bad that it's not worth fixing).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Denoising and Compression 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by