Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
vector-based transparent image

Subject: vector-based transparent image

From: Ross Anderson

Date: 18 Nov, 2013 19:14:15

Message: 1 of 3

I'm trying to add an alphadata property to some data and save a vector-based (as opposed to bitmap) image. I can't find any way to do it at the moment, but I supposed that someone has by now found a way around this matlab flaw, so I thought I'd ask. I read elsewhere that plot2svg was a workaround, but it's not working for me for images. An example:

p = peaks(20);
r =rand(20);
h = imagesc(p);
set(h,'alphadata', r);

plot2svg('testtransparency.svg'); %claims to offer vector-based transparency, doesn't work here
export_fig('testtransparency.pdf'); %nope
print -painters -depsc2 testtransparency.eps %transparency not supported
export_fig('testtransparency.png'); %not vector-based

Subject: vector-based transparent image

From: Oliver Woodford

Date: 19 Nov, 2013 10:27:08

Message: 2 of 3

"Ross Anderson" wrote:
> I'm trying to add an alphadata property to some data and save a vector-based (as opposed to bitmap) image. I can't find any way to do it at the moment, but I supposed that someone has by now found a way around this matlab flaw, so I thought I'd ask. I read elsewhere that plot2svg was a workaround, but it's not working for me for images. An example:
>
> p = peaks(20);
> r =rand(20);
> h = imagesc(p);
> set(h,'alphadata', r);
>
> plot2svg('testtransparency.svg'); %claims to offer vector-based transparency, doesn't work here
> export_fig('testtransparency.pdf'); %nope
> print -painters -depsc2 testtransparency.eps %transparency not supported
> export_fig('testtransparency.png'); %not vector-based

I don't know of any readily available function that can do this. But there are two potential workarounds that I can see.
1) Save as a png with transparency using export_fig and the -transparent option, then embed this bitmap in a pdf/eps using some other software, or simply writing out the eps file from within MATLAB. E.g. Save as png using export_fig; write out eps with image embedded in it; convert eps to pdf using eps2pdf (which comes with export_fig).
2) If you don't need the resulting pdf to be transparent itself, then you can avoid using the alphadata property of the image by compositing the transparency programmatically, e.g. as mentioned here: http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/244977#629720
Then all the normal pdf export methods should work fine.

HTH,
Oliver

Subject: vector-based transparent image

From: Bjorn Gustavsson

Date: 19 Nov, 2013 17:57:05

Message: 3 of 3

"Ross Anderson" wrote in message <l6dou7$dsk$1@newscl01ah.mathworks.com>...
> I'm trying to add an alphadata property to some data and save a vector-based (as opposed to bitmap) image. I can't find any way to do it at the moment, but I supposed that someone has by now found a way around this matlab flaw, so I thought I'd ask. I read elsewhere that plot2svg was a workaround, but it's not working for me for images. An example:
>
> p = peaks(20);
> r =rand(20);
> h = imagesc(p);
> set(h,'alphadata', r);
>
> plot2svg('testtransparency.svg'); %claims to offer vector-based transparency, doesn't work here
> export_fig('testtransparency.pdf'); %nope
> print -painters -depsc2 testtransparency.eps %transparency not supported
> export_fig('testtransparency.png'); %not vector-based
>
A couple of other options to do the same as Oliver suggests are:
http://www.mathworks.se/matlabcentral/fileexchange/4638-laprint
http://www.mathworks.se/matlabcentral/fileexchange/21286-matlabfrag
http://www.mathworks.se/matlabcentral/fileexchange/28545-matlabfrag-to-pdf

HTH,
Bjorn

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us