l'image de fond

fr       en

Binary processing

Barycenter

Method

The barycenter is to find the center of gravity of an image. We take the example of a white image on black background. To calculate the barycenter we use the weight of each pixel that is part of the form. This value will be row and column issue. Barycenter is calculated as follows:

Program

close all;
clear all,
F = [0 0 0 0 0 0 0 0 0;
   0 0 1 1 1 1 0 0 0;
   0 0 1 0 0 0 0 0 0;
   0 0 1 0 0 0 0 0 0;
   0 0 1 1 1 0 0 0 0;    
   0 0 1 0 0 0 0 0 0;
   0 0 1 0 0 0 0 0 0;
   0 0 0 0 0 0 0 0 0;
   0 0 0 0 0 0 0 0 0];

F = kron(F,ones(32));

valeurx=0;
valeury=0;
[M N]=size(F)
nbpoint=0;
for i = 1 : M
    for j = 1 : N
        if F(i,j)==1
            valeurx=valeurx+i;%sommation pondéré en x
            valeury=valeury+j;%sommation pondéré en y
            nbpoint=nbpoint+1;% nombre de point total
        end
    end
end

valeurx=round(valeurx/nbpoint);%normalisation sur x
valeury=round(valeury/nbpoint);%normalisation sur y


%De combien faut t'il translater
centreimagex=round(M/2);
centreimagey=round(N/2);
translatex=centreimagex-valeurx;
translatey=centreimagey-valeury;

%Maintenant on translate
Fcenter = zeros(M,N);
for i = 1 : M
    for j = 1 : N
        shiftx = i - translatex;
        shifty = j - translatey;
        if (shiftx < M && shiftx > 1 && shifty < N && shifty > 1)
            Fcenter(i,j) = F(shiftx,shifty);
        else
            Fcenter(i,j) = 0;
        end
    end
end

Fb=F;
Fb(valeurx,valeury)=not(F(valeurx,valeury));% pour voir le barycentre
figure(  'name','centrage image binaire','NumberTitle','off');
subplot(121)
imshow(Fb)
subplot(122)
imshow(Fcenter)
 

Example

Barycenter of a letter (at left) and we have centered the letter at the center of the image (at right)
barycentre d'une image 2D

Copyright © 2010-2014, tous droits réservés, contact : operationpixel@free.fr