how to change the color of an image?
12 ビュー (過去 30 日間)
古いコメントを表示
I'm wondering how to change the color of a grayscale image to rgb. In particular given a grayscale image, obtained form mat2gray(matrix), i would like to assign a specific color (e.g. green) to those pixels with a gray value in a specific range and the color red to the other pixels. I'm using the map jet(255) with imshow but i'm not satisfied of the result. I would like to choose the threshold in order to select pixels to assign green color and pixels to assign red.
0 件のコメント
回答 (2 件)
Image Analyst
2018 年 3 月 23 日
You can either adjust your colormap and display the gray scale image with the proper colormap.
imshow(grayImage);
colormap(customColorMap);
OR you can create an RGB image using ind2rgb() with the proper colormap.
rgbImage = ind2rgb(grayImage, customColorMap);
Which way do you want to do it? If you can't figure it out, attach your gray scale image and tell us what intensity ranges you want to show up in which colors.
See my visual/interactive thresholding utility: https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image
0 件のコメント
Klont
2018 年 3 月 23 日
function M=rgbThreshold(M,greenRange)
% rgbThreshold
% jacob 2018-03-23
% check the inputs
narginchk(0,2);
if ~exist('M','var') || isempty(M)
M=rand(10);
end
if ~exist('greenRange','var') || isempty(greenRange)
greenRange=[.25 .75];
end
% Clamp M between zero and 1
mat2gray(M);
% make Red Green Blue matrices
[R,G,B]=deal(zeros(size(M)));
% decide which pixels are withing range
inrange=M>=min(greenRange) & M<=max(greenRange);
% paint pixels within range green
G(inrange) = M(inrange);
% paint pixels not in range red
R(~inrange) = M(~inrange);
% Merge the RGB channels for plotting
RGB=cat(3,R,G,B);
% Plot the image
image(RGB);
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Convert Image Type についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!