Labeling objects in an image using nearest neighbors

I am trying to label all the objects in an image to analyze them and find their centroid. I am trying to do this without using the built in functions in matlab. I am trying to use the four nearest neighbors approach. Here is my code so far:
clc; clear all; close all;
SS = imread('star_sky.png');
SS2 = 0.2989 *SS(:,:,1)+0.5870*SS(:,:,2)+0.1140*SS(:,:,3);
threshold = 100;
SS3 = SS2 >= threshold;
[rows, cols] = size(SS3);
for M = 2 : R-1
for N = 2 : C-1
for k = 2:12
if SS4{M,N}=1
if (SS4(M-1, N)=1 && SS4(M, N-1)=0)
SS4(M,N)==SS4(M-1, N);
end
if (SS4(M-1, N)==0 && SS4(M, N-1)==1)
SS4(M,N)==SS4(M,N-1);
end
if (SS4(M-1,N)==1 && SS4(M, N-1)==1)
SS4(M,N)==SS4(M-1,N);
end
if (SS4(M-1, N)==0 && SS4(M, N-1)==0)
SS4(M,N) == k;
k;
end
end
end
end
end
Could someone help with why my code is not labeling the objects? Thanks!

답변 (0개)

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

질문:

2014년 11월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by