Calculating the area of the black objects in mm2
3 ビュー (過去 30 日間)
古いコメントを表示
hi, i am struggling to find the area of whole black objects in the image down blown and i dont know how to convert this area from pixels to mm2![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1697826/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1697826/image.png)
0 件のコメント
回答 (2 件)
Ayush Modi
2024 年 5 月 17 日
Hi Mathew,
You can calculate the area of all black objects using the function regionprops. Here is the sample code for your reference:
grayImage = rgb2gray(image); % Convert to grayscale if necessary
binaryImage = imbinarize(grayImage, 'adaptive'); % Convert to binary image
binaryImage = ~binaryImage; % Invert if necessary so objects of interest are white
cc = bwconncomp(binaryImage);
stats = regionprops(cc, 'Area');
allAreas = [stats.Area];
totalAreaInPixels = sum(allAreas);
Refer to the below Mathworks documentation for more information on regionprops function:
To convert the area into mm2, you would need to know scale of the image (pixels/mm). See the below thread for more information:
0 件のコメント
Image Analyst
2024 年 5 月 17 日
You need to know the length of your field of view or of some known thing in the image. See my attached spatial calibration demo.
To get a list of all the areas of the black blobs in your binary image, you can do
props = regionprops(~binaryImage, 'Area'); % Measure areas.
allAreas = [props.Area];
histogram(allAreas); % If you want to see a particle size distribution.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Segmentation and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!