How to calculate the total pixel value in volume segmentation

8 ビュー (過去 30 日間)
mohd akmal masud
mohd akmal masud 2022 年 5 月 7 日
コメント済み: mohd akmal masud 2022 年 5 月 9 日
Dear all,
I have code below. How to calculate the total counts (represent the pixel value) in every volume segmentation P
All the image attached.
% For binary images (png format, each pixel just have value 1 and 0.)
clc
clear all
close all
dataSetDir = fullfile('C:\Users\Akmal\Downloads\1.2.840.113619.2.280.2.1.6032022125618360.139679786-20220425T063142Z-001\1.2.840.113619.2.280.2.1.6032022125618360.139679786');
imageDir = fullfile(dataSetDir,'gradieweigbwaftersegmentationpngTCEswari');
imds = imageDatastore(imageDir);
for i = 1:45
subplot(13,11,i)
I = readimage(imds,i);
% binary
Is{i} = logical(I);
imshow3D(I)
end
% For 3D images spect
myFolder = ('C:\Users\Akmal\Downloads\1.2.840.113619.2.280.2.1.6032022125618360.139679786-20220425T063142Z-001\1.2.840.113619.2.280.2.1.6032022125618360.139679786\dcmeswariint16128x128');
filePattern = fullfile(myFolder, '*.dcm'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for K = 1 : length(theFiles)
baseFileName = theFiles(K).name;
fullFileName = fullfile(theFiles(K).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
P(:,:,K) = dicomread(fullFileName);
P(:,:,K) = (P(:,:,K)) .* int16( Is{K} );
% P(:,:,K) = double(uint8(K).*uint8(Is{K}));
end

採用された回答

DGM
DGM 2022 年 5 月 7 日
I'm not quite sure if this is what you're after, but this:
pnz = nnz(P);
will give you the total number of nonzero elements in the pagewise intersection of P and Is.
So it's not necessarily the volume of Is, but the intersection of the two volumes.
  2 件のコメント
mohd akmal masud
mohd akmal masud 2022 年 5 月 8 日
編集済み: mohd akmal masud 2022 年 5 月 8 日
Dear DGM,
My image P as below, where all the volume segmentation have the pixel value.
if I use you code pnz = nnz(P); , the asnwer is 589.
589 its look like give the total number pixel for all the six volume segmentation.
What I need is the total pixel value for each volume. As picture, there are index (represent the pixel value), I need the total pixel value for it volume.
DGM
DGM 2022 年 5 月 8 日
編集済み: DGM 2022 年 5 月 8 日
Not exactly sure if you're after the volumes of the objects in Is or the sum of the regions in P intersecting those volumes. Either way, this calculates both.
It makes sense to arrange Is as a 3D array instead of as a cell array.
% For binary images (png format, each pixel just have value 1 and 0.)
dataSetDir = fullfile('');
imageDir = fullfile(dataSetDir,'gradieweigbwaftersegmentationpngTCEswari');
imds = imageDatastore(imageDir);
Is = false(128,128,45); % preallocate
for i = 1:45
%subplot(13,11,i)
I = readimage(imds,i);
% binary
Is(:,:,i) = logical(I);
%imshow3D(I)
end
% For 3D images spect
myFolder = ('dcmeswariint16128x128');
filePattern = fullfile(myFolder, '*.dcm'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
P = zeros(128,128,45,'int16'); % preallocate
for K = 1 : length(theFiles)
baseFileName = theFiles(K).name;
fullFileName = fullfile(theFiles(K).folder, baseFileName);
%fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
P(:,:,K) = dicomread(fullFileName);
% this shouldn't be needed unless it's for something else
%P(:,:,K) = (P(:,:,K)) .* int16( Is(:,:,K) );
end
% calculate things
CC = bwconncomp(Is); % default uses 26-connectivity (a full 3x3x3 nhood) for 3D images
volumes = cellfun(@numel,CC.PixelIdxList) % the volumes of the objects in Is
volumesums = zeros(CC.NumObjects,1); % sum of pixel values in P as selected by Is
for k = 1:CC.NumObjects
volumesums(k) = sum(P(CC.PixelIdxList{k}));
end
volumesums

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 5 月 8 日
Use regionprops3 and ask for 'Volume'.
  3 件のコメント
Image Analyst
Image Analyst 2022 年 5 月 9 日
Get the MeanIntensity (one of regionprops3 measurements) and multiply it by the Volume. This will give you the "Total Integrated Graly Level" inside the volume.
mohd akmal masud
mohd akmal masud 2022 年 5 月 9 日
I see..Okay thank you Image Analyst.

サインインしてコメントする。

カテゴリ

Help Center および File Exchange3-D Volumetric Image Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by