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...
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
> 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
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...
> 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
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.
??? Error using ==> set
Invalid parameter/value pair arguments
Export to pdf. People can open this fine, and images are saved at native resolution.
> 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
it all depends which format you want to save your raster-image+vector-plot in...
us
I would like to have it as an image file. Preferably tiff, bitmap, or png, but things like jpeg would be acceptable I guess.
Hi Fatihcan Kılı? 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!!! :)
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
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