Calculating area of irreguar border shape

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

Billy
Billy 2014년 4월 7일
Why doesn't bwarea work?
Ben
Ben 2014년 4월 8일
I am unsure of the appropriate syntax of how to execute bwarea on the image BWoutline?

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2014년 4월 8일

0 개 추천

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

Ben
Ben 2014년 4월 8일
편집: Ben 2014년 4월 8일
So change 'image' in BorderLocater(image)?? and where would i execute bwboundaries()? Edit: Could I also use this to calculate the perimeter? Thanks
Image Analyst
Image Analyst 2014년 4월 9일
Yes. And also inside the function where you use "image".
And yes, though I'd probably use regionprops() to determine perimeter length if you need that.
Ben
Ben 2014년 4월 9일
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
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];

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

Ben
2014년 4월 7일

댓글:

2014년 4월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by