MATLAB: How can i solve median filter 5×5 on image on lena

median filter

hello,i have a project of image processing,it is a median filter 5×5 ,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

Best Answer

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.
Related Question