Calculating percentage of brown pixels over other colors in tumor

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Simon Chan
Simon Chan am 23 Jan. 2022
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));
  1 Kommentar
Ugur Akca
Ugur Akca am 23 Jan. 2022
Thank you so much for your help, it is working great and right now,my results is more reasonable.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by