Combining Color Images as one

20 次查看(过去 30 天)
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');

采纳的回答

Jang geun Choi
Jang geun Choi 2016-10-2
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 个评论
Jang geun Choi
Jang geun Choi 2016-10-2
To express amount of base color, two dimensional matrix is enough. In your code,
Bimage(:, :, 3) = repmat(255:-1:0, 256, 1);
This is used to express lack of blue as dark color.
And, cat function is used to merge matrix. Color image is considered as 3 dimensional matrix, image(x,y,c), in matlab. x and y are spatial coordinate, c is each base color.
image_data=cat(3,R2,Gimage,Bimage);
imshow(image_data)
Like this, we can stack base color matrix using cat function.
Sorry, my english is not good.
Jang geun Choi
Jang geun Choi 2016-10-2
编辑:Jang geun Choi 2016-10-2
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.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2016-10-2
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 个评论
PenguinForce
PenguinForce 2016-10-2
Thank you for answering! Your way of doing it has interested me and I will definitely look into it! thank you!!

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by