Calculating percentage of brown pixels over other colors in tumor

2 views (last 30 days)
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

Accepted Answer

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

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!