Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Cell Boundary Detection

Subject: Cell Boundary Detection

From: Felix Bragman

Date: 23 Sep, 2010 17:57:06

Message: 1 of 6

Dear all,

I am currently having some problems focusing on Image Processing (I am also very new to this toolbox).

I am working with a particularly noisy image which can be viewed via the following url
http://img825.imageshack.us/i/6proj.png/

My main problem is detecting the boundaries of the cell which is the edge of each green "cloud". The blue "ellipses" are the nuclei and the green dots are c-met vesicles.

I need to be able to calculate two distances; the distance of each vesicle to the edge of the nuclei and to the edge of the cell boundary. This will then allow me to calculate relative distances and perform statistical analysis on the movement of the c-met vesicles.

I have easily segmented and labelled the nuclei and the vesicles whilst also fitting ellipses to the nuclei however I have had some problems identifying the cell boundaries.

The code I have used so far may viewed below:

% Read in Microscopy Picture
I = imread('6PROJ.tif');
% Convert into 3 greyscale images
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);

% Use Global Thresholding to image of use
% Use Otsu's Method for greyscaling
% Use Use Gonzalez and Woods iterative method to determine threshold value

T = 0.5*(double(min(G(:))) + double(max(G(:))));
done = logical(0);
while ~done
    C = B >=T;
    Tnext = 0.5*(mean(B(C))) + mean(B(~C));
    done = abs(T- Tnext) < 0.5;
    T = Tnext;
end

T2 = graythresh(B);
T2*255;

% Clean Up Image i.e Remove Pixels under a given value
CELL = bwareaopen(C,40)

% Component Labelling
% Set Properties for each labelled component
% s --> stats for ellipses created
% L --> labelled image

L = bwlabel(CELL);
s = regionprops(L,'all');

% Apply Parametric Equation of Ellipse
% Fit Ellipse to each component
% Apply to Original Image

imshow(I);
hold on

phi = linspace(0,2*pi);
cosphi = cos(phi);
sinphi = sin(phi);

 for k= 1:length(s);
xbar = s(k) .Centroid(1);
ybar = s(k) .Centroid(2);

a = s(k) .MajorAxisLength/2;
b = s(k) .MinorAxisLength/2;

theta = pi*s(k) .Orientation/180;
R = [ cos(theta) sin(theta)
     -sin(theta) cos(theta)];

xy = [a*cosphi; b*sinphi];
xy = R*xy;

x = xy(1,:) + xbar;
y = xy(2,:) + ybar;

plot (x,y,'r','LineWidth',1);
end
hold off

% Sobel Edge Detection for c-met vesicles
% Create new Matrix g

g = edge(G,'sobel');

% Use Global Thresholding
% Apply Same Algorithm

t = 0.5*(double(min(g(:))) + double(max(g(:))));
done = logical(0);
while ~done
    c = g >=t;
    tnext = 0.5*(mean(g(c))) + mean(g(~c));
    done = abs(t- tnext) < 0.5;
    t = tnext;
end

t2 = graythresh(B);
t2*255;

% Detect Cell Boundaries

P = watershed (G);
...
Could someone please "offer" a strategy to determine the cell boundaries.

Thanks a lot,

F

Subject: Cell Boundary Detection

From: ImageAnalyst

Date: 23 Sep, 2010 18:08:09

Message: 2 of 6

I didn't run the code but you said you have already successfully
segmented the objects and that you just need to determine the
boundaries. Have you tried the bwboundaries() function?

Subject: Cell Boundary Detection

From: Felix Bragman

Date: 24 Sep, 2010 14:27:05

Message: 3 of 6

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c7b4ca4f-13d3-474d-8657-5de6af032801@k11g2000vbf.googlegroups.com>...
> I didn't run the code but you said you have already successfully
> segmented the objects and that you just need to determine the
> boundaries. Have you tried the bwboundaries() function?

Dear ImageAnalyst,

I haven't been able to use the bwboundaries function as the current version for the Image Processing Toolbox I am using is v3.1 which does not include the bwboundary function. However, I have seen that it is based on the Moore-Neighbor tracing algorithm so I will have a look at that.

My main problem is in calculating the distances. Having labelled the nuclei and c-met vesicles, I think I can calculate the minimum distance (straight line) between the two. However, I would I then calculate the distance between the c-met vesicle and the cell boundary. Are there any algorithms which would allow me to calculate the distances for all the c-met vesicles in Cell 1,2 and so forth?

Thanks a lot,

F

Subject: Cell Boundary Detection

From: Sean

Date: 24 Sep, 2010 16:07:07

Message: 4 of 6


> Dear ImageAnalyst,
>
> I haven't been able to use the bwboundaries function as the current version for the Image Processing Toolbox I am using is v3.1 which does not include the bwboundary function. However, I have seen that it is based on the Moore-Neighbor tracing algorithm so I will have a look at that.

Does your version have the conv2() function? If so then a very fast way to detect the boundary pixels from a logical mask is:

>>my_bounds = (conv2(double(M),ones(3),'same')<8)&M; %M is mask

