Masking dicom multiple files with same mask

2 visualizaciones (últimos 30 días)
Aga
Aga el 16 de Mayo de 2014
Comentada: Stelios Fanourakis el 28 de Mzo. de 2018
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!

Respuesta aceptada

Henric Rydén
Henric Rydén el 19 de Mayo de 2014
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 comentarios
Aga
Aga el 19 de Mayo de 2014
thanks a lot! yes, indeed repmat did the job!
Stelios Fanourakis
Stelios Fanourakis el 28 de Mzo. de 2018
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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by