Drawing a single ROI and then using it on multiple images in 3D matrix

4 visualizzazioni (ultimi 30 giorni)
Hello everyone,
I am relatively new to matlab, and I am currently working on a medical image segmentation of a multiple images stored in a 3D matrix. I was trying to draw a ROI on a first slice and then use that ROI for all other slices to implement segmentation algorithm on them. But, after multiple tries I did not come up with a solution. The best what I was able to do is to draw ROI on EVERY single slice but that is taking to much time. Is there any easier way I could do this? Perhaps there's a way to automate or semi-automate this process so I don't have to draw ROI at each slice? Somehow I think that there is a simple solution to this, but I just can not find it.
CT is my 3D matrix that contains images. My code for drawing ROI is:
for i = 1:size(CT,3)
figure; imshow(CT (:,:,i), []);
hFH = imfreehand();
binaryImage(:,:,i) = hFH.createMask;
xy = hFH.getPosition();
blackMaskedImage =CT;
blackMaskedImage(~binaryImage) = 1;
setPositionConstraintFcn(hFH,xy);
close ();
end
Thanks in advance.

Risposte (2)

Image Analyst
Image Analyst il 7 Ott 2014
Maybe something like this (untested):
hFig = figure; % Bring up a new figure.
for k = 1 : size(CT, 3)
subplot(1, 3, 1);
cla;
imshow(CT(:,:,i), []);
drawnow;
if k == 1
hFH = imfreehand();
binaryImage = hFH.createMask;
subplot(1, 3, 2);
cla;
imshow(binaryImage);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
drawnow;
% xy = hFH.getPosition(); % Unused
end
blackMaskedImage = CT(:,:,i) .* uint8(binaryImage);
subplot(1, 3, 3);
cla;
imshow(blackMaskedImage);
drawnow;
end

Mario
Mario il 7 Ott 2014
I tested it and it is displays this error:
Error using .*
Integers can only be combined with integers of the same class, or scalar doubles.
Error in segmentation (line 51)
blackMaskedImage = CT(:,:,i) .* uint8(binaryImage); %when I put here binaryImage(:,:,i) it is doing something
When I put "binaryImage(:,:,i)" it's doing something on all images, but I do not know what is it doing. And also I need binaryImage and blackMaskedImage to be also 3D matrix since that is where I need those ROIs to be stored because I will be using that ROI to segment my images.
I hope I explained it for you to understand.
Thanks!

Community Treasure Hunt

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

Start Hunting!

Translated by