how to find center of mass in each grid based on foreground pixel
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!