MATLAB Answers

Calculating the area of a selected region as a percentage of total image

3 ビュー (過去 30 日間)
Jenna Wahbeh
Jenna Wahbeh 2020 年 10 月 5 日
回答済み: Nitin Kapgate 2020 年 10 月 8 日
I have an image of bone on an implant. I would like to get the percentage of the implant covered by bone. I have written code for collecting pixels with a value less than 250 and pixels greater than 250 and dividing them, but the background is all white. How can I crop the image to get rid of the background or is there a more efficient/exact way to get this value? The photo is like the one attached but with a white background and taken from straight above. Thank you!

  1 件のコメント

Luciano Garim
Luciano Garim 2020 年 10 月 5 日
Hi,Jenna Wahbeh.
You may use some image segmentation technique. Algorithms like k-means are efficient when want to segment you image.
Other option is use the Image processing toolbox. The option threshold color is a good one.
I hope helped you!

サインインしてコメントする。

回答 (1 件)

Nitin Kapgate
Nitin Kapgate 2020 年 10 月 8 日
You can use the roipoly function to interactively specify polygonal region of interest (ROI) and create a binary mask for the same. This binary mask can be then used to calculate the area of ROI as a percentage of total image.
You can use the following code snippet to begin with:
% Load an inbuilt MATLAB image
I = imread('eight.tif'); % Read your own image here
% Interactively select the polygon ROI
% For more information about interactive selection of ROI, refer:
% https://www.mathworks.com/help/images/ref/roipoly.html#mw_826b4f37-e92a-4a20-ab6f-c2aa6d12d500
BW = roipoly(I); % Binary mask image
% Display input image and the binary mask image
figure;
imshow(I);
figure;
imshow(BW); % The white portion is ROI
% number of white pixels in the binary image(Area of ROI)
nWhite = sum(BW(:));
% number of black pixels in the binary image(Area of background)
nBlack = numel(BW) - nWhite;
% ROI as a percentage of Total Image
percentageROI = (nWhite / (nWhite + nBlack)) * 100;

  0 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by