How can I overlay in color a matrix over a grey scale image with Matlab2020

13 ビュー (過去 30 日間)
Tsipoura
Tsipoura 2020 年 8 月 27 日
コメント済み: DGM 2022 年 10 月 21 日
I have a a grey scale image I, and an array A of the same size that contains double between m and M. I would like to overlay in transparency the values contained in A over I, using the colormap jet for instance. I have attached an image of what I want.
With the previous version of Matlab I had, I was able to do so using imoverlay, specifying a background and a front image. But now, imoverlay is only for A binary, so my code is not working anymore.
I have all the toolboxes, in particular Image processing toolbox.
Thank you for your help

回答 (1 件)

Pratyush Roy
Pratyush Roy 2020 年 9 月 1 日
The function imagesc can be used to produce the desired results.
Assuming that I and A are 2-dimensional arrays, the following code snippet shows the image overlaying process with ‘jet’ colormap:
img = imagesc(I);
img.AlphaData = A;
colormap('jet');
You can go through the following link for further help:
  5 件のコメント
Tsipoura
Tsipoura 2020 年 9 月 7 日
I tried to cast A from double to uint8 but it didn't change anything
figure()
img = imagesc(I)
B=uint8(A);
img.AlphaData = B;
img.AlphaData=0.8;
colormap('jet')
DGM
DGM 2022 年 10 月 21 日
This isn't really an issue with class. This is simply a problem with trying to have two independently colormapped objects in the same axes. Take one or both images and convert them to RGB so that they aren't colormapped anymore. In this example, I simply expand I on dim3 to prevent it from being colormapped. The second image isn't expanded, so it's rendered with the current colormap (jet).
load answers.mat
alpha = 0.5;
imshow(repmat(I,[1 1 3])); hold on
hi = imshow(A);
hi.AlphaData = alpha;
colormap(jet)
If the goal is to create an image, I'd avoid using graphics tools as an ad-hoc compositor. You can just combine the two images directly.
load answers.mat
alpha = 0.5;
% colormap the foreground image
A = ind2rgb(im2uint8(A),jet(256));
% composite via scalar alpha blending
outpict = replacepixels(A,I,alpha);
imshow(outpict)
That uses replacepixels() from MIMT. Basic alpha blending can be done without higher level tools, but if you're rolling your own, you will have to pay attention to image class, scaling, and depth.
load answers.mat
alpha = 0.5;
% colormap the foreground image
A = ind2rgb(im2uint8(A),jet(256));
% scalar alpha blending again
% images need to be floating-point and share a common scale
% depth should match, though in this case, implicit expansion works
I = im2double(I);
outpict = alpha*A + (1-alpha)*I;
imshow(outpict)
The output is the same as above

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRed についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by