How to apply image labeling algorithm using neighborhood values?

5 views (last 30 days)
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');

Answers (1)

Image Analyst
Image Analyst on 8 Jun 2020
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 Comment
Peter Masters
Peter Masters on 9 Jun 2020
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');

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!