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');

답변 (1개)

Image Analyst
Image Analyst 2020년 6월 8일
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

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');

댓글을 달려면 로그인하십시오.

질문:

2020년 6월 8일

댓글:

2020년 6월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by