How to calculate the area of this object in an image?
9 ビュー (過去 30 日間)
古いコメントを表示
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1565304/image.jpeg)
2 件のコメント
Walter Roberson
2023 年 12 月 11 日
Is the "object" everything that is black?
Is the "object" everything that is 8-connected to the largest black area -- so excluding the small stand-alone black areas?
Is the "object" the white area inside the black area?
回答 (1 件)
Walter Roberson
2023 年 12 月 11 日
"area" could potentially refer to a physical quantity rather than just a pixel count.
In order to calculate as a physical quantity, either you have to have existing information about the physical sizes of the pixels, or else you need to have some reference information in the image that you can relate to physical quantities as a calibration. For example if there were a ruler in the image that was known to span 1 mm then the size of the ruler could be determined and knowing the associated physical size, the physical dimensions of the represented object could be calculated.
filename = "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1565304/image.jpeg";
img = imread(filename);
bw = im2bw(img);
object_pixels_count = nnz(~bw)
%for the purposes of illustration, we will not assume that individual
%pixels are square, and we will assume that **somehow** you know the actual
%physical size of each pixel
pixel_height = 2.54/80;
pixel_width = pixel_height * 4/3;
%then
object_area = object_pixels_count * pixel_height * pixel_width
4 件のコメント
Image Analyst
2023 年 12 月 11 日
See my attached spatial calibration demo to convert pixels into mm.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!