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

조회 수: 12 (최근 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;

Community Treasure Hunt

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

Start Hunting!

Translated by