我在MATLAB中有一个2336x3504 RGB uint8文件。我还有一个由索引符号中的感兴趣像素组成的矢量(基于2336x3504二进制图像)。我希望RGB图像中与感兴趣像素相对应的所有点都被设置为特定颜色。基于MATLAB中的索引位置将RGB图像中的特定位置更改为特定颜色
我首先想到的是要做到以下几点:
% Separate RGB image into three 3 uint8 arrays.
RGB1 = RGBImage(:,:,1);
RGB2 = RGBImage(:,:,2);
RGB3 = RGBImage(:,:,3);
% Change each layer based on the color I want (say for red, or [255 0 0])
RGB1(interestPixels) = 255;
RGB2(interestPixels) = 0;
RGB3(interestPixels) = 0;
% Then put it all back together
NewRGBImage = cat(3,RGB1,RGB2,RGB3);
虽然这个工作,它看起来凌乱。我确定有一个更优雅的解决方案,但我没有看到它。