<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/243231</link>
    <title>MATLAB Central Newsreader - Overlay image on a plot, with transparent background on image</title>
    <description>Feed for thread: Overlay image on a plot, with transparent background on image</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 27 Jan 2009 17:45:04 -0500</pubDate>
      <title>Overlay image on a plot, with transparent background on image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/243231#624354</link>
      <author>Stephen </author>
      <description>Hello,&lt;br&gt;
&lt;br&gt;
I've got an outline map of the US I need to overlay on a patch plot.  The map was created in Photoshop and is a 300dpi .png with black lines for the state borders, etc, and everything else transparent.  I want to create the patch plot, then overlay the map such that the colors of the patch plot show through the transparent parts of the map.&lt;br&gt;
&lt;br&gt;
I have tried doing this according to the two procedures laid out here:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/support/solutions/data/1-1AK7N.html&quot;&gt;http://www.mathworks.com/support/solutions/data/1-1AK7N.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
However, the transparency of the image read in using imread always seems to default to black, even if I try changing it to something else using whitebg.  It also seems to wipe out the patch plot, no matter what.  &lt;br&gt;
&lt;br&gt;
Does anyone have any suggestions?  I would greatly appreciate it, as I've been beating my head going over the same threads again and again.  Thanks.</description>
    </item>
    <item>
      <pubDate>Tue, 27 Jan 2009 19:53:03 -0500</pubDate>
      <title>Re: Overlay image on a plot, with transparent background on image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/243231#624380</link>
      <author>Pete </author>
      <description>I've never tried to use image transparencies in MATLAB, so I don't know how to solve it that way.  Can you do it the other way around - patch plot on top of the image?&lt;br&gt;
&lt;br&gt;
imshow(im, []);&lt;br&gt;
h = patch([10, 200, 200], [10, 10, 200], [1, 0 0]);&lt;br&gt;
set(h, 'FaceAlpha', .4, 'EdgeColor', 'none');&lt;br&gt;
&lt;br&gt;
If that means your patch vertices would have to be too accurate, you could load in a simple black and white image, use bwtraceboundary or bwboundaries to get the coordinates of the borders, and plot them on top using line.  The image is then only used to get the coordinates, you don't actually display it.  This would also give you control over how thick you want the borders to display and it could scale more nicely.&lt;br&gt;
&lt;br&gt;
The 'tracing object boundaries' part here might help:&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/toolbox/images/index.html?/access/helpdesk/help/toolbox/images/f11-11942.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/toolbox/images/index.html?/access/helpdesk/help/toolbox/images/f11-11942.html&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Tue, 27 Jan 2009 19:59:02 -0500</pubDate>
      <title>Re: Overlay image on a plot, with transparent background on image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/243231#624381</link>
      <author>Pete </author>
      <description>Oops, I mistakenly thought imread was part of the Image Processing Toolbox.  If you don't have that, my suggestion won't have been very helpful, sorry...</description>
    </item>
    <item>
      <pubDate>Tue, 27 Jan 2009 21:17:02 -0500</pubDate>
      <title>Re: Overlay image on a plot, with transparent background on image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/243231#624385</link>
      <author>Stephen </author>
      <description>Pete, &lt;br&gt;
&lt;br&gt;
Thanks for your response.  I'm not sure how overlaying a patch plot doesn't wipe out the black lines of the map, unless I give the patch plot an alpha value for transparency, which seems to be what your code does.  However, I believe this compromises the original shades of color of the patch plot, right?  It's important for me to keep that intact.  &lt;br&gt;
&lt;br&gt;
I will look into the bwtraceboundary solution.  The map has quite complex lines.  I assume this is immaterial?&lt;br&gt;
&lt;br&gt;
This also still leaves unaddressed the problem of the transparency defaulting to black.  When I do imshow(img w/transparent bg) with no other superposition, this always happens.  Why does this go to black instead of white or the figure gray?&lt;br&gt;
&lt;br&gt;
I believe I do have the image toolbox as well, if it makes a difference.&lt;br&gt;
&lt;br&gt;
Thanks.&lt;br&gt;
&lt;br&gt;
&quot;Pete &quot; &amp;lt;pete.dot.bankhead@btinternet.dot.com&amp;gt; wrote in message &amp;lt;glnomv$qe$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I've never tried to use image transparencies in MATLAB, so I don't know how to solve it that way.  Can you do it the other way around - patch plot on top of the image?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; imshow(im, []);&lt;br&gt;
&amp;gt; h = patch([10, 200, 200], [10, 10, 200], [1, 0 0]);&lt;br&gt;
&amp;gt; set(h, 'FaceAlpha', .4, 'EdgeColor', 'none');&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If that means your patch vertices would have to be too accurate, you could load in a simple black and white image, use bwtraceboundary or bwboundaries to get the coordinates of the borders, and plot them on top using line.  The image is then only used to get the coordinates, you don't actually display it.  This would also give you control over how thick you want the borders to display and it could scale more nicely.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The 'tracing object boundaries' part here might help:&lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/toolbox/images/index.html?/access/helpdesk/help/toolbox/images/f11-11942.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/toolbox/images/index.html?/access/helpdesk/help/toolbox/images/f11-11942.html&lt;/a&gt;</description>
    </item>
  </channel>
</rss>

