|
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.
|