<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166433</link>
    <title>MATLAB Central Newsreader - saving image with plot</title>
    <description>Feed for thread: saving image with plot</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>Wed, 26 Mar 2008 20:44:02 -0400</pubDate>
      <title>saving image with plot</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166433#423016</link>
      <author>Dan Haeg</author>
      <description>I have an image of a marine chart. I imported the image into&lt;br&gt;
matlab and figured out how to register pixel locations with&lt;br&gt;
latitude and longitude. Next I converted some GPS data from&lt;br&gt;
[latitude, longitude] pairs into pixel coordinates and&lt;br&gt;
plotted a track on top of the image. The only way I can&lt;br&gt;
figure out how to save the image with the track is to use&lt;br&gt;
the print command and save it to a jpeg.&lt;br&gt;
&lt;br&gt;
Does anyone know how to save the resulting image with the&lt;br&gt;
same resolution as the original image. &lt;br&gt;
&lt;br&gt;
Here is what I am doing:&lt;br&gt;
A = imread(filename, fmt);&lt;br&gt;
s=size(A);&lt;br&gt;
x=rand(s(1))*s(1);%for example&lt;br&gt;
y=rand(s(2))*s(2);%for example&lt;br&gt;
figure&lt;br&gt;
image(A)&lt;br&gt;
hold on&lt;br&gt;
plot(x,y)&lt;br&gt;
print -djpeg -r1000 chartwithtrack&lt;br&gt;
&lt;br&gt;
I would like to be able to change the pixels in A where the&lt;br&gt;
line is plotted. I know it is easy to change pixels at each&lt;br&gt;
data point, but I do not know of an elegant way to connect&lt;br&gt;
the data points without using plot. Then I could just save A&lt;br&gt;
with:&lt;br&gt;
imwrite(A,filename,fmt)&lt;br&gt;
&lt;br&gt;
Any help would be appreciated.&lt;br&gt;
Dan Haeg&lt;br&gt;
&lt;br&gt;
Here are the toolboxes I have:&lt;br&gt;
Operating System: Microsoft Windows XP Version 5.1 (Build&lt;br&gt;
2600: Service Pack 2)&lt;br&gt;
Java VM Version: Java 1.5.0_07 with Sun Microsystems Inc.&lt;br&gt;
Java HotSpot(TM) Client VM mixed mode&lt;br&gt;
-----------------------------------------------------------&lt;br&gt;
MATLAB                         Version 7.4        (R2007a)&lt;br&gt;
Simulink                       Version 6.6        (R2007a)&lt;br&gt;
Communications Blockset        Version 3.5        (R2007a)&lt;br&gt;
Communications Toolbox         Version 3.5        (R2007a)&lt;br&gt;
Control System Toolbox         Version 8.0        (R2007a)&lt;br&gt;
Extended Symbolic Math Toolbox Version 3.2        (R2007a)&lt;br&gt;
Fuzzy Logic Toolbox            Version 2.2.5      (R2007a)&lt;br&gt;
Image Processing Toolbox       Version 5.4        (R2007a)&lt;br&gt;
MATLAB Compiler                Version 4.6        (R2007a)&lt;br&gt;
Neural Network Toolbox         Version 5.0.2      (R2007a)&lt;br&gt;
Partial Differential Equation Toolbox                &lt;br&gt;
Version 1.0.10     (R2007a)&lt;br&gt;
Real-Time Workshop             Version 6.6        (R2007a)&lt;br&gt;
Signal Processing Blockset     Version 6.5        (R2007a)&lt;br&gt;
Signal Processing Toolbox      Version 6.7        (R2007a)&lt;br&gt;
Simulink Control Design        Version 2.1        (R2007a)&lt;br&gt;
Statistics Toolbox             Version 6.0        (R2007a)&lt;br&gt;
Symbolic Math Toolbox          Version 3.2        (R2007a)</description>
    </item>
    <item>
      <pubDate>Thu, 27 Mar 2008 13:10:53 -0400</pubDate>
      <title>Re: saving image with plot</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166433#423126</link>
      <author>Richard Quist</author>
      <description>Dan Haeg wrote:&lt;br&gt;
