How can I calculate areas of different segmented regions which are in the same image?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello all as I mentioned in the title I want to calculate the areas of the segmented regions which are in the same image. Thus far, I deleted the noises on the image and segmented three objects but I do not know how to calculate the areas of these regions, and this is the code i use :
close all
% Reads the image and names it as RGB (writing file location
% w/ file location and file extension)
% and shows it
figure
subplot(2,3,1)
RGB = imread('C:\Users\hp.user\Desktop\1\image #1.png');
imshow(RGB);
% Firstly, converts the image to gray, after that converts it
% to pure black and white
I = rgb2gray(RGB);
bw = imbinarize(I);
subplot(2,3,2)
imshow(bw);
% binarize function has global threshold level, to change
% this threshold level, we can implemet :
% level = graythresh(I)
% level = 0.5
% bw = imbinarize(I, level);
% global threshold level is 0.6863
% in our image global threshold level is erasing the some
% figures on the image so the threshold level is changed
% to 0.65
level = graythresh(I);
level = 0.65;
bw = imbinarize(I,level);
subplot(2,3,3)
imshow(bw)
% Removing the noise by using morphology functions,
% remove pixels which do not belong to the objects of
% interest
% bwareaopen removes all objects contatining fewer that 36 pixels but not
% removing the noise in the objects
bw = bwareaopen(bw,36);
subplot(2,3,4)
imshow(bw);
% to remove the noise in the objects we do the following code
% fill a gap in the pen's cap
% strel('disk',R) creates a disk-shaped structuring elemnt,
% where R speccifies the radius
se = strel('disk',2);
% bw1 = imclose(bw,se) performs morphological closing on the
% grayscale or binary image bw, returning the closed
% image, bw1
bw = imclose(bw,se);
% fill any holes, so that region props can be used to estimate
% the area enclosed by each of the boundaries
% imfill(bw,locations) performs a flood-fill operation on background pixels
% the input binary image starting from the points specified in
% locations
bw = imfill(bw,'holes');
subplot(2,3,5)
imshow(bw)
% find the boundaries
% calculate boundaries of regions in image and overlay the boundaries
% on the image
[B,L] = bwboundaries(bw,'noholes');
subplot(2,3,6)
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
*boundary = B{k};*
*plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)*
end
-------------------------------------
According to my lecturer, it is not available to use " regionprops" where image includes more than one segmented region to calculate area. Waiting for your helps. Thanks!
0 comentarios
Respuestas (3)
Image Analyst
el 20 de Jul. de 2017
Editada: Image Analyst
el 20 de Jul. de 2017
Your lecturer is completely wrong. Or perhaps you didn't understand exactly what he was trying to say. You certainly CAN measure multiple blobs with one call to regionprops().
See my Image Segmentation Tutorial http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862&sort=downloads_desc
5 comentarios
Wenqi Chen
el 9 de Feb. de 2024
How can I measure different cells in different areas like this? And how to deal with cells on the boundaries?Thanks!
Image Analyst
el 10 de Feb. de 2024
@Wenqi Chen you can turn your boundaries into masks with poly2mask. Then use regionprops to measure the area of the region.
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters.
If you have any more questions, start your own discussion thread (rather than continue here).
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!