How to save an average voxel values from multiple ROIs in a dicom slice?

2 visualizaciones (últimos 30 días)
I want to extract an average voxel values form each ROIs drawn on dicom slice. How can I do that? Using the following code I read the dicom slice, then draw 4 rois, now I want to save the ROI intensty statistics such as the average, minimum, maximum and standard deviation in voxel values within the ROI. How to complete the code below to get that done?
close all; clear; clc;
%% load and read dicom slice
info_ct = dicominfo('37.100.dcm');
Height = info_ct.Height;
Width = info_ct.Width;
slope = info_ct.RescaleSlope;
intercept = info_ct.RescaleIntercept;
ct_matrix = slope * double(dicomread(info_ct)) + intercept; % respect slope and intercept
%% Now, draw 4 ROIs on dicom slice
figure
N = 4;
I = imshow(ct_matrix(:,:,1), [-800 1000]);
% Define the Region of Interest
e = drawcircle(gca, 'Label', '1'); % draw 1 ROI
f = drawcircle(gca, 'Label', '2'); % draw 2 ROI
g = drawcircle(gca, 'Label', '3'); % draw 3 ROI
h = drawcircle(gca, 'Label', '4'); % draw 4 ROI
% Create a Mask
BW1 = createMask(e, I); % 1s at ROI and 0s everywhere
BW1 = double(BW1);
BW2 = createMask(f, I);
BW2 = double(BW2);
BW3 = createMask(g, I);
BW3 = double(BW3);
BW4 = createMask(h, I);
BW4 = double(BW4);
....

Respuesta aceptada

Rik
Rik el 16 de Mzo. de 2020
Editada: Rik el 17 de Mzo. de 2020
BW1 = createMask(e, I);
Data=I(BW1);
Now you can calculate the statistics you need.
I would suggest using a struct array:
% Generate example data (yes, it is an MRI, but the code works)
D=load('mri');D=double(D.D);
ct_matrix= ( D/max(D(:)) *1800 ) -800;
f=figure(1);clf(f)
N = 4;
IM=ct_matrix(:,:,1);
I = imshow(IM, [-800 1000]);
set(f,'WindowState','maximized')
% Define the Region of Interests
H=cell(N,1);
for n = 1:N
H{n} = drawcircle(gca, 'FaceAlpha', 0.05, 'Label', sprintf('%d',n));
end
% Extract parameters
output=struct;
for n = 1:N
BW = createMask(H{n}, IM);
data = IM(BW);
%or:
% BW = createMask(H{n}, I.CData);
% data = I.CData(BW);
output(n).mean = mean(data);
output(n).SD = std(data);
end
  7 comentarios
Rik
Rik el 18 de Mzo. de 2020
You can store the logical matrices.
blues
blues el 18 de Mzo. de 2020
Hi Rik, how can I copy ROIs from previous image and apply it to the next image using the following code? Could you give me some insights?
% Generate example data (yes, it is an MRI, but the code works)
D = load('mri');D = double(D.D);
ct_matrix= ( D/max(D(:)) *1800 ) -800;
f=figure(1);clf(f)
N = 4;
IM = ct_matrix(:,:,1);
I = imshow(IM, [-800 1000]);
set(f,'WindowState','maximized')
% Define the Region of Interests
H = cell(N,1);
for n = 1:N
H{n} = drawcircle(gca, 'FaceAlpha', 0.05, 'Label', sprintf('%d',n));
end
% Extract parameters
output = struct;
for n = 1:N
BW = createMask(H{n}, IM);
data = IM(BW);
%or:
% BW = createMask(H{n}, I.CData);
% data = I.CData(BW);
output(n).mean = mean(data);
output(n).SD = std(data);
end
% save mask.mat (ROIs) data
filename = 'ROIs.mat';
save(filename, 'BW');
%% load next image
IM1 = new_matrix(:,:,1);
I1 = imshow(IM1, [-800 1000]);
set(f,'WindowState','maximized')
% Apply the same ROIs (defined above) to this image, data from ROIs.mat file, and save statistics
% how can I move forward?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre DICOM Format en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by