Skip to main content
10 of 11
edited tags
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

Rasterize: Resolution option not working properly

Bug introduced in 7 or earlier and persisting through 12.0
Bug isn't present in version 5.2


Something about Rasterize which doesn't seem to work as intended.

Recipe:

  1. Make some simple vector graphics:

    Test = Graphics[Circle[{0, 0} 1]]
    
  2. Try to rasterize it having defined ImageSize and ImageResolution:

    TestNew = Rasterize[Test, "Image", ImageResolution -> 300, ImageSize -> 72]
    

    ImageSize set to 72 means that the resulting image should have exactly 1 inch in size on the screen, since screen resolution is 72 pixels per inch. This is okay.

    ImageResolution set 300 means that this image should have dimensions 300 over 300, since ImageResolution is defined in printer dots per inch and the image has the size of one inch.

  3. However, check image dimensions:

    ImageDimensions[TestNew]
    

To discover that it is 72.

Moreover: the result does not depend at all on ImageResolution option. From documentation: "RasterSize and ImageResolution determine the coarseness of rasterization; ImageSize determines the size at which the final image will be displayed." If I vary RasterSize, the coarseness indeed changes. If I vary ImageResolution, the coarseness stays the same.

My system: Ubuntu 14, MMA10.0.1

Questions:

  1. Can anyone reproduce the behaviour? (done; yes)

  2. If it's not a bug, what is the reason? (mostly done: technical reason wonderfully explained by Alexey Popkov; this will be updated after the answer from WRI support is available)

  3. Could someone try this on older MMA versions? (done: See Alexey's comment to his answer: ImageResoltution is overriden by ImageSize in V7, but not in V5)

Edit: The result I would want to obtain in the above example can be obtained by calling:

TestNew = Rasterize[Test, "Image", RasterSize -> 300, ImageSize -> 72]

Or, for general image sizes:

Rasterize[Test, "Image", ImageResolution -> <DESIRED RESOLUTION IN DPI>, ImageSize -> (<DESIRED SIZE IN CENTIMETERS>)*(72/2.54)]

should give the same result as:

Rasterize[Test, "Image", RasterSize -> (<DESIRED SIZE IN CENTIMETERS>/2.54)*(<DESIRED RESOLUTION IN DPI>), ImageSize -> (<DESIRED SIZE IN CENTIMETERS>)*(72/2.54)]

In other words, ImageResolution and RasterSize seem to serve the same purpose, but the former one doesn't seem to work as it should.

Status update: According to the feedback from WRI: The question has been acknowledged as an issue. However it is not decided yet, how exactly it is to be resolved.

Alexey Bobrick
  • 1.7k
  • 1
  • 14
  • 24