Code covered by the BSD License  

Highlights from
Cell_area

image thumbnail

Cell_area

by

 

For phase/dic images. Centroid and area written to a file, images overlapped and written to a file.

Cell_area.m
% ------------------------------------------------------------------------
% Cell_area is an interactive tool which allows the user to input images 
% of cells and easily subtract out background (especially in the case of DIC 
% or phase images)and then collect images of the finalized cell and calculate 
% the centroid and area of the cell. 
% 
% Cell_area launches an input dialogue which allows the user to select the 
% image file name, the desired threshold, the desired disk element size for 
% background subtraction, and the desired disk element size for the imfill 
% command.  Threshtool will allow the user to identify the optimal
% threshold on a test image before running the fully automated program, and
% will pause the test progam.  BE SURE TO EXPAND THE threshtool image gui
% otherwise it will not accept the user input and the operation will pause.
% 
% The program will display several figures, including the original image,
% the background subtracted image with the imclose and imfill command applied,
% the merged image, for comparison, and the finalized image of only the 
% largest cell in the image.  The program will also write several files to 
% the open user directory, including the merged image of the original image 
% and the imfill and imclose applied image, as well as the finalized image of 
% only the largest cell which statistics were derived from.
% 
% This program will also write two text files, in the structure of 'filename'
% IC.txt or 'filename'IA.txt.  IC is the centroid position in x, y format.  
% IA is the area of the largest object in pixels.
% 
% Daniel J Gould April, 2010
% 
% 
% See ALSO IMTOOLBOX IMFILL IMCLOSE bwlabel imopen regionprops. 
% ------------------------------------------------------------------------

clear all;
close all;
indata=inputdlg({'image file','threshold_automated? n=1/y=2','threshold(if automated)','background_disk_size','closing_disk_size'});
ima = imread(indata{1});
TA = str2num(indata{2})
T = str2num(indata{3});
BD = str2num (indata{4});
CD = str2num (indata{5});
[rows cols dims] = size(ima);
% if(dims == 3)
%     ima = rgb2gray(ima);
% end

% figure; imshow(ima);
% img=imread(indata{1});
% ima=rgb2gray(img);
background=imopen(ima,strel('disk',BD));
figure; imshow(background);
I2=imsubtract(ima,background);
figure; imshow(I2);
I3=imadjust(I2);
if TA==1
    lev = thresh_tool(I3)
    I4=I3>lev;
end
if TA==2
    I4=I3>T
end
figure; imshow(I4);
imcl=imclose(I4,strel('disk',CD));
figure; imshow(imcl);
imclfil=imfill(imcl,'holes');
figure; imshow(imclfil);
imclfil2=uint8(255*imclfil)
img3(:,:,2)=ima;
img3(:,:,1)=imclfil2;
img3(:,:,3)=zeros(507,446);
figure;imshow(img3);
imwrite(img3,strcat('merged',indata{1},'.tif'));
bw2=bwlabel(imclfil2);
STATS = regionprops(bw2, 'basic');
max([STATS.Area]);
biggrain = find([STATS.Area]==(max([STATS.Area])));
IC =(STATS(biggrain).Centroid);
IA =(STATS(biggrain).Area);
dlmwrite(strcat(indata{1},'IC','.txt'), IC,'delimiter','\t','precision',6);
dlmwrite(strcat(indata{1},'IA','.txt'), IA,'delimiter','\t','precision',6);
IMW=bwlabel(imclfil2);
STATS= regionprops(IMW,'basic');
biggrain=find([STATS.Area]==(max([STATS.Area])));
imshow(IMW==biggrain);
figure; imshow(IMW==biggrain);
imwrite((IMW==biggrain),(strcat('bigcell',indata{1})));

Contact us