MATLAB Answers

0

How can I rearrange the RGB planes of an image in MATLAB 7.9 (R2009b)?

I would like to reorder the color planes of an RGB image. Note that this has no effect on the image dimensions. This only changes the image coloring.

Tags

No tags entered yet.

Products


Release

R2009b

1 Answer

Answer by MathWorks Support Team on 18 Dec 2009
 Accepted Answer

This functionality is not available in MATLAB 7.9 (R2009b).
As a workaround, you can use the following code to rearrange the color planes of an image.
function out=switchColors(im,order)
switch (order(1))
case 'r'
first=1;
case 'g'
first=2;
case 'b'
first=3;
end
switch (order(2))
case 'r'
second=1;
case 'g'
second=2;
case 'b'
second=3;
end
switch (order(3))
case 'r'
third=1;
case 'g'
third=2;
case 'b'
third=3;
end
out=zeros(size(im));
out(:,:,1)=im(:,:,first);
out(:,:,2)=im(:,:,second);
out(:,:,3)=im(:,:,third);
out=uint8(out);
Here is an example of how to use this function to swap the Red and Blue planes of "football.jpg":
im=imread('football.jpg');
figure, imshow(im), title('Original');
bgr=switchColors(im,'bgr');
figure, imshow(bgr), title('Red/Blue Swapped');

  0 Comments

Sign in to comment.