Any way to preserve the native resolution of data when saving a figure?
Informazioni
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Mostra commenti meno recenti
I've seen many ideas about changing paper size and the adjusting "-r" parameter, but it appears that all this does is take the on-screen displayed resolution and reproduce that at finer resolution. It doesn't get to the issue of saving a figure, whose data resolution is, say 1800x3200, to an image format that preserves that resolution on zoom. Is there any way to force MATLAB to save the figure as an image that would preserve that native high resolution - the way the .fig file would?
17 Commenti
JDC
il 12 Ott 2017
JDC
il 12 Ott 2017
JDC
il 12 Ott 2017
Modificato: John Kelly
il 30 Ott 2017
Rena Berman
il 30 Ott 2017
(Answers Dev) Restored edit
Jan
il 14 Nov 2017
@JDC: I'm still convinced that the problem can be solved easily, as soon as it is exactly defined, what you want.
JDC
il 14 Nov 2017
Walter Roberson
il 14 Nov 2017
JDC comments to Jan Simon:
This is an opinion and should be omitted.
Walter Roberson
il 14 Nov 2017
JDC: A lot of computing is based upon opinions. Computing does not have only one possible measurement such as "Code quality is universally defined as being inversely proportional to the number of commas in the code.| As soon as there are at least two competing measures having to do with code, it becomes a matter of opinion as to how to what "better" code is. Therefor opinion has a big place in computing, and we will not delete opinion comments unless they are abusive.
JDC
il 14 Nov 2017
JDC
il 14 Nov 2017
Walter Roberson
il 14 Nov 2017
JDC: it was not until a couple of hours ago that you clearly defined what you were trying to do. You knew what you meant, but something went missing in-between your intent and the words you had posted, which led to the situation where it was indeed reasonable for people to think there was a solution. They may have been mistaken in that assessment because of missing information, but it was reasonable.
JDC
il 15 Nov 2017
Modificato: Walter Roberson
il 15 Nov 2017
@JDC: Almost 100'000 other contributors had more success with their questions in this forum, maybe because they do not take weeks before the problems is defined, answer questions for clarifications and stay at a businesslike discussion.
I'm not interested in participating in such an impolite discussion. Therefore I have removed my comments and the trial to solve or narrow down the problem with code.
JDC
il 15 Nov 2017
JDC
il 15 Nov 2017
Rena Berman
il 12 Dic 2019
(Answers Dev) Restored edit
Risposte (1)
Cam Salzberger
il 12 Ott 2017
3 voti
Hello,
It's a little hard for me to understand what you are asking for. You want an image that, when you zoom in on it, it increases its resolution (so you don't see chunky pixels)?
In that case, it sounds like you're looking for vector format images. Any raster format (JPG, PNG, etc.) will have a fixed resolution. When you zoom in, a single data point (pixel) of the image will grow to fit multiple pixels on the screen. A vector format (EPS, PDF, etc.) stores data on the "objects" within the image, rather than the pixels themselves. Thus, when you zoom in on a line, it recalculates what the line should look like on-screen, and will display it smoothly.
See the print documentation page (specifically the section on Vector Graphics Files) for information on your options.
-Cam
25 Commenti
Cam Salzberger
il 12 Ott 2017
Ah, I understand. However, why are you trying to use "print" to save the image data rather than imwrite? If you have the image data already, it's invariably better to save it directly rather than putting it onto a figure and printing it.
Have you done some other manipulation to the figure/axes that you are hoping to preserve in the image? If so, what kind (e.g. drawn a single circle, drawn a box, arbitrarily allowed the user to scribble anywhere, etc.)?
Cam Salzberger
il 12 Ott 2017
Alright, so you're looking to save the figure to a FIG file, but maintain the resolution. I think I understand now.
One workaround I can suggest is to still use imwrite to create a separate image file. Then add a CreateFcn callback to read in the image from file and display it on the axes. Then clear the axes before saving the figure (if you want to).
It would mean tracking two files rather than just one, but you'll preserve the image size.
Hope this does it for you!
-Cam
JDC
il 14 Nov 2017
Cam Salzberger
il 14 Nov 2017
Alright, I think I understand now, and can reproduce it to a certain extent. You have a very large image that you would like to annotate with axes-based graphics objects, then convert back to an image file. I believe the underlying issue comes from the warning you see when you display the image:
Warning: Image is too big to fit on screen; displaying at 17%
When you go to save the image, getframe and File -> Save As will provide it at the screen resolution size. saveas will provide it at a fixed 150 dpi, and if you scale up the resolution in print, it will simply stretch the displayed pixels and make the resulting image choppy. Keeping the resolution at screen resolution and expanding the size of the image through the 'PaperPosition' property has similar results.
Windows itself will prevent any program from making its window size larger than screen size, so you can't simply change the figure's 'Position' property to be as big as you need. You may be able to get around that somewhat if you have multiple monitors though. Windows (I believe) limits the size of windows to the combined width of the displays, and the largest height of the displays. So you may be able to push that boundary on width somewhat. However, it's a workaround at best.
You could, potentially, display just part of the image at a time. Or display the whole thing, annotate, and play with the axes limits to only view part of the image at a time. Finally, use getframe on the axes, and concatenate the resulting images together in a final large image. It's not an ideal workflow, but it could get around the issue.
I will put in an enhancement request with the appropriate team, including your workflow and the limitations you are running into. Our development teams will look into potentially including a method to meet your workflow in a future release of MATLAB.
-Cam
Rik
il 14 Nov 2017
I can set the position of a figure outside the bounds of the monitor before writing, so this might be the trick you're looking for.
f=figure(1);
plot(rand(2,4))
p=get(0,'screensize');
set(f,'Position',[1 1 p(3:4)*2])
drawnow
saveas(f,'test1.png')
set(f,'Position',[1 1 p(3:4)/2])
drawnow
saveas(f,'test2.png')
JDC
il 14 Nov 2017
JDC
il 14 Nov 2017
JDC
il 14 Nov 2017
@Cam:
Windows itself will prevent any program from making its window
size larger than screen size
While Windows does not restrict the size, it is Matlab who does it, unfortunately. See https://www.mathworks.com/matlabcentral/fileexchange/31437-windowapi:
FigH = figure;
WindowAPI(FigH, 'Position', [100, 100, 5000, 200]);
get(FigH, 'Position')
>> [100, 100, 5000, 200]
Maybe it matters that JDC works on a Mac.
Walter Roberson
il 15 Nov 2017
One process for adding information to large images and saving them with the same size is to use the Computer Vision toolbox insertShape() or insertText() or insertObjectAnnotation(), and imwrite() the result.
This approach is not the most pleasant for merging plots such as surfaces with images: it does require rendering those at the target resolution, grabbing the frame, and merging the captured information in. If the item to be merged exceeds screen resolution when drawn at target resolution then there could be difficulty.
JDC
il 15 Nov 2017
Cam Salzberger
il 15 Nov 2017
Jan Simon,
It was my understanding that Windows at least tries to prevent windows becoming larger than display size, though I may have misunderstood (I am not a graphics expert). I have observed the behavior with other programs when simply trying to resize their window to be larger than screen size (e.g. Chrome). There appear to be ways around the limitation if you specifically try to do that. I would guess that's what the WindowsAPI submission does, though I haven't taken more than a cursory glance at it. Definitely a viable option to try though.
Walter's idea for editing the image directly is definitely another viable alternative, depending on what kind of annotations you are looking to do.
-Cam
Jan
il 15 Nov 2017
@Cam: Yes, WindowAPI.mex is simply a wrapper function to the Windows API function SetWindowPos(). This can be used e.g. to create a window, which covers 3 monitors to display a movie in the 25:9 format, e.g. using the VLC player.
Matlab's ResizeFcn limits the size of a figure to the current screen - to be exact, to the usable area without the taskbar. Therefore setting the position to [0,0,1,1] does not create a full screen view of the inner position, but the outer position is set to the screen size. Therefore WindowAPI.mex uses a flag, which hides the change of the window size, such that Matlab's ResizeFcn is not triggered.
While a huge figure can be created using this method, Matlab's PRINT fails with a Java error during trying to grab its contents. The figure's contents can be grabbed by the Windows API directly also. E.g. a screenshot of the OS using Ctrl-Print works for a multi-monitor setup - even for monitors which are not existing physically. But on one hand JDC is not interested in my assistance to solve his problem, obviously. On the other hand it seems like Matlab figures are not a convenient way to insert annotations in high-resolution images. Therefore I'd follow Walter's suggestion or use e.g. ImageMagick.
JDC
il 15 Nov 2017
Walter Roberson
il 15 Nov 2017
JDC: could I ask you for a citation for your definition of "spam" ?
Walter Roberson
il 15 Nov 2017
"[mass noun]
1 Irrelevant or unsolicited messages sent over the Internet, typically to a large number of users, for the purposes of advertising, phishing, spreading malware, etc.
1.1 Unwanted or intrusive advertising on the Internet.
[verb]
Send the same message indiscriminately to (a large number of Internet users)."
I see no advertising, phishing, or spreading of malware here. Furthermore, by posting in this forum you were soliciting replies.
Walter Roberson
il 15 Nov 2017
Nothing in that wikipedia article agrees with your use of the term "spam" with respect to any postings in this thread.
JDC
il 15 Nov 2017
Walter Roberson
il 15 Nov 2017
"I did not solicit a response from Jan"
You posted here. That solicits responses from anyone who cares to respond -- whether you like the response or not. You asked how to do something, with the something originally being unclear, and various people including Jan attempted to assist you, including by asking you to clarify statements and by proposing solutions that were in line with the information that had been presented by you. You solicited responses; you got responses. None of the responses were advertising, phishing, or spreading malware.
JDC
il 16 Nov 2017
A newcomer drops into the forum, asks an unclear question and gets upset due to questions for clarifications. He accuses two long term high reputation users for "spamming" and "trolling" and tries to attack with off-topic insults, sarcasm and parody. Finally he announces to disturb threads of other users. There is no doubt, who acts like a troll here.
JDC, your excitement is not impressing and nobody will care about your personal opinions. Walter (mainly) and I have posted more than 45'000 answers in this forum with great success and we will proceed with our style of communication. I do not have to defend against you, how I try to help to solve a problem or what I write while talking with another user. You simply do not have the power to influence, what I write.
The customs in the forum will not be changed, because one user is not satisfied in his first thread. You can check, how this forum works, and decide for yourself if you want to participate productively - or not. this is your decision and I cannot influence it by asking some questions for clarifications.
JDC
il 16 Nov 2017
JDC
il 16 Nov 2017
Questa domanda è chiusa.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!