How to plot together a surface plot and a DICOM image without loosing the colors of the surface plot?

8 views (last 30 days)
Hi everyone!
I'm trying to plot together a surface plot done with 'surface' function, which represents the dose absorbed per voxel, over a DICOM image from a CT scan. As you can see, firstly I plot succesfully the surface plot and after I try to plot a DICOM image using 'dicomread' function. As you can see in the pictures, both the surface plot and the image are succesfully represented whilst they are separated (figure 1 and 2). However, once I plot them together, everything turn to be in greyscale (figure 3), and the colorbar just shows the range of HU numbers window.
I assume it must be something related with converting the DICOM file to an RGB image but keeping the greyscale colours, but, honestly, I've tried lots of things but no one works for me. Is there anyone who can help me, please?
Thank you all in advance.
pd: I leave attached the code used in my attemps (lines with % are just past attemps to make it work, extracted from other questions in this forum).
figure;
s=surface(dose{29});
s.EdgeColor='none';
s.FaceColor='interp';
alpha color
alpha scaled
axis([0 phantdim(1) 0 phantdim(2)])
colorbar
set (gca, 'ydir', 'reverse' )
hold on
figure;
info = dicominfo('Prostate__Bob__12345678.ct.028.dcm');
imag = dicomread(info);
% if size(imag,3) == 1
% imag = repmat(imag,[1 1 3]);
% end
% imag = flipud(imag);
% image(imag,'xdata',[0 188],'ydata',[0 127])
imshow(imag,[50 2000]);
axis([0 phantdim(1) 0 phantdim(2)])
xlabel('x voxel');
ylabel('y voxel');
title('Absorbed dose distribution in CT slice number 29')
% axis equal

Accepted Answer

DGM
DGM on 10 Jul 2023
Edited: DGM on 10 Jul 2023
Convert the image to standard data ranges using mat2gray(), then expand it so that it's RGB. The objective here is to create a standard RGB array so that it's no longer treated as a pseudocolor image. All single-channel images, contour(), and surf() plots all use the same axes colormap. Making the image RGB breaks its dependence on the colormap. In the case of using imshow(), that also keeps it from altering the current colormap to gray().
% draw the image first
displayimg = mat2gray(imag,[50 2000]);
displayimg = repmat(displayimg,[1 1 3]);
imshow(displayimg)
% then plot things atop it
s = surface(dose{29});
% ... etc
At that point, you would plot your scatter()/contour()/surf() atop the image. If you plotted them before the image, they'll be beneath it. Either plot things in the order necessary to stack them appropriately, or use uistack() to reorder them afterwards.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!