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

3 views (last 30 days)
blues on 16 Mar 2020
Commented: blues on 18 Mar 2020
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;
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
BW1 = createMask(e, I); % 1s at ROI and 0s everywhere
BW1 = double(BW1);
BW2 = double(BW2);
BW3 = double(BW3);
BW4 = double(BW4);
....

Rik on 16 Mar 2020
Edited: Rik on 17 Mar 2020
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)
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
data = IM(BW);
%or:
% data = I.CData(BW);
output(n).mean = mean(data);
output(n).SD = std(data);
end
Rik on 18 Mar 2020
You can store the logical matrices.
blues on 18 Mar 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)
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
data = IM(BW);
%or:
% data = I.CData(BW);
output(n).mean = mean(data);
output(n).SD = std(data);
end
filename = 'ROIs.mat';
save(filename, 'BW');
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?