MATLAB Answers


how to arrange RGB image in a plane

Asked by Bibin George on 13 Aug 2018
Latest activity Commented on by Image Analyst
on 1 Sep 2018
I need to create an input plane by separating an rgb image into individual images red, green and blue channels and placing them in specific points of the 2d plane. I tried it using uint8 array but did not yield the desired result. Could someone help me with this problem please.


Sign in to comment.

3 Answers

Answer by Walter Roberson
on 13 Aug 2018

R = 0 * YourRGBImage;
G = R;
B = R;
R(:,:,1) = YourRGBImage(:,:,1);
G(:,:,2) = YourRGBImage(:,:,2);
B(:,:,3) = YourRGBImage(:,:,3);
image([xmin_1, xmax_1], [ymin_1, ymax_1], R);
hold on
image([xmin_2, xmax_2], [ymin_2, ymax_2], R);
image([xmin_3, xmax_3], [ymin_3, ymax_3], R);
hold off
The xmin_1 and so on reflect the "specific points on the 2d plane" that the centers of the lower left and upper right pixels are to be placed at.


What I really want is arrange the red, green and blue channels of two input images in such a way. I have some calculations that involving the entire plane later on in the rest of the program.
I am using matlab 2014b

Sign in to comment.

Answer by Image Analyst
on 21 Aug 2018

In case you want a copy and paste operation where you can paste some rectangular image at a specified location on a2-D canvass, see attached demo.


Please note that i am arranging two images
Input = uint8(zeros(height_input, width_input, 3));
%3. Arrange the red, green and blue portion of the input image separately
% on the left hand side of the input plane.
Input(1:height_t, 1:width_t, 1) = t(:,:,1);
Input(height_t*2+1:height_t*3, 1:width_t, 2) = t(:,:,2);
Input(height_t*4+1:height_t*5, 1:width_t, 3) = t(:,:,3);
and a similar change for the other image.
It is working as i expected now. Thanks a lot

Sign in to comment.

Answer by Image Analyst
on 21 Aug 2018

In case you want to take color channels and put them at different locations vertically, see attached demo.
rgbImage = imread('peppers.png');
% Extract the individual red, green, and blue color channels.
redChannel = im2double(rgbImage(:, :, 1));
greenChannel = im2double(rgbImage(:, :, 2));
blueChannel = im2double(rgbImage(:, :, 3));
H(1) = slice(repmat(redChannel,[1 1 2]),[],[], 1); %slice() requires at least 2x2x2
set(H(1),'EdgeColor','none') %required so image isn't just an edge
hold on
H(2) = slice(repmat(greenChannel,[1 1 2]),[],[], 2); %slice() requires at least 2x2x2
set(H(2),'EdgeColor','none') %required so image isn't just an edge
H(3) = slice(repmat(blueChannel,[1 1 3]),[],[], 3); %slice() requires at least 2x2x2
set(H(3),'EdgeColor','none') %required so image isn't just an edge
hold off
axis ij


I have the same question but I need this image in a horizontal plane with red, green and blue colour.
It appears to me that Image Analyst's code puts them vertically, so it is not clear what you would like done differently ?
hardik, now you say horizontally but we still do not know exactly how you'd like it to look. Why don't you just use subplot() or montage(). If not, then create a picture of what you want and upload it.

Sign in to comment.