Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define transparent element in colormap

I would like to define a transparent color within the color map how do I do that?

The reason I need this is that I have a multiple layers in my axes (produced both by imagesc and plot). I know I could simply first use imagesc and then plot but I want to draw the lines behind non-zero values of the imagesc representation.

To color the zeros white I use

jet = colormap('jet');
jet(1:2,:) = 1;
colormap(jet);

Now I would like to make white transparent.

like image 741
magu_ Avatar asked May 01 '15 15:05

magu_


People also ask

How do you define a colormap?

A colormap is a matrix of values that define the colors for graphics objects such as surface, image, and patch objects. MATLAB® draws the objects by mapping data values to colors in the colormap. Colormaps can be any length, but must be three columns wide. Each row in the matrix defines one color using an RGB triplet.

How does colormap work Python?

The format of the colormap is that each row contains three elements (red, green, blue) and the lower color limit is mapped to the first entry, the upper color limit is mapped to the last and data is mapped linearly to all colors that may appear in between the two.

How do I open colormap editor in Matlab?

Open the Colormap Editor MATLAB command prompt: Enter colormapeditor .


1 Answers

The colormap doesn't have a fourth element for alpha, it's RGB only, so the way I do this sort of thing is to make a mask of the desired transparency layer - binary or greyscale will work - and then apply that to the image. To do this you need to store the handle of the image

% make random image
im = rand(100,100);
% make example alphamask
alphamask = im<0.3;
% store handle
hnd = imagesc(im);
% apply mask
set(hnd, 'AlphaData', alphamask);
like image 113
xenoclast Avatar answered Nov 15 '22 05:11

xenoclast