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 ExchangeImage 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