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!