MATLAB: How could I save a large image to a pdf without compression

image

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 6510×7305 – 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.

Best Answer

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