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.
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.
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.
Open the Colormap Editor MATLAB command prompt: Enter colormapeditor .
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With