23

I'm finding images imported into Mathematica 13 notebooks are noticeably pixelated. (Oddly, pasting an image into a notebook cell does not have this problem.) Has the default changed for some import option?

Example figure generation with color and text:

g1 = Graphics[{
    {LightGray, Rectangle[{0, 0}, {2, 2}]},
    {Black, Circle[{1, 1}, 1]},
    {Thick, Blue, Circle[{1, 1}, Sqrt[2]]},
    {Blue, Text[Style["text", 20], {1, 1}]}
    }, Axes -> True, ImageSize -> 144];
Export["/temp/temp.pdf", g1] ;(* WARNING: this will overwrite temp.pdf *)
First@Import["/temp/temp.pdf"]

Mathematica 12.3:

Mma12 outcome

Mathematica 13:

Mma 13 outcome

Alan
  • 13,686
  • 19
  • 38
  • 2
    I found the following. The PDF file export is not the problem. I Created pdf file from V13 and V12. Importing the V13 PDF file into V12 shows good display, same as with V12 own exported PDF. The PDF files seems to be the same. This tells me the problem is with either the import in V13 or some font settings in V13 which affects this. Do not know. More investigation is needed. Try it yourself and you will see. Import the PDF created from V13 into V12. May be report this to WRI. – Nasser Feb 14 '22 at 00:52
  • @Nasser Yes that's right: the imports are the problem. The export in the example is just to allow easy testing. – Alan Feb 14 '22 at 01:22
  • 3
    They changed some settings for screen resolution in V13. I wonder if this has anything to do with it. – Nasser Feb 14 '22 at 01:28
  • @MichaelE2 As you can see from the accepted answer, the actual problem discussed here is quite different from the question you linked, and isn't necessarily related to PDF import. I is a common problem of rendering of images in version 13.0.0. – Alexey Popkov Feb 19 '22 at 07:04
  • 1
  • @MichaelE2 The OP had't specified which subversion of the version 12 they used. Starting from version 12.2, the default import element for PDF is Image. I reproduce the OP's output with version 12.3.1. – Alexey Popkov Feb 19 '22 at 14:46
  • @MichaelE2 The only clarification there could be that all these apply only to the Windows OS, but I can't be sure in this statement because I hadn't tried other OS. My answer is perfectly valid irrespectively of the subversion of version 12 used by the OP. What is important in my mind is that the question is very short and directly compares importing and pasting an image, which implies working with raster images (on Windows). – Alexey Popkov Feb 19 '22 at 16:04
  • 1
    @MichaelE2 The only person so far who sees a Problem (!) is you. There are so many duplicate and even trashy questions on this site, and nobody cares. This question (and my answer) clarify a significant change in version 13.0.0 and should not be considered as a duplication of an older question with another scope. – Alexey Popkov Feb 19 '22 at 16:48
  • @MichaelE2 Done. (Just fyi, the answer to the question you linked refers to the link I provided in a comment to the question.) – Alan Feb 19 '22 at 17:02
  • @Alan I thought it might be, but I didn't click. Thanks for the clarification. – Michael E2 Feb 19 '22 at 17:05
  • @AlexeyPopkov It's all resolved. I hope there's no point in arguing further about our respective interpretations of the original problem statement. – Michael E2 Feb 19 '22 at 17:06

1 Answers1

23

TL;DR

Has the default changed for some import option?

From the investigation given below we see three important changes:

  1. By default FrontEnd of version 13.0.0 applies to the whole Notebook window a hidden scale of 96/72 upon rendering on the Windows OS. This unnecessary scaling is the only reason for the observed low image rendering quality in the FrontEnd.

  2. The reason why you didn't notice this when pasting an image from the clipboard is that in version 13.0.0 the FrontEnd by default sets ImageResolution -> {96., 96.} for the image in the clipboard. Then upon conversion into boxes, it sets the ImageSizeRaw option of obtained GraphicsBox to the value equal to (72/96)*ImageDimensions[image]. This often results in non-integer values of ImageSizeRaw, which in turn leads to rounding them down by the FrontEnd and in turn also low image rendering quality after applying the hidden scale factor 96/72. But when the image is large this effect is not so apparent as when you Import the image. You can see these effects yourself:

    img = RandomImage[1, {110, 113}, ImageResolution -> 96]
    Options[ToBoxes[img], ImageSizeRaw]
    

screenshot

  1. Despite the ImageSize -> 144 explicitly specified in g1, export to PDF of version 12.3.1 sets ImageSize -> 104, while in version 13.0.0 it correctly sets ImageSize -> 144.

Note that it is possible to disable applying the 96/72 scale in version 13.0.0 using the undocumented FrontEnd option "ScreenResolutionCompatibilityMode" (you should restart Mathematica after evaluating this):

CurrentValue[$FrontEnd, "ScreenResolutionCompatibilityMode"] = True

But this only works if all of your displays are set to 100% under the "Display" in the Windows "Settings" application. And of course, there is no guarantee that this will continue to work in future Mathematica versions.

Another possible workaround is to apply default Magnification -> 72/96 to all GraphicsBox objects in the FrontEnd (Image appears inside of a Notebook as GraphicsBox, as well as Graphics):

SetOptions[$FrontEnd, GraphicsBoxOptions -> {BaseStyle -> Magnification -> 72/96}] 

After evaluating this the described problem disappears:

screenshot


The investigation

Starting from version 12.2, the default import element for PDF format is "PageImages", which means that the contents of the pages will be rasterized upon import. Let us compare ImageDimensions of obtained images (on Windows 10 x64):

Export["temp.pdf", g1];
im = First@Import["temp.pdf"]
im // ImageDimensions

With version 12.3.1 (Notebook Magnification is set to 100%):

screenshot

With version 13.0.0 (Notebook Magnification is set to 100%):

screesnhot2

We see that the dimensions of the obtained images are substantially different. Even more interesting, here is what happens when we import in version 12 the PDF exported from version 13, and vice versa:

screesnhot3

screesnhot4

Let us import them as "PageGraphics" instead and check the values of the ImageSize option:

gr12 = First@Import["ver12.3.1.pdf", "PageGraphics"]
gr13 = First@Import["ver13.0.0.pdf", "PageGraphics"]
Options[#, ImageSize] & /@ {gr12, gr13}

screenshot

Indeed, ImageSizes are different and equal to ImageDimensions obtained with version 12.3.1.

So, from where come ImageDimensions obtained with version 13?

By default under Windows Mathematica 13 uses hidden global magnification equal to 96/72:

SystemInformation["Devices", "ConnectedDisplays"]

screenshot7

Multiplying 104 and 144 by 1.33333333 and rounding produces 139 and 192, correspondingly.

The actual reason for the low quality of displayed images in version 13 is that they are magnified by the factor of 96/72 by default. Let us try to overcome this by magnifying them by the factor of 72/96 in version 13.0.0:

Image[Import@"ver12.3.1.pdf", Magnification -> 72/96]
Image[Import@"ver13.0.0.pdf", Magnification -> 72/96]

screesnhot8

We see that the quality is actually quite good.

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368