How to create ROI then know the total pixel number in ROI

조회 수: 7(최근 30일)
mohd akmal masud
mohd akmal masud 2022년 2월 26일
댓글: yanqi liu 2022년 3월 1일
Hai Everyone, Anyone know how to create ROI (as red circle) in my image dicom (3D) (as attached), then I can know the total pixel counts in ROI it self
This is my coding to view the images. also the function of imshow3D
%% Read main set data
clc
clear all
close all
[spect map]=dicomread('I-13125610N1.dcm');
info = dicominfo('I-13125610N1.dcm');
gp=info.SliceThickness;
ps=info.PixelSpacing;
spect=(squeeze(spect));%smooth3
aa=size(spect);aa=aa(3);
figure, imshow3D(spect)
  댓글 수: 1
yanqi liu
yanqi liu 2022년 3월 1일
may be upload I-13125610N1.dcm to analysis

댓글을 달려면 로그인하십시오.

채택된 답변

AndresVar
AndresVar 2022년 2월 27일
편집: AndresVar 2022년 2월 27일
You can use drawcircle to create a circular roi and then make a mask form it. Then you can sum or find the number of non-zero elements in the mask: Circular region of interest - MATLAB (mathworks.com)
This is an example using matlab's peppers image. When you run it and the image is displayed just click to draw a circle. Modify the circle to show the number of pixels.
clear;
close all;
I = imread('peppers.png');
imshow3D(I);
roi = drawcircle; % interactive
roi.HandleVisibility='off';
addlistener(roi,'MovingROI',@allevents);
addlistener(roi,'ROIMoved',@allevents);
function allevents(src,evt)
% when the roi was modified update label with the number of pixel inside
mask = src.createMask;
count = nnz(mask);
src.Label = sprintf('%g',count);
end
BTW by total pixel counts you mean the number of pixel? or the total intensity counts? if you want intensity counts then you can apply the mask to the image and just sum. sum(im(mask),'all')
  댓글 수: 1
AndresVar
AndresVar 2022년 2월 27일
Added Handlevisibility 'off' in the answer so that imshow3d can still advance slices.
Here is a verision of allevents that gets the intensity counts also
function allevents(src,evt)
% when the roi was modified update label with the number of pixel inside
mask = src.createMask;
count = nnz(mask);
% find the image data in the imshow3d axis
imdata = findall(src.Parent,'Type','Image');
imdata = imdata(1).CData; % there should be only 1 anyway
intcount = sum(imdata(mask),'all');
src.Label = sprintf('%g (%g)',count,intcount);
end

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by