how can i solve median filter 5x5 on image on lena?
5 views (last 30 days)
Show older comments
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 Comment
Geoff Hayes
on 19 May 2014
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.
Accepted Answer
Image Analyst
on 19 May 2014
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 Comments
Image Analyst
on 19 May 2014
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).
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!