Filter löschen
Filter löschen

Combining Color Images as one

16 Ansichten (letzte 30 Tage)
PenguinForce
PenguinForce am 2 Okt. 2016
Bearbeitet: Jang geun Choi am 2 Okt. 2016
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');

Akzeptierte Antwort

Jang geun Choi
Jang geun Choi am 2 Okt. 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 Kommentare
Jang geun Choi
Jang geun Choi am 2 Okt. 2016
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 am 2 Okt. 2016
Bearbeitet: Jang geun Choi am 2 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by