Labeling objects in an image using nearest neighbors
Show older comments
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!
Answers (0)
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!