Program Working Error REGION GROWING

1 vue (au cours des 30 derniers jours)
DP
DP le 5 Nov 2019
ERROR
Undefined function or variable 'M'.
Error in A5>regiongroww (line 36)
D = zeros(M,N);
PLEASE HELP ME IN THIS ERROR OR GIVE ME OTHER PROGRAM THAT WORKS FOR ME
THANK YOU
%% my algorithm for regiongrowing
Threshold = 15
segmentedimage = regiongroww(Image, x , y ,Threshold);
figure(3),imshow(((segmentedimage)));
function segmentedimage = regiongroww(Image, x , y ,threshold)
%[M,N]=size(Image);
%Image=Oimage(:,1:N/2);
segmentedimage = zeros(size(Image));
% 8-neighbors
nhood = [-1 -1; -1 0; -1 1; 0 -1; 0 1; 1 -1; 1 0; 1 1];
pdist = 0;
seed = Image(x,y);
reg_size = 1;
position = 0;
% some space to save co-ordinates and values of neighbors
D = zeros(M,N);
while (pdist<threshold && reg_size<numel(Image))
for ix = 1:8
% gives the co-ordinates of the 8 neighbors
xn = x + nhood(ix,1);
yn = y + nhood(ix,2);
ins=(xn>=1)&&(yn>=1)&&(xn<=M)&&(yn<=N);
if(ins&&segmentedimage(xn,yn)==0)
position = position+1;
D(position,:) = [xn yn Image(xn,yn)];
segmentedimage(xn,yn)=1;
end
end
% calculate the mean of the 8 connected pixel and and add the
% co-ordinates into x,y
dist = abs((D(1:position,3)) - (seed));
[pdist, index] = min(dist);
segmentedimage(x,y)=2; reg_size=reg_size+1;
seed= (seed*reg_size + D(index,3))/(reg_size+1);
x = D(index,1); y = D(index,2);
%delete the empty stuff
D(index,:) = D(position,:); position=position - 1;
end
segmentedimage = segmentedimage > 1;
end

Réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by