image processing loop to calculate median value in window / kernel
Mostrar comentarios más antiguos
I want to slide through an image matrix and evaluate the median at each frame. The structuring element needs to be 5x5. This is what i have so far:
img = imread('img.jpg');
length = 5;
half = round(length/2);
Len = size(greyscale_Gaussian);
rows = Len(1);
cols = Len(2);
kernel = zeros(5,5);
rowend = (rows - 1);
colend = (col - 1);
for row = 3 : rows -3;
for column = 3: num_cols -3;
up = row + half;
down = rows - half;
right = column + half;
left = cols - half;
startrow = max(up), 1;
endrow = min(down), rowend;
startcolumn = max(left),1;
endcolumn = min(right),colend;
window = W(startrow:endrow, startcolumn:endcolumn); %??
window = ([up:down,right:left]); %??
B(row, column) = median(window);
end
end
Im not sure how to define the window or how to end this script? i dont want to use any inbuilt functions such as imfilter etc.
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 21 de Mzo. de 2021
0 votos
Why not use the build-in function medfilt2()?
3 comentarios
Yas Rebecca
el 21 de Mzo. de 2021
Image Analyst
el 21 de Mzo. de 2021
Then can you please accept DGM's answer to give him reputation points?
And it's almost always better to use built-in methods because they've been extensively tested for robustness and validated for accuracy, rather than your own method, which might not think of all the things that could go wrong or have bugs.
DGM
el 21 de Mzo. de 2021
I second Image Analyst's note about using existing tools. Not only are they typically more robust, but they're often faster. I should've added that the only reason I wrote that sliding window filter was as a fallback for use only when imdilate() wasn't available.
Categorías
Más información sobre Image Preview and Device Configuration en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!