How do I write a code to rearrage the colors in an RGB color array?
4 views (last 30 days)
Jorg Woehl on 8 Mar 2021
Edited: Jorg Woehl on 8 Mar 2021
The third dimension of your 229x600 image contains the rgb values for each pixel: image1(:,:,1) is the red channel, image1(:,:,2) is the green channel, and image1(:,:3) is the blue channel.
To change the order of colors, it therefore is sufficient to copy the red -> green, green -> blue, and blue -> red channel. This can be done by a succession of matrix reassignment operations, or even simpler by using
image1 = circshift(image1,1,3)
This circularly shifts the third dimension of image1 by 1 position, cycling through the colors each time it is executed.