Code covered by the BSD License  

Highlights from
Spot Border Detection

Spot Border Detection

by

 

15 Jan 2007 (Updated )

Spot on image ? get border as numeric array and a number of measurements of a spot and a border

publscript01

Contents

Path Tracing

%        An application of path tracing is intended for
%detecting an external border of spot (simply connected
%black  pixels set).
%        An output includes:
% - two arrays with spot border pixels,
% - coordinates of points of optimal location (centers
%   of mass) for a spot and for a spot border,
% - perimeter (as length of line connected  centers of
%   border pixels and as count of external border pixel
%   edges),
% - count of  pixels of a spot and its border,
% - coordinates of the most remote pixels,
% - a distance between them,
% - coordinates of vertices of minimal  rectangle with
%   spot inside it.
%        Output data might  be calculated from both an
%image and a numeric matrix.
%The author - Eduard Polityko, PHD.
%E-mail     - Edpolit@gmail.com
%Edition 28-Dec-2006
alfa='examp03.bmp';
[a b xc]=digis1(alfa);

Displaying results

figure;
image(imread(alfa)');colormap([0 0 0;1 1 1]);
title('Spot');axis xy;grid on
format short g
rp=repmat('_',1,26);
disp('     Coordinates')
disp(rp)
disp('Center of mass of contour')
disp(xc(1:2));
disp('Center of mass of spot   ');
disp([xc(3:4)]);
disp(['Rectangle to crop ';...
'(ends of diagonal)'])
disp(xc(10:13))
disp('The most remote points')
disp([a(xc(7)),b(xc(7)),a(xc(8)),b(xc(8))])
disp(rp)
disp('Maximal distance between points')
disp(xc(9));
disp('Count of black pixels:')
disp([{'Border'},{xc(5)};{'Spot'},{xc(6)}])
disp('         Perimeter:')
disp('  count of external edges')
disp('      of border pixels ')
disp(xc(14))
disp('  length of line connected')
disp('  centers of border pixels')
disp(xc(15))
figure;
zx=plot(a,b,'-',xc(1),xc(2),'+',...
  xc(3),xc(4),'*',[xc(10) xc(12)],[xc(11) xc(13)],'o',...
  [a(xc(7)),a(xc(8))],[b(xc(7)),b(xc(8))],'p');grid on
set(zx,'linewidth',1)
legend('spot border',['center of '; 'curve mass'],...
  ['center of'; 'spot mass'],['rectangle vertices'],...,
  ['the most     ';'remote points'],'location', 'best');
title(['Measurement']);
     Coordinates
__________________________
Center of mass of contour
       308.43       232.64

Center of mass of spot   
       200.95       180.43

Rectangle to crop 
(ends of diagonal)
    10     1   430   558

The most remote points
    36    47   407   553

__________________________
Maximal distance between points
       627.44

Count of black pixels:
    'Border'    [ 3354]
    'Spot'      [61786]

         Perimeter:
  count of external edges
      of border pixels 
        3560

  length of line connected
  centers of border pixels
       3437.7

Series detection of spots

figure
subplot(2,3,1)
J=imread('examp05.bmp');
image(J');axis xy;title('Spots')
colormap([0 0 0;1 1 1]);
subplot(2,3,2)
[a b xc]=digis1(J);
plot(a,b,'-',xc(1),xc(2),'+',...
  xc(3),xc(4),'*',[xc(10) xc(12)],[xc(11) xc(13)],'o',...
  [a(xc(7)),a(xc(8))],[b(xc(7)),b(xc(8))],'p');
for rr=1:4
subplot(2,3,2+rr)
J1=J;
for i=1:length(a);
 ii=0;
 while ~J(a(i),b(i)+ii)
   J(a(i),b(i)+ii)=1;
   ii=ii+1;
 end
end
[a b xc]=digis1(J);
plot(a,b,'-',xc(1),xc(2),'+',...
  xc(3),xc(4),'*',[xc(10) xc(12)],[xc(11) xc(13)],'o',...
  [a(xc(7)),a(xc(8))],[b(xc(7)),b(xc(8))],'p');
end

Contact us