How do I write a code to rearrage the colors in an RGB color array?
조회 수: 5 (최근 30일)
이전 댓글 표시
I have this image and I need to change the order of the colors. I have the image uploaded into MATLAB, with the code:
image1 = imread('colors.png')
The value is 229x600x3.
댓글 수: 0
채택된 답변
Jorg Woehl
2021년 3월 8일
편집: Jorg Woehl
2021년 3월 8일
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.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!