0
votes

In Matlab I'm plotting a matrix (let's call it M) using imagesc over an image using imshow. I would like M to have a degree of transparency so I can actually see the image below. This is what I'm doing:

    imshow(img); hold on;
    h = imagesc(M); 
    set(h,'AlphaData',0.4); % set transparency to 40%

However, the last line generates an error when running it on Linux. I've been trying to solve it but nothing seems to work. I wonder if there is an alternative to the "AlphaData" property to make it transparent. Thanks!

EDIT: I'm using Matlab R2014a and Java 1.7 on a Linux CentOS 6.6

1
What does get(gcf,'renderer') return? (This will tell you the current renderer). And set(gcf,'renderer')? (This is the list of possible renderers). Try setting the renderer to one different than the one you are currently using. Some renderers don't support transparency. (On Windows, I think only 'opengl' does)Luis Mendo
Have you tried alpha(.4) or even set(h, 'alpha',.5); ?Iman
Thanks, Luis. That has solved it!karl71
I just needed to start matlab from terminal calling "matlab -softwareopengl" to change to OpenGL rendererkarl71
Post that as an answer? It may be helpful for Linux users having the same issueLuis Mendo

1 Answers

2
votes

As Luis Mendo suggested, I just needed to change the renderer. You can:

>get(gcf,'renderer'); % to see which render engine is Matlab using
>set(gcf,'renderer'); % to get a list with all the possible renderers in your machine

So, at least in Linux, to change the renderer it's necessary to start Matlab from terminal by calling it as:

matlab -softwareopengl 

Once this is done, setting transparency in an specific plot, as shown in the description of the question, is possible.