23
$\begingroup$

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

$\endgroup$
12
  • 2
    $\begingroup$ 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. $\endgroup$
    – Nasser
    Commented Feb 14, 2022 at 0:52
  • $\begingroup$ @Nasser Yes that's right: the imports are the problem. The export in the example is just to allow easy testing. $\endgroup$
    – Alan
    Commented Feb 14, 2022 at 1:22
  • 3
    $\begingroup$ They changed some settings for screen resolution in V13. I wonder if this has anything to do with it. $\endgroup$
    – Nasser
    Commented Feb 14, 2022 at 1:28
  • 1
    $\begingroup$ Strongly related WC thread: "Working with Graphics on Windows in a pixel perfect way." $\endgroup$ Commented Feb 19, 2022 at 8:29
  • 1
    $\begingroup$ @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. $\endgroup$ Commented Feb 19, 2022 at 16:48

1 Answer 1

23
$\begingroup$

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.

$\endgroup$
7
  • $\begingroup$ fyi, before I tried this option CurrentValue[$FrontEnd, "ScreenResolutionCompatibilityMode"] = True which is supposed to make V 13 work as before these changes to dpi were made but this had no effect (need to started frontend for this option to take effect). $\endgroup$
    – Nasser
    Commented Feb 14, 2022 at 6:24
  • $\begingroup$ @Nasser It works for me. Note that this only works if all of your displays are set to 100% under the display settings in the Settings app. What is your Windows Magnification setting (not Mathematica, but Windows)? $\endgroup$ Commented Feb 14, 2022 at 6:31
  • $\begingroup$ @Nasser I mean this setting: i.sstatic.net/uwjpI.png $\endgroup$ Commented Feb 14, 2022 at 6:42
  • 2
    $\begingroup$ Ah, yes, that is why it had no effect for me. My display is not set to be 100%. Thanks. $\endgroup$
    – Nasser
    Commented Feb 14, 2022 at 11:27
  • 1
    $\begingroup$ @Nasser I updated the answer with another workaround which should work in your case: SetOptions[$FrontEnd, GraphicsBoxOptions -> {BaseStyle -> Magnification -> 72/96}]. $\endgroup$ Commented Feb 14, 2022 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.