Masking dicom multiple files with same mask
2 次查看(过去 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!
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Read, Write, and Modify Image 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!