Calculating area of irreguar border shape
2 views (last 30 days)
Show older comments
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
Accepted Answer
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
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];
More Answers (0)
See Also
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!