how to find center of mass in each grid based on foreground pixel

2 vues (au cours des 30 derniers jours)
Raghu Rao
Raghu Rao le 19 Mar 2017
Modifié(e) : Raghu Rao le 19 Mar 2017

this is my code

clc;
clear all;
close all;
a = imread('i2eee.jpg');
figure;imshow(a);
% Normalizatoin
b = imresize(a,[100,100]);
figure;imshow(b);
% Binarization
th = graythresh(b);
figure;imshow(th);
a = im2bw(b,th);
figure,imshow(a);
s=0;
x=1;z=1;
w = 10;
h = 10;
c=100/w;
r=100/h;
a(r:c:end,:,:) = 0;
a(:,r:c:end,:) = 0;
figure,imshow(a);
cellA = cell(r,c);
m=1;
n=1;
Row_CoM=0;
Col_CoM=0;
tot=0;
ic=1;
for i=1:w:100
for j=1:h:100            
k=i+w-1;
l=j+h-1;
i1=1;j1=1;
if(k <=100 && l<=100)
for ii=i:k
for jj=j:l
s(i1,j1)=a(ii,jj);
j1=j1+1;
end
i1=i1+1;
j1=1;
end
cellA{ic}=s;
ic=ic+1;            
end       
end
end
rr=0;
cc=0;
for i=1:10
for j=1:10
s=cellA{i,j};
Row_CoM = 0;
Col_CoM = 0;
for rw=1:10
for cr=1:10
if(s(rw,cr)==0) 
Row_CoM = Row_CoM + rw;
Col_CoM = Col_CoM + cr;
tot=tot+1;
end
end
end            
Row_CoM = Row_CoM/tot;
Col_CoM = Col_CoM/tot;
rr=rr+Row_CoM;
cc=cc+Col_CoM;
j = impoint(gca,[rr,cc]);
end  
end

Réponses (0)

Catégories

En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by