Borrar filtros
Borrar filtros

help me to find center of mass in each segments

1 visualización (últimos 30 días)
Raghu Rao
Raghu Rao el 19 de Mzo. de 2017

this is my code, am trying to find the center of mass in each grid based on foreground pixels

clc;
clear all;
close all;
a1 = imread('i2eee.jpg');
figure;imshow(a1);
% Normalizatoin
b = imresize(a1,[100,100]);
figure;imshow(b);
% Binarization
th = graythresh(b);
a = im2bw(b,th);
figure,imshow(a);
s=0;
x=1;z=1;
w = 10;
h = 10;
c=100/w;
r=100/h;
cellA = cell(c);
m=1;
n=1;
% Row_CoM=0;
% Col_CoM=0;
%  tot=0;
ic=1;
%Count=0;
for i=1:100
    for j=1: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;
               tot = 0;
              for rw=1:c
                  for cr=1:r
                      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,[cc,rr]);
       end
    end

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by