Masking dicom multiple files with same mask

15 次查看(过去 30 天)
Dear all,
I want to mask dicom files (#slices>100) with same mask and than do the histogram for all slices of the unmasked part and masked separately . For single (1 slice file) it works perfect:
test_image=dicomread(fullfile(pathname, filename) );
imagesc(test_image)
test_if=imfreehand;
notmask=createMask(test_if);
mask=~notmask; //since I want to have everything except mask area
test_image(mask);
test_image(~mask)=NaN;
imagesc(test_image)
Histogram also works:
hist(double(test_image(:)).
But I can't find the right indexing method for masking all slices. I tried:
for cnt=1:p X(:,:,1,numel(dicomlist))=dicomread(fullfile(pwd, dicomlist(cnt).name)); % Xmask(:,:,1,numel(dicomlist))=double(X(:,:,1,numel(dicomlist))).*mask; % Xmask(find(Xmask==0))=NaN;
end (the upper sometimes work)
or in a different way, similar to single file (below differen tries):
Xmask(mask,1,numel(dicomlist));
Xmask(mask, numel(dicomlist);
Xmask(:,:,1,p)=X(mask);
That all failedm, usually with an error that indexing has to be placed in the end or there is dimension mismatch.
So I am both curious and confused..What is the proper way of doing that? Thank you in advance!

采纳的回答

Henric Rydén
Henric Rydén 2014-5-19
Hi,
you should load all your dicom files into a 3D matrix. Then, make your mask 3D using repmat. Your code should look something like this: (I haven't tried it so expect errors)
slices = 50; % I don't know how many slices you have, change this
test_image=dicomread(fullfile(pathname, filename));
myAwesomeData = zeros(size(test_image,1),size(test_image,2), slices);
myAwesomeData(:,:,1) = test_image;
test_if=imfreehand;
mask=createMask(test_if);
test_image(mask)=NaN;
figure;
imagesc(test_image)
for idx = 2 : slices
myAwesomeData(:,:,idx) = dicomread(dicomlist(idx).name);
end
maskedData = myAwesomeData(repmat(mask,1,1,slices));
  2 个评论
Aga
Aga 2014-5-19
thanks a lot! yes, indeed repmat did the job!
Stelios Fanourakis
Stelios Fanourakis 2018-3-28
Excuse me. To this line myAwesomeData(:,:,1) = test_image;
It gives me the error 'Assignment has more non-singleton rhs dimensions than non-singleton subscripts'
what does this mean?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by