Reputation: 570
I have two separate gray scale images im1
(Fig1) and im2
(Fig2) each of size 50 by 50 that are displayed here by color coding them. When I combine them together using cat()
command and then display the result of concatenated images, they get displayed side by side (Fig3). However, if I create a third image by replicating either the first of the second image and then display the concatenation of the 3 images I get a single image (Fig4). I don't understand how the merging for the RGB (3 dimensions) could be possible whereas for the conversion to grayscale the merging did not happen. How can I get a single image using the two images im1
and im2
merged or overlayed whichever is legally possible and not side by side? Si how do I overlay im1
and im2
to get a single image and display it by color coding?
imgGray = cat(2,im1,im2);
imshow(imgGray)
imgGray = cat(2,im1,im2);
imshow(imgGray)
imagesc(imgGray)
im3=im1;
imgColor = cat(3,im1,im2,im3);
imagesc(imgColor)
Upvotes: 2
Views: 520
Reputation: 26069
You can also just add them to each other (after normalizing them) and have a single colormap represent it all
imagesc(I1+I2);
or if you want to set transparency according to the color and intensity you can add
alpha color
alpha scaled
Upvotes: 1
Reputation: 32104
You can to do it "manually":
ind2rgb
for converting each Grayscale image to RGB with "color coding". Here is a code sample:
% Use cameraman as first image, and resized moon for the second image (just for example).
I1 = imread('cameraman.tif'); % I1 is uint8 Grayscale
I2 = imresize(imread('moon.tif'), size(I1)); % I2 is uint8 Grayscale
% Convert images to RGB using parula color map (you may choose any color map).
J1 = ind2rgb(I1, parula(256)); % J1 is double RGB (three color planes in range [0, 1]).
J2 = ind2rgb(I2, parula(256)); % J2 is double RGB (three color planes in range [0, 1]).
% Fuse J1 and J2 "manually".
alpah = 0.5; % Using alpah=0.5, gives average of J1 and J2.
K = J1*alpah + J2*(1-alpah); %K is is double RGB.
K = im2uint8(K); % Convert K to uint8 (im2uint8 multiplies pixels by 255, and convert to uint8).
%Display result
figure;imshow(K);
Upvotes: 1