%In an example:
M = imread('cameraman.tif')<100;
my_bounds = (conv2(double(M),ones(3),'same')<8)&M;

> My main problem is in calculating the distances. Having labelled the nuclei and c-met vesicles, I think I can calculate the minimum distance (straight line) between the two. However, I would I then calculate the distance between the c-met vesicle and the cell boundary. Are there any algorithms which would allow me to calculate the distances for all the c-met vesicles in Cell 1,2 and so forth?


If I understand you correctly:
Get coordinates of the nuclei and calculate distance from that to the edge using a basic distance formula. Label the my_bounds image from above as you have done before and then find them one at a time.
I would use a cell array:

nlabel = max(labelledImage(:));
my_bounds_cell_array = cell(nlabel,1);
for ii = 1:nlabel
    [r c] = find(labelledImage == ii);
    my_bounds_cell_array{ii} = [r,c];
end

Now put all of your centroid coordinates in another cell array of the same size and use cellfun to calculate distances:
centroid_cell = ...;%centroids where each row of the cell array contains a cell with [r_centroid,c_centroid]

distances = cellfun(@(x,y)sqrt(sum((x(:,1)-y(1)).^2+(x(:,2)-y(2)).^2,2)),my_bounds_cell_array,centroid_cell,'uni',false);

Now to find the minimum distance, use cellfun again:
min_dist = cellfun(@(x)min(x),distances);

%%A few ideas
%I haven't tested this or had it in the MATLAB window so it may be missing a ( or something.
%Sean

Subject: Cell Boundary Detection

From: Felix Bragman

Date: 24 Sep, 2010 17:43:19

Message: 5 of 6

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i7iibb$1hp$1@fred.mathworks.com>...
>
> > Dear ImageAnalyst,
> >
> > I haven't been able to use the bwboundaries function as the current version for the Image Processing Toolbox I am using is v3.1 which does not include the bwboundary function. However, I have seen that it is based on the Moore-Neighbor tracing algorithm so I will have a look at that.
>
> Does your version have the conv2() function? If so then a very fast way to detect the boundary pixels from a logical mask is:
>
> >>my_bounds = (conv2(double(M),ones(3),'same')<8)&M; %M is mask
>
> %In an example:
> M = imread('cameraman.tif')<100;
> my_bounds = (conv2(double(M),ones(3),'same')<8)&M;

My version does include the conv2() function however I cannot visualise whether or not the cell boundaries are being detected properly.

As I have 10 cells in total, is there a way I can trace the boundaries to make sure all 10 boundaries are being detected correctly. Furthermore, do you think in order to calculate the relevant distances to the relevant cells, I could calculate the BoundingBox for each cell. I would then set up 2 loops which would calculate the distances of the c-met vesicles between the cell and nuclei boundaries for each particular bounding box.

This can be illustrated via the following picture
http://img691.imageshack.us/i/exampleth.png/ where the green line is the cell boundary, the red line is the nuclei boundary and the orange dots are vesicles.

I have read a paper where the cell boundaries were interactively determined however I am not sure what this entitles.
>
> > My main problem is in calculating the distances. Having labelled the nuclei and c-met vesicles, I think I can calculate the minimum distance (straight line) between the two. However, I would I then calculate the distance between the c-met vesicle and the cell boundary. Are there any algorithms which would allow me to calculate the distances for all the c-met vesicles in Cell 1,2 and so forth?
>
>
> If I understand you correctly:
> Get coordinates of the nuclei and calculate distance from that to the edge using a basic distance formula. Label the my_bounds image from above as you have done before and then find them one at a time.
> I would use a cell array:
>
> nlabel = max(labelledImage(:));
> my_bounds_cell_array = cell(nlabel,1);
> for ii = 1:nlabel
> [r c] = find(labelledImage == ii);
> my_bounds_cell_array{ii} = [r,c];
> end
>
> Now put all of your centroid coordinates in another cell array of the same size and use cellfun to calculate distances:
> centroid_cell = ...;%centroids where each row of the cell array contains a cell with [r_centroid,c_centroid]
>
> distances = cellfun(@(x,y)sqrt(sum((x(:,1)-y(1)).^2+(x(:,2)-y(2)).^2,2)),my_bounds_cell_array,centroid_cell,'uni',false);
>
> Now to find the minimum distance, use cellfun again:
> min_dist = cellfun(@(x)min(x),distances);
>
> %%A few ideas
> %I haven't tested this or had it in the MATLAB window so it may be missing a ( or something.
> %Sean

Thanks so much for providing some help however I do not understand your methodology notably setting up the arrays. Please bare with me, I am quite new to MATLAB.

Subject: Cell Boundary Detection

From: Sean

Date: 24 Sep, 2010 19:41:04

Message: 6 of 6


> Thanks so much for providing some help however I do not understand your methodology notably setting up the arrays. Please bare with me, I am quite new to MATLAB.

I privately emailed you some code to help at least a little. If it doesn't get past your spam filter; post back on here.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us