Thread Subject: saving image with plot

Subject: saving image with plot

From: Dan Haeg

Date: 26 Mar, 2008 20:44:02

Message: 1 of 5

I have an image of a marine chart. I imported the image into
matlab and figured out how to register pixel locations with
latitude and longitude. Next I converted some GPS data from
[latitude, longitude] pairs into pixel coordinates and
plotted a track on top of the image. The only way I can
figure out how to save the image with the track is to use
the print command and save it to a jpeg.

Does anyone know how to save the resulting image with the
same resolution as the original image.

Here is what I am doing:
A = imread(filename, fmt);
s=size(A);
x=rand(s(1))*s(1);%for example
y=rand(s(2))*s(2);%for example
figure
image(A)
hold on
plot(x,y)
print -djpeg -r1000 chartwithtrack

I would like to be able to change the pixels in A where the
line is plotted. I know it is easy to change pixels at each
data point, but I do not know of an elegant way to connect
the data points without using plot. Then I could just save A
with:
imwrite(A,filename,fmt)

Any help would be appreciated.
Dan Haeg

Here are the toolboxes I have:
Operating System: Microsoft Windows XP Version 5.1 (Build
2600: Service Pack 2)
Java VM Version: Java 1.5.0_07 with Sun Microsystems Inc.
Java HotSpot(TM) Client VM mixed mode
-----------------------------------------------------------
MATLAB Version 7.4 (R2007a)
Simulink Version 6.6 (R2007a)
Communications Blockset Version 3.5 (R2007a)
Communications Toolbox Version 3.5 (R2007a)
Control System Toolbox Version 8.0 (R2007a)
Extended Symbolic Math Toolbox Version 3.2 (R2007a)
Fuzzy Logic Toolbox Version 2.2.5 (R2007a)
Image Processing Toolbox Version 5.4 (R2007a)
MATLAB Compiler Version 4.6 (R2007a)
Neural Network Toolbox Version 5.0.2 (R2007a)
Partial Differential Equation Toolbox
Version 1.0.10 (R2007a)
Real-Time Workshop Version 6.6 (R2007a)
Signal Processing Blockset Version 6.5 (R2007a)
Signal Processing Toolbox Version 6.7 (R2007a)
Simulink Control Design Version 2.1 (R2007a)
Statistics Toolbox Version 6.0 (R2007a)
Symbolic Math Toolbox Version 3.2 (R2007a)

Subject: saving image with plot

From: Richard Quist

Date: 27 Mar, 2008 13:10:53

Message: 2 of 5

Dan Haeg wrote:
> I have an image of a marine chart. I imported the image into
> matlab and figured out how to register pixel locations with
> latitude and longitude. Next I converted some GPS data from
> [latitude, longitude] pairs into pixel coordinates and
> plotted a track on top of the image. The only way I can
> figure out how to save the image with the track is to use
> the print command and save it to a jpeg.
>
> Does anyone know how to save the resulting image with the
> same resolution as the original image.
>
> Here is what I am doing:
> A = imread(filename, fmt);
> s=size(A);
> x=rand(s(1))*s(1);%for example
> y=rand(s(2))*s(2);%for example
> figure
> image(A)
> hold on
> plot(x,y)
> print -djpeg -r1000 chartwithtrack
>
> I would like to be able to change the pixels in A where the
> line is plotted. I know it is easy to change pixels at each
> data point, but I do not know of an elegant way to connect
> the data points without using plot. Then I could just save A
> with:
> imwrite(A,filename,fmt)
>
> Any help would be appreciated.
> Dan Haeg
>

Are you trying to save at the same resolution (DPI) or at the same size
(width X height)?

If the latter, you can use imfinfo to find the dimensions of the image,
use that as the figure size and then set the paperpositionmode property
of the figure to 'auto' to tell print to use the figure's size as the
output size. You also want to tell print to output the file at the
on-screen resolution (-r0) since the onscreen size is what you want in
the output. You may also want to position the axes so it fills the
figure and also hide the axes so the output file won't contain the
rulers, tick marks, etc.

Something along the lines of:
info = imfinfo(filename);
width = info.Width;
height = info.Height;
f = figure('units', 'pixels', ...
    'position', [0 0 width height], ...
    'paperpositionmode', 'auto');
A = imread(filename);
s=size(A);
x=rand(s(1))*s(1);%for example
y=rand(s(2))*s(2);%for example
image(A);
hold on;
plot(x,y);
set(gca, 'visible', 'off', ...
     'position', [0 0 1 1]);

print -djpeg -r0 chartwithtrack


My saveSameSize File Exchange submission handles setting the
print-related properties, printing/exporting to the requested format,
and then restoring the original print-related settings when done. It's
available off of here:
http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1097474&objectType=author

Hope that helps
--

Richard Quist
Software Developer
The MathWorks, Inc.

Subject: saving image with plot

From: Dan Haeg

Date: 29 Mar, 2008 22:47:01

Message: 3 of 5

My original image is 5939 by 4639 pixels. I would like to
export my image and plot at the same resolution if possible.

Subject: saving image with plot

From: Dan Haeg

Date: 29 Mar, 2008 22:47:01

Message: 4 of 5

My original image is 5939 by 4639 pixels. I would like to
export my image and plot at the same resolution if possible.

Subject: saving image with plot

From: Dan Haeg

Date: 29 Mar, 2008 22:53:01

Message: 5 of 5

sorry for the double post. I always wonder how that happens,
I only hit the button once.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com