&amp;gt; I have an image of a marine chart. I imported the image into&lt;br&gt;
&amp;gt; matlab and figured out how to register pixel locations with&lt;br&gt;
&amp;gt; latitude and longitude. Next I converted some GPS data from&lt;br&gt;
&amp;gt; [latitude, longitude] pairs into pixel coordinates and&lt;br&gt;
&amp;gt; plotted a track on top of the image. The only way I can&lt;br&gt;
&amp;gt; figure out how to save the image with the track is to use&lt;br&gt;
&amp;gt; the print command and save it to a jpeg.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Does anyone know how to save the resulting image with the&lt;br&gt;
&amp;gt; same resolution as the original image. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Here is what I am doing:&lt;br&gt;
&amp;gt; A = imread(filename, fmt);&lt;br&gt;
&amp;gt; s=size(A);&lt;br&gt;
&amp;gt; x=rand(s(1))*s(1);%for example&lt;br&gt;
&amp;gt; y=rand(s(2))*s(2);%for example&lt;br&gt;
&amp;gt; figure&lt;br&gt;
&amp;gt; image(A)&lt;br&gt;
&amp;gt; hold on&lt;br&gt;
&amp;gt; plot(x,y)&lt;br&gt;
&amp;gt; print -djpeg -r1000 chartwithtrack&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I would like to be able to change the pixels in A where the&lt;br&gt;
&amp;gt; line is plotted. I know it is easy to change pixels at each&lt;br&gt;
&amp;gt; data point, but I do not know of an elegant way to connect&lt;br&gt;
&amp;gt; the data points without using plot. Then I could just save A&lt;br&gt;
&amp;gt; with:&lt;br&gt;
&amp;gt; imwrite(A,filename,fmt)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any help would be appreciated.&lt;br&gt;
&amp;gt; Dan Haeg&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Are you trying to save at the same resolution (DPI) or at the same size &lt;br&gt;
(width X height)?&lt;br&gt;
&lt;br&gt;
If the latter, you can use imfinfo to find the dimensions of the image, &lt;br&gt;
use that as the figure size and then set the paperpositionmode property &lt;br&gt;
of the figure to 'auto' to tell print to use the figure's size as the &lt;br&gt;
output size. You also want to tell print to output the file at the &lt;br&gt;
on-screen resolution (-r0) since the onscreen size is what you want in &lt;br&gt;
the output. You may also want to position the axes so it fills the &lt;br&gt;
figure and also hide the axes so the output file won't contain the &lt;br&gt;
rulers, tick marks, etc.&lt;br&gt;
&lt;br&gt;
Something along the lines of:&lt;br&gt;
info = imfinfo(filename);&lt;br&gt;
width = info.Width;&lt;br&gt;
height = info.Height;&lt;br&gt;
f = figure('units', 'pixels', ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'position', [0 0 width height], ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'paperpositionmode', 'auto');&lt;br&gt;
A = imread(filename);&lt;br&gt;
s=size(A);&lt;br&gt;
x=rand(s(1))*s(1);%for example&lt;br&gt;
y=rand(s(2))*s(2);%for example&lt;br&gt;
image(A);&lt;br&gt;
hold on;&lt;br&gt;
plot(x,y);&lt;br&gt;
set(gca, 'visible', 'off', ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'position', [0 0 1 1]);&lt;br&gt;
&lt;br&gt;
print -djpeg -r0 chartwithtrack&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
My saveSameSize File Exchange submission handles setting the &lt;br&gt;
print-related properties, printing/exporting to the requested format, &lt;br&gt;
and then restoring the original print-related settings when done. It's &lt;br&gt;
available off of here: &lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1097474&amp;objectType=author&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1097474&amp;objectType=author&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Hope that helps&lt;br&gt;
-- &lt;br&gt;
&lt;br&gt;
Richard Quist&lt;br&gt;
Software Developer&lt;br&gt;
The MathWorks, Inc.</description>
    </item>
    <item>
      <pubDate>Sat, 29 Mar 2008 22:47:01 -0400</pubDate>
      <title>Re: saving image with plot</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166433#423526</link>
      <author>Dan Haeg</author>
      <description>My original image is 5939 by 4639 pixels. I would like to&lt;br&gt;
export my image and plot at the same resolution if possible.</description>
    </item>
    <item>
      <pubDate>Sat, 29 Mar 2008 22:47:01 -0400</pubDate>
      <title>Re: saving image with plot</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166433#423527</link>
      <author>Dan Haeg</author>
      <description>My original image is 5939 by 4639 pixels. I would like to&lt;br&gt;
export my image and plot at the same resolution if possible.</description>
    </item>
    <item>
      <pubDate>Sat, 29 Mar 2008 22:53:01 -0400</pubDate>
      <title>Re: saving image with plot</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/166433#423529</link>
      <author>Dan Haeg</author>
      <description>sorry for the double post. I always wonder how that happens,&lt;br&gt;
I only hit the button once.</description>
    </item>
  </channel>
</rss>

