Add transparency to colormap

Hi,
How can I add transparency to a colormap 2D?
I have the following code and I am using the version R2016a of MATLAB.
function covFunc( mapa, minPrx, maxPrx, arrayPrx )
wallMask(:,:,1) = mapa.img(:,:,1) ~= 255 & mapa.img(:,:,2) ~= 255 & mapa.img(:,:,3) ~= 255;
cover = (arrayPrx') .* ~wallMask + wallMask.*minPrx;
cover = cover + 0 * wallMask;
cover = (arrayPrx') .* wallMask;
imshow(cover);
caxis([minPrx maxPrx]) % Set colormap limits
colormap (jet(round((maxPrx-minPrx/50))))
colorbar
end
I need that the image stays intact and the new colors created by the color map stay transparent.

回答 (1 件)

Image Analyst
Image Analyst 2020 年 8 月 11 日
編集済み: Image Analyst 2020 年 8 月 11 日

0 投票

I'd probably create a new RGB image with the colormap and ind2rgb(). Then take a weighted average of them
rgbImage = cat(3, grayImage, grayImage, grayImage);
rgbOverlay = ind2rgb(grayImage, cmap);
factor = 0.6; % 60% or whatever.
rbgOutput = uint8(factor * double(rgbImage) + (1-factor) * 255 * rg0bOverlay);

4 件のコメント

Oliver Lestrange
Oliver Lestrange 2020 年 8 月 11 日
I am sorry, I'm not understanding.
The variable grayImage is the return of the imshow function, right?
Is this what you are suggesting?
function covFunc( mapa, minPrx, maxPrx, arrayPrx )
wallMask(:,:,1) = mapa.img(:,:,1) ~= 255 & mapa.img(:,:,2) ~= 255 & mapa.img(:,:,3) ~= 255;
cover = (arrayPrx') .* ~wallMask + wallMask.*minPrx;
cover = cover + 0 * wallMask;
cover = (arrayPrx') .* wallMask;
im = imshow(cover);
caxis([minPrx maxPrx]) % Set colormap limits
cmap = colormap (jet(round((maxPrx-minPrx/50))))
rgbImage = cat(3, im, im, im);
rgbOverlay = ind2rgb(im, cmap);
factor = 0.6; % 60% or whatever.
rbgOutput = uint8(factor * double(rgbImage) + (1-factor) * double(rgbOverlay));
colorbar
end
Image Analyst
Image Analyst 2020 年 8 月 11 日
編集済み: Image Analyst 2020 年 8 月 11 日
No, it's the output of imread(). Try this:
grayImage = imread('moon.tif');
rgbImage = cat(3, grayImage, grayImage, grayImage);
cmap = jet(256);
rgbOverlay = ind2rgb(grayImage, cmap);
factor = 0.6; % 60% or whatever.
rgbOutput = uint8(factor * double(rgbImage) + (1-factor) * 255 * rgbOverlay);
% Show everything
subplot(2, 2, 1);
imshow(grayImage);
title('Original Gray Scale Image');
subplot(2, 2, 2);
imshow(rgbOverlay);
title('Colormapped Image');
subplot(2, 2, 3);
imshow(rgbOutput);
title('Blended Image');
Once you have an RGB image, you wouldn't use a color bar - that's used only for indexed images.
Oliver Lestrange
Oliver Lestrange 2020 年 8 月 11 日
編集済み: Oliver Lestrange 2020 年 8 月 16 日
In my code the ind2rgb returns error.
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in ind2rgb (line 34)
rout(:,:,1) = r;
I am using:
cmap = jet((round((maxPrx-minPrx/50))));
rgbOverlay = ind2rgb(mapa.img, cmap)
Where mapa.img is the image.
I don't understand very well image processing... but cmap is getting a 14x3 matrix and the image is a 15x15x3. I don't know if that can be a problem...
But I think the matter here is that the values of maxPrx and minPrx are negative.
Any suggestion?
Thanks for the demonstration above.
Image Analyst
Image Analyst 2020 年 8 月 16 日
You forgot to attach your script and your image. So, how can I help? cmap can be as many colors as you want to quantize it into. I have no idea what your maxPrx and minPrx are.

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

カテゴリ

製品

リリース

R2016a

質問済み:

2020 年 8 月 11 日

コメント済み:

2020 年 8 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by