Combining Color Images as one

27 views (last 30 days)
SO I have three separate green, blue, and red images. I want to display these three separate images as one combined image, while displaying them each individually as well, like in the picture below. However, my code is not working and only returns an error message instead. Could someone help me out? Thanks!
Bimage = zeros(256, 256, 3, 'uint8');
Bimage(:, :, 3) = repmat(255:-1:0, 256, 1);
imagesc(Bimage)
Gimage = zeros(256, 256, 3, 'uint8');
Gimage(:, :, 2) = repmat(0:1:255, 256, 1);
imagesc(Gimage)
Rimage = zeros(256, 256, 3, 'uint8');
Rimage(:, :, 1) = repmat(0:1:255, 256, 1);
R2= imrotate(Rimage,90); %Rotate image by 90 degrees
imagesc(R2)
subplot(2,2,1), mesh(Bimage); title('Blue Image');
subplot(2,2,2), mesh(Gimage); title('Green Image');
subplot(2,2,3), mesh(R2); title('Red Image');
subplot(2,2,4), mesh(Bimage,Gimage,R2); title('Rainbow Image');

Accepted Answer

Jang geun Choi
Jang geun Choi on 2 Oct 2016
Bimage = zeros(256, 256, 1, 'uint8');
Bimage(:, :, 3) = repmat(255:-1:0, 256, 1);
Bimage=Bimage(:,:,3);
imagesc(Bimage)
Gimage = zeros(256, 256, 1, 'uint8');
Gimage(:, :, 2) = repmat(0:1:255, 256, 1);
Gimage=Gimage(:,:,2);
imagesc(Gimage)
Rimage = zeros(256, 256, 1, 'uint8');
Rimage(:, :, 1) = repmat(0:1:255, 256, 1);
R2=imrotate(Rimage,90); %Rotate image by 90 degrees
R2=R2(:,:,1);
imagesc(R2)
subplot(2,2,1), imshow(Bimage); title('Blue Image');
subplot(2,2,2), imshow(Gimage); title('Green Image');
subplot(2,2,3), imshow(R2); title('Red Image');
subplot(2,2,4), imshow(cat(3,Bimage,Gimage,R2)); title('Rainbow Image');
  5 Comments
Jang geun Choi
Jang geun Choi on 2 Oct 2016
Edited: Jang geun Choi on 2 Oct 2016
Yes, you can. You already use rotation in red color matrix using function "imrotate"
Gimage = zeros(256, 256, 1, 'uint8');
Gimage(:, :, 2) = repmat(0:1:255, 256, 1);
Gimage=Gimage(:,:,2);
Gimage=imrotate(Gimage,-90);
imagesc(Gimage)
Change code like this.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 2 Oct 2016
Try this:
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
greenImage = uint8(repmat(0:255, 256, 1));
redImage = imrotate(greenImage, 90);
blueImage = imrotate(greenImage, 180);
subplot(2, 2, 1);
imshow(redImage);
title('Red Image', 'FontSize', fontSize);
subplot(2, 2, 2);
imshow(greenImage);
title('Green Image', 'FontSize', fontSize);
subplot(2, 2, 3);
imshow(blueImage);
title('Blue Image', 'FontSize', fontSize);
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redImage, greenImage, blueImage);
subplot(2, 2, 4);
imshow(rgbImage);
title('Color Image', 'FontSize', fontSize);
  1 Comment
PenguinForce
PenguinForce on 2 Oct 2016
Thank you for answering! Your way of doing it has interested me and I will definitely look into it! thank you!!

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!