MATLAB: Calculating area of irreguar border shape

areacalculatecellsimage processing

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

Best Answer

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.