Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

saving image with it's native resolution...

919 views
Skip to first unread message

Fatihcan Kılıç

unread,
Jul 11, 2009, 3:35:20 AM7/11/09
to
Hello,

I've been working for 3 week on this subject and i still couldn't find a way to do this. I will be crazy soon...

----------
My problem is:


I have an image whose resolution is very high(1200dpi). I plot something on this image(for example : star, point,etc...) and i want to save this image to a file (jpeg,png or whatever).

1-) I load the image and represent the image:
rgb= imread('pic/1200dpi.jpg');
image(rgb)
hold on

2-) and then i plot something on it:
plot(rand(100,1),rand(100,1),'p')

3-) i take a screen shot and i save it to a file:
f = getframe;
imwrite(f.cdata,'test.jpg')

it is saved, but the resolution is very low. I want to save plotted image with it's native resolution. it can't capture the graphics larger than the screen resolution.

Is there a way to save plotted image as vector?

Thanks a lot
Ahmet...

Oliver Woodford

unread,
Jul 12, 2009, 4:53:03 AM7/12/09
to
Fatihcan K&#305;l&#305;? <fatihcan...@yahoo.com> wrote in message <24851728.10891.1247297...@nitrogen.mathforum.org>...

Use print and set the resolution parameter (-rXXX) such that the image is output at the correct resolution. The value of XXX will depend on the difference between the images actual resolution (A) and its on screen resolution (B), and also your screen's dpi (C). Specifically XXX = C * A / B. You also need to set the figure's PaperPositionMode to auto.

HTH,
Oliver

Jan Simon

unread,
Jul 12, 2009, 1:10:17 PM7/12/09
to
Dear Fatihcan K&#305;l&#305;?!

> I have an image whose resolution is very high(1200dpi). I plot something on this image(for example : star, point,etc...) and i want to save this image to a file (jpeg,png or whatever).

rgb= imread('pic/1200dpi.jpg');
H = image(rgb)
hold on
plot(rand(100,1),rand(100,1),'p')

set(gca, 'Units', 'normalized', 'Position', [0,0,1,1], 'visible', 'off');
set(gcf, 'Units', 'pixels', [1, 1, size(H, 1), size(H, 2)]);
f = getframe(gcf);
imwrite(f.cdata,'test.jpg')

Perhaps you have to swap the X- and Y-sizes, I'm always confused by the effects of the IMAGE command.
Sometimes (not sure), it helps to insert PAUSE(0.1) after reshaping the figure, before GETFRAME can see all elements of the figure.
The visibility of GCA is disabeled to hide the tickmarks on the border.
Actually GETFRAME could act on the GCA instead of the GCF also - just try which methods works better.

Good luck, Jan

Fatihcan Kılıç

unread,
Jul 13, 2009, 11:21:58 AM7/13/09
to
I tried to use "print" command and i got better result than "getframe"...

i typed this:

>> print -depsc -tiff -r1200 test

i tried to save another image formats but the best one was EPS.

I need to export image as jpeg,png with high quality but i couldn't. if i export image as jpeg, quality of image will be low.

as well as, could you check my calculation about resolution parameter?

>> size(rgb)

ans =

4777 11803 3

(A) => 4777 x 11803

--------------------------------
>> get(gcf,'Position')

ans =

1 1 1186 730

(B) => 1186 * 730

--------------------------------

>> scrsz = get(0,'ScreenSize')

scrsz =

1 1 1280 800

(C) => 1280 * 800

--------------------------------

Finally :

i am stuck here

XXX = C * A / B

XXX = ???


-------------------------

Thanks again...

Jan Simon

unread,
Jul 13, 2009, 12:01:04 PM7/13/09
to
Dear Fatihcan K&#305;l&#305;?!

> I tried to use "print" command and i got better result than "getframe"...
Can you specify, what "better" means?

JPEG means a lossy compression, so the quality is reduced usually. You can minimize the compression with:
printf -djpeg100 ...

If I save a picture obtained with GETFRAME method (as described above) and IMWRITE as PNG, the result equals the input picture **exactly** (except for the applied changes, of course). So what is "better" than an exact copy?

Curious, Jan

Fatihcan Kılıç

unread,
Jul 14, 2009, 7:18:18 AM7/14/09
to
if i use "getframe", it took a screen shot whatever on the screen. My image's resolution is very high so it doesn't fit on the screen so that "getframe" is useless for me...

When i use "print" command it saves less quality than input picture's quality.

I try to develop a program for users so that everything should be simple. If export the image as EPS, users may not have enough knowledge to open EPS file so i need to export easy to open formats, for example: jpeg,png,etc... but if i save the image as jpeg, the quality will reduce. That's the problem.

I need to export common formats(jpeg,png,tiff) and it should be higher quality.

Fatihcan Kılıç

unread,
Jul 14, 2009, 7:20:02 AM7/14/09
to
I used code you gave. But it gave me an error.

??? Error using ==> set
Invalid parameter/value pair arguments

Oliver Woodford

unread,
Jul 14, 2009, 7:41:03 AM7/14/09
to
Fatihcan K&#305;l&#305;? <fatihcan...@yahoo.com> wrote in message <1539820.23901.12475703...@nitrogen.mathforum.org>...

Export to pdf. People can open this fine, and images are saved at native resolution.

Jan Simon

unread,
Jul 17, 2009, 3:28:01 PM7/17/09
to
Dear Fatihcan K&#305;l&#305;?!

