voronoi

  • Follow


Hi,I have a function to calculate the center of each cells.Now I want to apply the voronoi to segment the cells but I don t know how to apply it.Can you help me??this is the function:

function p = blobdetector(im, side, min_dist,option,th,map);

% function p = blobdetector(im, side, min_dist,option,th,map);
%
% Input
%-------------------------------------------------------------
% im = image to count cells
% side: filter size - choose the diameter (or slightly larger) of the blob (in pixels)
% min_dist : minimum distance between peaks
% option : 1 if the peak to detect is dark
%          0 if the peak to detect is bright (e.g. Topro stained image)
% map : mask of layer
% th : threshold for filter output
      %- suggested to choose -0.05 or 0

% Output
%-------------------------------------------------------------
% p: returns the number of peaks detected.
% resultImaage: under current directory as 
% Result(filter size,min_dist)_p_totalarea

% Works only with gray-scale images. If RGB image is input, the image will
% be converted to gray image

%
tic
% specified result path
resultPath = [pwd,'\'];


if nargin ==3
    map =ones(size(im,1),size(im,2));
    option = 0;
end

% if map is not specified, assume a whole image as a map

if nargin<5
        th =0;
end
if nargin <6
    map =ones(size(im,1),size(im,2));
end
if size(im,3) ==1
    img = im;
else
    img = rgb2gray(im);
end

if option==0
    img = 255-img;
end
% apply the filter
ac = lapofgau(img,side);
ac(find(ac<th))=th;
ac = ac-th;

scaling = 1;
ac2=ac;
figure; imagesc(ac); axis image; axis off

% find local maxima from filter output
[i,j,val] = find_local_max_2D(ac2,[],floor(side/4/scaling),inf,min_dist,[],[1 1],map);


area = length(find(map==255 |map==1 ));

p =0;
ind=[];
tmp = [i' j' ];
if size(im,3) ==1 % gray
    result(:,:,1) = im;
    result(:,:,2) = im;
    result(:,:,3) = im;
else
    result = im;
end

for k =1: length(i)
    p = p+1;
    ind = [ind ; tmp(k,:)];
    result(tmp(k,1), tmp(k,2),1)= 255;
    result(tmp(k,1), tmp(k,2),2)= 255;
    result(tmp(k,1), tmp(k,2),3)= 0;
end



toc
figure;
imagesc(im);axis image; colormap gray; axis off
hold on; plot(scaling*ind(:,2), scaling*ind(:,1), '.r');
title([num2str(p),' Number of Cobblestone (area:',num2str(area),')']);
%imwrite(result,[resultPath,'Result(',num2str(side),',',num2str(min_dist),')_',num2str(p),'_',num2str(area),'.tif'],'tif');

TANKS A LOT!!
0
Reply pier 12/7/2010 10:30:08 AM

Why would you want to do that?  I don't see how voronoi is applicable
here.  To segment, count, and measure the objects, the general
procedure is this
threshold (binarize)
call bwlabel
call regionprops.

Go here for a simple demo segmenting coins:
http://www.mathworks.com/matlabcentral/fileexchange/25157
http://blogs.mathworks.com/pick/2009/11/06/segmenting-coinsa-tutorial-on-blob-analysis/

Is there some reason why you don't want to do the standard process?
0
Reply ImageAnalyst 12/7/2010 11:14:25 AM


The output of the function is an image with a dot for each cells in the center of the cells.I was wandering that the voronoi could work with this dots.I don t need the treshold or other demo about the segmentation my aim is apply the voronoi around those dots.This is not my function so I don t know how to do.I post you the second function that is inside of the previus maybe can be usefull.tanks    :

PROBABLY YOU CAN FIND THE DOTS HERE AND APPLY THE VORONOI


function [i, j, val] = find_local_max_2D(E, delta, epsilon, N, min_dist, crop_box_m, borders_m,map)

% [i, j, val] = find_local_max_2D(E, delta, epsilon, N, min_dist, crop_box_m, borders_m)
%
% DESC:
% finds at most N local max in the 2D map E. The minimum distance between
% the peaks is min_dist. The neighborhood to verify the presence of a max
% has radius epsilon

% INPUT:
% E			    = input 2D map (the entries should be POSITIVE)
% delta         = lattice cell dimensions (if empty then the distance
%                 between the lattice elements is assumed to be 1)
% epsilon       = radius of the interval inside which we look for the
%                 stationary point (defined w.r.t. delta)
% N             = number of desired peaks (inf to find all the admissible
%                 peaks)
% min_dist      = minimum distance between peaks
% crop_box_m    = defines the map portion [x_min x_max] 
%                 to be processed. If empty use the whole map
% borders_m     = prevents the search in the map borders If empty use the
%                 whole map portion
%
% OUTPUT:
% i, j          = peaks coordinates (in the lattice coordinates)
% val           = peaks value

if isempty(delta)
    delta = [1 1];
end;

% select image portion
if isempty(crop_box_m)
    crop_box = [1 size(E, 1) 1 size(E, 2)];
    E_c = E;
else
    crop_box = ceil(crop_box_m ./ delta);
    E_c = E(crop_box(1):crop_box(2), crop_box(3):crop_box(4));
end;


% save some memory
clear E;

if isempty(borders_m)
    borders_m = [0 0];    
end;
borders = ceil(borders_m ./ delta);

% clean non-numeric elements
minimum = min(E_c(:));
E_c(find(~isfinite(E_c))) = minimum;
s = size(E_c);
s_m = delta .* s;

% prepare neighborhood indices
n_dim = ceil(epsilon ./ delta);

h = 1;
ind_n=[];
for i = -n_dim(1):n_dim(1)
    for j = -n_dim(2):n_dim(2)
        
        if ~(i == 0) && ~(j == 0) && ((i*delta(1))^2 + (j*delta(1))^2 <= epsilon^2)
            
            ind_n(1:2, h) = [i; j];
            h = h + 1;
            
        end;
        
    end;
end;
N_n = h - 1;

% prepare extended neighborhood indices
n_dim = ceil(min_dist./delta);

h = 1;
for i = -n_dim(1):n_dim(1)
    for j = -n_dim(2):n_dim(2)
        
        if ( (i*delta(1))^2 + (j*delta(2))^2 <= min_dist^2 )                
            
            ind_n_ext(1:2, h) = [i; j;];  
            h = h + 1;
            
        end;
        
    end;
end;
N_n_ext = h - 1;

l = 1;
val = [];
i = [];
j = [];
mask_s = ones(size(E_c));
mask_s(1:borders(1), :) = 0;
mask_s(size(E_c, 1)-borders(1)+1:size(E_c, 1), :) = 0;
mask_s(:, 1:borders(2)) = 0;
mask_s(:, size(E_c, 2)-borders(2)+1:size(E_c, 2)) = 0;
% only work for map ==1
% to avoid to find a local maximum on the borders
%map = bwmorph(map,'erode');
mask_s(find(map==0))=0;
minimum = min(E_c(:));
while (length(i) < N)
    
    % seek for peaks inside the allowed region
    ind_s = find(mask_s == 1);
   if isempty(ind_s)
        break
    end;
    [v_0 temp] = max(E_c(ind_s));
    if (v_0 == minimum) | isempty(v_0)
        break
    end;
    ind = ind_s(temp(1));
    if isempty(ind)
        break
    end;            
    [I J] = ind2sub(s, ind(1));
    I_m = delta(1) * I;
    J_m = delta(2) * J;
    
    indices = ind_n + repmat([I(1); J(1)], 1, N_n);
    
    % check if we are inside the map portion
    in = find(...
        (indices(1, :) >= 1) & (indices(1, :) <= s(1)) & ...
        (indices(2, :) >= 1) & (indices(2, :) <= s(2)) ...
        );

   
    N_n_in = length(in);
    
    if N_n_in > 0;
        
        % check if v_0 is actually a max
        flag = 1;
        p = 1;
        while (flag) && (p <= N_n_in)
            
            flag = flag && (v_0(1) >= E_c(indices(1, in(p)), indices(2, in(p))));
            p = p + 1;
            
        end;
        
        if flag
            
            % fprintf('\n%d local max found', l);
            
            % save the peak data
            i(l) = crop_box(1) + I - 1;
            j(l) = crop_box(3) + J - 1;
            val(l) = v_0;
            l = l + 1;                
            
        else
            
            mask_s(I, J) = 0;
            
        end;
                
        % and remove it from the map (together with the minimum
        % distance neighborhood)
        indices = ind_n_ext + repmat([I(1); J(1)], 1, N_n_ext);
        in = find( ...
            (indices(1, :) >= 1 & indices(1, :) <= s(1)) & ...
            (indices(2, :) >= 1 & indices(2, :) <= s(2)) ...
            );
        mask_s(sub2ind(s, indices(1, in), indices(2, in))) = 0;
     end;        
    
end;
    
return;
0
Reply pier 12/7/2010 11:40:07 AM

If your aim is to experiment with the voronoi concept, and not to
solve any real world problem or learn about image processing through a
tutorial, then why don't you simplify and just call the voronoi
function already built into MATLAB?  Sorry but I don't have time to
look through dozens of lines of poorly commented code to figure out
what it does.  Maybe you or someone else does.  Or you can try to ask
the author.  Have you actually tried that code?  Did it work or give
any error messages?  What is it about calling that function that you
don't know how to do?  It tells you what all the input arguments are.
Isn't it just like calling any other function?
0
Reply ImageAnalyst 12/7/2010 11:50:01 AM

The two function that i posted works with an image that contain about 5000 cells.Segment those cells is an hard work so with those function you can find the maxima inside of each cells and the algorithm works with the minimal distance between the center of two cells and the diameter of the cells in pixel.The problem is that i m not an expert so i use those function to find the center of each cells to count them and is very good i can count all the cells,now the voronoi can works very good with this dots the problem is that i don t know how to find the coordinate of those dots and apply the voronoi.if you find the dots i think is not difficult to apply the voronoi.
0
Reply pier 12/7/2010 12:03:04 PM

the second function is called in the first function,the first function return in the main program the number of the dots 
0
Reply pier 12/7/2010 12:14:05 PM

On Dec 7, 7:14=A0am, "pier " <pieralessandrogiorge...@yahoo.it> wrote:
> the second function is called in the first function,the first function re=
turn in the main program the number of the dots
---------------------------------------------------------------------------=
---------------------------------------------------------------------------=
--------
Do you want to post your image somewhere (some free image hosting web
site) and post the code that you used to turn your grayscale image
into a binary image?

Maybe I can see what standard methods (bwlabel, regionprops) can do.
0
Reply ImageAnalyst 12/7/2010 1:25:08 PM

I know what you mean but i don t use the binary image i use only the 2 function that i posted to find the center of the cells and than count them but i don t need the segmentation because is impossible i ve tried a lot of method(watershed,edge detection,treshold ecc...) I only want to  know how and where apply voronoi using the dots
but i don t know how the 2 functions work. So what i ask you is if you can see in the functions were are the coordinate of the dots to applay the voronoi.the main of my code is:





%--------------------------------------------------------------------------
%COLORARE E CONTARE TUTTE LE COBBLESTONE CON POSSIBILITA' DI CROP
%MADDALENA PIU "CONTARE COBBLESTONE CROPPATI"
%--------------------------------------------------------------------------



close all
clear all
clc
 
% -------------------------------------------------------------------------
% ---------------------------- Parameters ---------------------------------
% -------------------------------------------------------------------------


s1B = strel('disk', 4); %structure element for the closing in Toggle-MApping
s2B = strel('disk', 3); %structure element for the opening in Toggle-MApping
L = 40;     %minimal lenght of the path opening
long = 10;  %number of pixel of a small object to be remove by the skeleton


%--------------------------------------------------------------------------
%OPEN IMAGE
%--------------------------------------------------------------------------


 [file,path]= uigetfile('*.*','Load');
 filename= sprintf ('%s%s',path,file);
 IM=imread(filename);
 figure('name','Original image'),
 subplot(1,1,1);imshow (IM);
 pause

%--------------------------------------------------------------------------
%OPEN IMAGE IN RED BLUE AND GREEN CHANNEL
%--------------------------------------------------------------------------
 
  figure 
  imshow (IM(:,:,1)),title ('Imm in red channel');
  
  figure 
  imshow (IM(:,:,2)),title ('Imm in green channel');
  
  figure 
  imshow (IM(:,:,3)),title ('Imm in blue channel');
 
  pause
  
% The image is RGB. The GREEN bande does not contain much information. 
% The  GREEN band contain too much noise. The RED band is used.

 IM = IM (:,:,1);
 subplot(1,1,1);imshow (IM);   
 pause
 
%--------------------------------------------------------------------------
%CHANGE THE RESOLUTION
%--------------------------------------------------------------------------
 
 
% High resolution 

        [r,c]=size(IM);
        factor = r/512;
        cnew = round(c/factor);
        IM_high = imresize(IM,[ 1024 (2*cnew) ], 'bicubic');       % uint8 0-255
   
%--------------------------------------------------------------------------
%Cobblestone measure(cells diameter)using image resized with high resol.
%--------------------------------------------------------------------------
 

      figure('name','Original image resized with high resolution'), imshow(IM_high);
      [I1,rect] = imcrop(IM_high);
      figure('name','Crop image with high resolution'), imshow(I1);
      diam = measure;
      close ('Original image resized with high resolution')
      message = sprintf('The distace is :\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t%d pixel',diam);msgbox(message)
      clc
      pause
      
%--------------------------------------------------------------------------
%PREPROCESSING image resized with high resol.
%--------------------------------------------------------------------------

min_dist=13;
option=0;
%map=150;

Cobblestone=blobdetector(I1,diam, min_dist,option,0);
0
Reply pier 12/7/2010 1:54:04 PM

7 Replies
208 Views

(page loaded in 0.09 seconds)


Reply: