Group Abstract Group Abstract

Message Boards Message Boards

0
|
10.4K Views
|
11 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Graphics dimensions unexpected in 12.1

Posted 5 years ago

A code for data analysis in use in version 12.0 throws errors in version 12.1. I tracked the issue to version 12.1 generating graphics which appear to have an incorrect dimension . Below are two code segments with the same code executed in the two versions.

Version 12.0 produces a 2048x2048 image as expected:

$Version

(* "12.0.0 for Microsoft Windows (64-bit) (April 6, 2019)" *)

disk = Graphics[{Black, Disk[{985, 1030}, 600]}, 
   ImageSize -> {2048, 2048}];

ImageDimensions[disk]

(* {2048,2048} *)

For some reason, the same code in 12.1 produces a 3414x3414 image:

$Version

(* "12.1.0 for Microsoft Windows (64-bit) (March 14, 2020)" *)

disk = Graphics[{Black, Disk[{985, 1030}, 600]}, 
   ImageSize -> {2048, 2048}];

ImageDimensions[disk]

(* {3414,3414} *)

Does anyone have any insight into this? I have reported the issue to tech support and reverted to 12.0 for this work.

POSTED BY: David Keith
11 Replies
Posted 5 years ago
POSTED BY: David Keith
Posted 5 years ago

I agree with Szabolcs. The last two releases have broken the same code for me. The first time it was due to changes in FITS image import. This time it’s changes to rasterization. I am trying to do real work and need more attention paid to quality assurance.

POSTED BY: David Keith
POSTED BY: Szabolcs Horvát

In response to the large number of questions on this topic on the Wolfram Community, on StackExchange, and through Wolfram Technical Support, we have published a support article describing these changes, and their rationale, at

https://support.wolfram.com/50417

It is also depends on the OS. On my MacBook Pro

disk = Graphics[{Black, Disk[{985, 1030}, 600]}, 
   ImageSize -> {2048, 2048}];

ImageDimensions[disk]

returns

{4096, 4096}

So, different behaviors on different systems and different OSs certainly cause problems...

Posted 5 years ago

Thanks, Szabolcs. Makes perfect sense. And I agree about the automatic resolution. Things just work . . .until they don't.

POSTED BY: David Keith
POSTED BY: Szabolcs Horvát
POSTED BY: Szabolcs Horvát

I understand what you are doing, I am doing the same thing and adapting to this chance was annoying ...

You can set $ImageResolution = 72 at the beginning of the session.

Alternatively, you can make all rasterization explicit, and set ImageResolution -> 72. This is some trouble because I also used to do things like Binarize@Graphics[Disk[],...] instead of using Rasterize explicitly.

I have not refactored all my code for this, but I was thinking of using something similar to the following:

rast[im_?ImageQ][gr_Graphics] :=
 Module[{w, h},
  {w, h} = ImageDimensions[im];
  Rasterize[
   Style[
    Show[gr, PlotRange -> {{0, w}, {0, h}}, ImageSize -> {w, h}],
    Antialiasing -> False
    ],
   "Image",
   ImageResolution -> 72
   ]
  ]

Then if we have an image im = RandomImage[{0.9, 1}, {100, 100}], we can rasterize corresponding masks as mask = rast[image][Graphics[Disk[{50, 50}, 50]]].

I am curious how others handle this.

POSTED BY: Szabolcs Horvát
Posted 5 years ago
POSTED BY: David Keith

See my answer here:

https://mathematica.stackexchange.com/questions/219227/unexpected-behaviour-of-imagesize-and-imagedimensions-in-12-1/

Note that ImageDimensions works on Image and not on Graphics. When you apply it to graphics, they get implicitly Rasterized. 12.1 may rasterize at higher resolution, depending on the screen you have connected.

POSTED BY: Szabolcs Horvát
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard