how to calculate area of different components in an image?
3 次查看(过去 30 天)
显示 更早的评论
I created a matrix by using the Randi function. I then converted the matrix to an image using mat2gray. The resulting image was black and white. Can you please tell me how to get the area and define the shape of all the white components of the image?
i used the following code:
A = randi([0 1], [10 10]);
B= mat2gray(A);
i used the regionprops to get its area, but i want the individual area of the components.
0 个评论
回答(1 个)
Prabhan Purwar
2020-2-11
Using the matrix B provided and assuming connectivity to be along the horizontal or vertical direction only.
Following code may help:
A = randi([0 1], [10 10]);
B = mat2gray(A);
% To consider the horizontal or vertical connectivity set connectivity parameter = 4.
cc = bwconncomp(B, 4);
% Calculate area of individual connected component.
Area = regionprops(cc,'Area');
Output:
Area= 14 6 4 17 3 2 1 3 1 1 ;
Refer to the following links for more information:
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!