How to show the image slice from the below example?

조회 수: 5 (최근 30일)
blues
blues 2021년 2월 26일
댓글: Walter Roberson 2021년 2월 28일
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?

채택된 답변

Walter Roberson
Walter Roberson 2021년 2월 26일
% 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
blues
blues 2021년 2월 26일
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 2021년 2월 28일
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')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 DICOM Format에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by