Calculating area of irreguar border shape

2 views (last 30 days)
Hi all, I am developing a system to calculate border irregularity in cell images. For this i need to know the perimeter and area of the cell in the image. I have been able to create a border around the cell by using the following code:
files = uigetfile('*.jpg', 'Please Select Image','multiselect','on');
if (iscell(files))
for count = 1:numel(files)
BorderLocater(files{count});
end
else
BorderLocater(files);
end
-----------------------------------------------
function BorderLocater(image)
I = rgb2gray(imread(image));
figure, imshow(I), title('Original Cell Image');
text(size(I,2),size(I,1)+15, ...
'converted to grayscale', ...
'FontSize',7,'HorizontalAlignment','right');
[junk, threshold] = edge(I, 'sobel');
fFr = .5;
BWs = edge(I,'sobel', threshold * fFr);
figure, imshow(BWs), title('Binary Gradient Mask');
se90 = strel('line', 3, 90);
se0 = strel('line', 3, 0);
BWsdil = imdilate(BWs, [se90 se0]);
figure, imshow(BWsdil), title('Dilated Gradient Mask');
BWdfill = imfill(BWsdil, 'holes');
figure, imshow(BWdfill);
title('binary image with filled holes');
BWnobord = imclearborder(BWdfill, 4);
figure, imshow(BWnobord), title('Partial Images Removed');
seD = strel('diamond',1);
BWfinal = imerode(BWnobord,seD);
BWfinal = imerode(BWfinal,seD);
figure, imshow(BWfinal), title('Segmented Image');
BWoutline = bwperim(BWfinal);
Segout = I;
Segout(BWoutline) = 255;
figure, imshow(Segout), title('Cell with Border Outline');
return
I got my cell images off Google, and so have no idea of the spatial resolution. I was wondering if anyone knew how to calculate a value for the area (doesn't have to be in cm^2)
Thanks in advance
  2 Comments
Ben
Ben on 8 Apr 2014
I am unsure of the appropriate syntax of how to execute bwarea on the image BWoutline?

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 8 Apr 2014
Assuming you have a good binary image, you do this
measurements = regionprops(logical(binaryImage), 'Area');
allAreas = [measurements.Area];
DON'T USE IMAGE AS THE NAME OF YOUR VARIABLE. It's a built in function and you will overwrite it if you do that. It's never a good idea to use the names of functions or keywords as variable names. I probably wouldn't do it the same way as you but it depend on what your image looks like. For example, I wouldn't burn the perimeter into the image like you're doing - I'd use bwboundaries() and just display the boundaries in the overlay above the image. I'd maybe change some other things too, but whatever, if it works, then fine.
  4 Comments
Ben
Ben on 9 Apr 2014
Thank you ever so much for your help! One final Question: Is it possible to convert the results of regionprops() from a structure to a double? I need to use those values found in an equation, but it will not work with structure data type
Image Analyst
Image Analyst on 9 Apr 2014
Yes. I did that for the area. See the allAreas array? It concatenates all the Area fields from every structure in the structure array into one single double vector. You can do the same for perimeter or any other measurement.
allPerimeters = [measurements.Perimeter];

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!