Calculating percentage of brown pixels over other colors in tumor

2 次查看(过去 30 天)
Hi everyone,
I want to calculate percentage of white signals over black ones (but just in the tumor roi). I mean the code that I am using now calculating all black pixels in picture so gives me small percantage but I need calculate just in the tumor area.
Can you help me to remove other black parts from calculations?
THANKS

采纳的回答

Simon Chan
Simon Chan 2022-1-23
Define the tumor roi and then calculate the white pixels inside the roi:
clear;clc;
rawdata=imread('image.png');
BW = rgb2gray(rawdata);
J = imclearborder(BW); % Clear pixels in the boundary
black = sum(BW==0,'all');
white = sum(BW~=0,'all');
tiledlayout(1,2,'TileSpacing','none','Padding','none')
nexttile
imshow(rawdata,[]);
title(sprintf('Original Image, Black Pixel: %d, White Pixel: %d',black,white));
BW2=bwconvhull(J); % Finding the mask
BW3 = bwperim(BW2); % Finding the perimeter, only for figure display
[r,c]=find(BW3);
for k = 1:length(r)
rawdata(r(k),c(k),1)=255; % Set the pixels in the perimeter to red
end
black = sum((BW==0).*BW2,'all');
white = sum((BW~=0).*BW2,'all');
nexttile
imshow(rawdata);
title(sprintf('Mask Region, Black Pixel: %d, White Pixel: %d',black,white));

更多回答(0 个)

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by