将matlab.graphics.primitive.Image(imagesc的输出)转换为rgb数组 [英] Convert matlab.graphics.primitive.Image (output of imagesc) to rgb array
问题描述
我正在使用MATLAB函数
imagesc(my_gray_valued_image)
可视化 my_gray_valued_image
: [1024x1024] double array
使用像 jet
这样的色彩映射,其值为0.0 - 1.0(灰度值)。
我想将输出存储为RGB图像( [1024x1024x3]双数组
)。但是函数的输出是一个Image对象( matlab.graphics.primitive.Image
),它包含原始数组( Image.CData
)但不允许提取带有颜色标记的图像。
跟随类似(虽然容易混乱)的问题(
I'm using the MATLAB function
imagesc(my_gray_valued_image)
to visualize my_gray_valued_image
: [1024x1024] double array
with values from 0.0 - 1.0 (gray values) using colormaps like jet
.
I want to store the output as a RGB image ([1024x1024x3] double array
). However the output of the function is a Image object (matlab.graphics.primitive.Image
) that contains the original array (Image.CData
) but doesn't allow to extract the colorscaled image.
Following a similar (although confusingly cluttered) question (How to convert an indexed image to rgb image in MATLAB?) I tried the following, but that gave me a plain blue image:
RGB = ind2rgb(my_gray_valued_image, jet);
imshow(RGB);
here for arbitrary colormap:
im = rand(5); % input [0-1] image
figure;
h = imagesc(im); % imagesc handle
title('imagesc output')
cdata = h.CData; % get image data (if you don't have variable 'im')
cm = colormap(h.Parent); % get axes colormap
n = size(cm,1); % number of colors in colormap
c = linspace(h.Parent.CLim(1),h.Parent.CLim(2),n); % intensity range
ind = reshape(interp1(c,1:n,im(:),'nearest'),size(im)); % indexed image
rgb = ind2rgb(ind,cm); % rgb image
figure;
imshow(rgb,'InitialMagnification','fit');
title('rgb image')
这篇关于将matlab.graphics.primitive.Image(imagesc的输出)转换为rgb数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!