How to show the image slice from the below example?

5 views (last 30 days)
Hello, I want to show the image slice from the below example, where CT and SPECT both are image array with the same width, size and spacing.
% This is a part of the code
% Visualize the CT and SPECT together
for m = 1:199
CT_img = new_CT(:,:,m);
SPECT_img = SPECT(:,:,m);
final_img = imfuse(CT_img, SPECT_img);
% Visualize CT and SPECT together
imshow(final_img, [-800 1000]);
end
% Now, I want to see the overlapped slices one by one, so I want somethig like:
show_20th_slice = imshow(final_img(:,:,20)) %...>> but this says: "Index in position 3 exceeds array bounds (must not exceed 3)."
How can I do this?

Accepted Answer

Walter Roberson
Walter Roberson on 26 Feb 2021
% This is a part of the code
% Visualize the CT and SPECT together
for m = 1:199
CT_img = new_CT(:,:,m);
SPECT_img = SPECT(:,:,m);
final_img(:,:,:,m) = imfuse(CT_img, SPECT_img);
% Visualize CT and SPECT together
imshow(final_img(:,:,:,m), [-800 1000]);
end
% Now, I want to see the overlapped slices one by one, so I want somethig like:
show_20th_slice = imshow(final_img(:,:,:,20))
I am not sure at the moment why you are getting back color images instead of grayscale, but your error message would have been different if you were getting back grayscale.
  4 Comments
blues
blues on 26 Feb 2021
One additional thing: When I use imfuse the colormap of CT image becomes green and SPECT becomes pink. Is there a way to change the colormap to grey and hot or jet? See attached.
Thank you, Walter, for your help. Have a great weekened.
Walter Roberson
Walter Roberson on 28 Feb 2021
im1 = imread('cameraman.tif');
im2 = rgb2gray(imread('flamingos.jpg'));
im2 = imresize(im2, size(im1));
fused_by_function = imfuse(im1, im2);
fused_manually = cat(3, im2, im1, im2);
subplot(2,1,1);
imshow(fused_by_function);
title('imfuse()')
subplot(2,1,2)
imshow(fused_manually);
title('manual fuse')
max(abs(double(fused_by_function(:)) - double(fused_manually(:))))
ans = 12
We can see from this that imfuse(A,B) is effectively the same as putting B into the red and blue panes and A into the green pane.
And that in turn tells us that using a different colormap would not be easy, because it is not really "calculating" a color for each pixel, and is more "just letting it happen". So you would need a quite different approach.
Perhaps something like:
alpha = 0.7;
cmap1 = gray(256);
cmap2 = jet(256);
im1rgb = ind2rgb(im1, cmap1);
im2rgb = ind2rgb(im2, cmap2);
blended = alpha * im1rgb + (1-alpha) * im2rgb;
figure()
subplot(3,1,1)
imshow(im1rgb); title('image1 recolored');
subplot(3,1,2);
imshow(im2rgb); title('image2 recolored');
subplot(3,1,3);
imshow(blended); title('blended')

Sign in to comment.

More Answers (0)

Categories

Find more on DICOM Format in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!