How to apply image labeling algorithm using neighborhood values?

How do I prodcue an image using neighbourhood 3 x 3, median value ? I cannot see where i am going wrong. Help much appreciated. Peter
Im = imread('Ruben Weg hl.jpg'); % input image
S = size(Im); %size of image X & Y
%NewImage = zeros(size(Im));
%[row,column,depth]=size(Im);
%I need to put something in here
for Tl=1:size(Im,1)
Th=1:size(Im,2)
pixel=Im(Tl,Th);
% p = Im(m) /9
%Im(:,:,1)
V = Im(m)/9; %pixel values of p neighborhood //9 values
m = median(V); %//Median value of V
V = m(:,:,1);
if Im(p) >= Th && Im(p) > m
Bi(p) = 1;
else ifIm(p) >= Th || (Im(p) > Tl && Im(p) > m)
Bi(p) = 2;
else
Bi(p) = 3;
end
end
end
subplot (1,1,1)
imshow(Im);
title('output');

Réponses (1)

Well for one, m is not defined when you use it as an index to your image Im.
V = Im(m)/9; %pixel values of p neighborhood //9 values
Also if you're doing it manually, you'd need 2 for loops, not one. And we'd need to know if the image is color or not.
And why not simply use the built-in function medfilt2()???
Also, do you know that you can type control-a, control-i in the MATLAB editor to fix your indenting. Can you do that and edit your post with the fixed indenting so people can read it.

1 commentaire

Hello, thank you. I didn't know that you could type control-a controli. I have done that now. I'm not sure how to use the medfilt function as i am still learning how to use matlab.
Im = imread('Ruben Weg hl.jpg'); % input image
S = size(Im); %size of image X & Y
Med = median(V); %//Median value of V
V = m(:,:,1);
for Tl=1:size(Im,1);
for Th=1:size(Im,2);
p=Im(Tl,Th);
% p = Im(m) /9
%Im(:,:,1)
% V = Im(m)/9; %pixel values of p neighborhood //9 values
if Im(p) >= Th && Im(p) > m
Bi(p) = 1;
else if Im(p) >= Th || (Im(p) > Tl && Im(p) > m)
Bi(p) = 2;
else
Bi(p) = 3;
end
end
end
end
subplot (1,1,1)
imshow(Im);
title('output');

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by