> if i use "getframe", it took a screen shot whatever on the screen. My image's


> resolution is very high so it doesn't fit on the screen so that "getframe" is
> useless for me...

You are right: GETFRAME does not work properly, if the window is larger than the screen. Sorry for the wrong advice.

> I try to develop a program for users so that everything should be simple.

Perhaps this is the wrong point to start from.
Users **want** problems. Otherwise they print the picture on a sheet of paper and use a ballpen for adding marks...

> When i use "print" command it saves less quality than input picture's quality.

> I need to export common formats(jpeg,png,tiff) and it should be higher quality.

"Higher" quality than what? What kind of effects do you see: Reduced resolution, pixel artifacts, wrong colors?

Another try:
N = 10; % Divider for size until the picture has a "good" size on screen
RGB = imread('YourPic.jpg');
Img = image(a);
set(gcf, 'Units', 'pixels', 'Position', [32, 32, size(RGB, 2) / N, size(RGB, 1) / N]);
set(gca, 'Units', 'normalized', 'Position', [0,0,1,1]);
set(gca, 'Units', 'points');
set(gcf, 'Units', 'points', 'PaperUnits', 'points', 'PaperPositionMode', 'auto');
screen_DPI = get(0, 'ScreenPixlesPerInch');
printf('-dtiff', sprintf('-r%d', N * screen_DPI), 'YourOutput.tif');

Unfortunately this does not reproduce the original picture exactly: Due to roundoff some pixels are missing. For my 2304x3072 original picture, I got 2300x3070 as output. But it is quite near to the original.

The resulting picture has a high resolution of 960x960 dpi and a tiny paper size, but both values are multiplied, and the result looks equal to the original resolution and paper size.

The short program is just a proof of concept! [N] is chosen arbitrarily, the figure size is fixed, and most likely the number of changes of the units can be reduced. But before optimizing the code, it's worth to ask:
Does this satisfy your demands to quality?

Kind regards, Jan

Jay

unread,
Jul 26, 2009, 2:57:01 PM7/26/09
to
I have a similar problem to Fatihcan. I am trying to plot on top of an image and then save it, but when I save the resulting image, I need to have EXACTLY the same resolution as the original image. This is because I am doing some other processing on the resultant image later on. Does anyone know if this is even possible in matlab? Also, things like getframe will not work for me since my images are very large (something like 7900 pixels by 4800 pixels). I appreciate any suggestions.
Thanks,
Jay

us

unread,
Jul 26, 2009, 3:27:01 PM7/26/09
to
"Jay" <jcar...@uiuc.edu> wrote in message <h4i8tt$n58$1...@fred.mathworks.com>...

> I have a similar problem to Fatihcan. I am trying to plot on top of an image and then save it, but when I save the resulting image, I need to have EXACTLY the same resolution as the original image. This is because I am doing some other processing on the resultant image later on. Does anyone know if this is even possible in matlab? Also, things like getframe will not work for me since my images are very large (something like 7900 pixels by 4800 pixels). I appreciate any suggestions.
> Thanks,
> Jay

it all depends which format you want to save your raster-image+vector-plot in...

us

Jay

unread,
Jul 26, 2009, 3:33:01 PM7/26/09
to
"us " <u...@neurol.unizh.ch> wrote in message <h4iam5$iei$1...@fred.mathworks.com>...

I would like to have it as an image file. Preferably tiff, bitmap, or png, but things like jpeg would be acceptable I guess.

Shamane

unread,
Oct 2, 2009, 8:50:19 AM10/2/09
to
"Jay" <jcar...@uiuc.edu> wrote in message <h4ib1d$d2p$1...@fred.mathworks.com>...

Hi Fatihcan K&#305;l&#305;? and Jay,

Would like to find out if you guys managed to solve it? I currently have the same problem! :( getframe absolutely doesn't work for me. In fact, saving the image using microsoft paint program will get better result! Will be so grateful if you guys can help shed some light on how to save a grayscale image which has some colored scribblings on it. Thank you soooo much!!! :)

Fatihcan Kılıç

unread,
Oct 28, 2009, 10:48:21 AM10/28/09
to
I worked on this problem long time and i understood the only way to handle this:

to extract as "PDF"

Jimmy

unread,
Mar 2, 2010, 7:56:03 AM3/2/10
to
Fatihcan K&#305;l&#305;ç <fatihcan...@yahoo.com> wrote in message <583348585.126303.12567...@gallium.mathforum.org>...

> I worked on this problem long time and i understood the only way to handle this:
>
> to extract as "PDF"

> Hi guys,
I have exactly the same problem, I read all of you posts, can you let me know if someone managed to solve the problem?

Thank you
Jimmy

ImageAnalyst

unread,
Mar 2, 2010, 8:05:38 AM3/2/10
to
On Mar 2, 7:56 am, "Jimmy " <testbe...@yahoo.com> wrote:
>  I have exactly the same problem, I read all of you posts, can you let me know if someone managed to solve the problem?
>
>     Thank you
>      Jimmy
-----------------------------------------------------------------------------
I would say that everyone solved the problem, using the above posts
that you read.
Were you unable to?

Oliver Woodford

unread,
Mar 2, 2010, 2:42:06 PM3/2/10
to

Hi

The function export_fig, available on the file exchange (http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig), now has the -native option, which will automatically save a figure at the native resolution of an image in the figure.

If you have problems with it please read all the help text to make sure you are using the function correctly, then email me from the author contact page if it still doesn't work.

HTH,
Oliver

0 new messages