How to replace RGB values
20 ビュー (過去 30 日間)
Guillaume 2016 年 5 月 4 日
To go from the colour image to a grayscale image, assuming you have the original colour bar, use rgb2ind:
grayimg = rgb2ind(colourimg, map, 'nodither'); %where map is an nx3 matrix
This should give you a gray image with intensities from 0 to the number of colours in your map - 1.
You can then rescale that to whatever range you want with multiplication and addition.
その他の回答 (2 件)
Alessandro Masullo 2016 年 5 月 3 日
If I understood it correctly, you may simply use a linear scale. Once you read you image, you have a 3d matrix (row,col,3). The third dimension is the RGB. (:,:,1) is R, is (:,:,2) is G and the last one is B.
If you want to replace colours, you simply need to scale those matrices using some constants. If your image is 8 bits, the matrix will range from 0 to 255 (2^8-1). Convert it to double first, so that you won't lose information during the scale due to the rounding, and then scale the colours according to what you need:
RGB_Values = double(imread('RGB.jpg'));
RGB_Values(:,:,3) = RGB_Values(:,:,3)/2+40; % example of scaling