How could I save a large image to a pdf without compression?

19 visualizzazioni (ultimi 30 giorni)
Hello!
I have been struggling for a couple of days trying to solve this problem. Basically, I import an image, then I do some processing and I export it as a PDF. So far, there was no need to have a high resolution view of the image, but now I do need to export a good quality PDF.
The image has dimensions of 6510x7305 - and it is class uint8.
I have tried multiple approaches and read many threads in this forum with no luck. I have used exportfig, export_fig, saveas, print, and other options but the problem seem to lie in that I always rely on what is shown on screen and therefore, the resolution goes down dramatically. As suggested in other threads, I have changed the resolution but it does not help (like using -native or -q101 in export_fig).
I do understand that there is a difference between the actual variable being saved and the commands that save what is being displayed. My main issue right now is that I do not know how to directly save into a PDF.
On the left you see the kind of quality that I see when I zoom in after I have exported the images (no matter what method I use, it looks similar every time) and on the right how the original image looks when I zoom in the figure within matlab (in the figure wintow).
If anyone could help me, I would much appreciate it! All I am hoping to do is to save to PDF the large image stored in a given variable with enough resolution so that I can see the rings (as in the figure attached).
I wanted to attach the image as a mat file but the mat file is ~50mb. It may be worth also mentioning that I am using the 2018 version of matlab.
Best, Nico.

Risposta accettata

Stephen23
Stephen23 il 3 Ago 2018
Modificato: Stephen23 il 3 Ago 2018
Use imwrite.
All of the commands that you tried save the displayed figure data, which obviously limits the image resolution. All of your processing should occur purely in MATLAB memory: do NOT display the image in a figure and then expect to save whatever is shown as being the same resolution as your original data. The simplest solution is to process your image array, and save that array directly. Anything to do with figures is just a distraction.
  3 Commenti
Guillaume
Guillaume il 3 Ago 2018
Modificato: Guillaume il 3 Ago 2018
The problem you are facing is that pdf is not an image format. It's a document format meant for displaying stuff (text and image) in a particular layout on screen. It's not really meant for preserving the original resolution of images. While it is possible to save images at their native resolution in a pdf (photoshop does it), matlab does not have enough control over the pdf generation to do that reliably.
Perhaps the best course of action is to save your image as an image (e.g. png) and use another tool that gives you better control over the conversion for the pdf generation, if you really do need pdf
Stephen23
Stephen23 il 3 Ago 2018
Modificato: Stephen23 il 3 Ago 2018
@Nicolas Perez: .pdf files are not image files. If you want to have control over the image resolution then you will need to use an image file.
.pdf files are really an abomination against nature, something like a black hole from which no information can ever return. They are designed to show pages with a particular layout, but not for storing data with a particular format or resolution. No doubt it could be done with some hacking around: if you want to do this I suggest that you use a dedicated .pdf manipulation tool, as all of the options and parameters for setting up the file properly are beyond a basic save command.

Accedi per commentare.

Più risposte (1)

Nicolas Perez
Nicolas Perez il 6 Ago 2018
No quite was I was looking for but I really appreciate your help! I wrote a program that processes an image and was hoping to generate a report with an embedded image. Since this program runs many times, it will be time consuming to generate separate files to later combine them. As it is, the pdf is not of the best quality but I think I can live with that.

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by