Combining Color Images as one

조회 수: 11 (최근 30일)
PenguinForce
PenguinForce 2016년 10월 2일
편집: Jang geun Choi 2016년 10월 2일
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