Bug introduced in 7 or earlier and fixed in 12.1
Bug isn't present in version 5.2
Something about Rasterize
which doesn't seem to work as intended.
Recipe:
Make some simple vector graphics:
Test = Graphics[Circle[{0, 0} 1]]
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, sinceImageResolution
is defined in printer dots per inch and the image has the size of one inch.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 ImageResolutio
n 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:
Can anyone reproduce the behaviour? (done; yes)
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)
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.
Rasterize
, butTestNew = Rasterize[Test, "Image", ImageResolution -> 300, ImageSize -> 300]
returns a 300 by 300 image. So perhapsRasterize
uses whichever ofImageSize
andImageResolution
is smaller? If so, then I agree that doesn't make much sense. As a more extreme example,Rasterize[Test, "Image", ImageResolution -> 0, ImageSize -> 600]
gives a 600x600 image. So it almost looks likeImageSize
overridesImageResolution
. Can anyone confirm this? The documentation saysRasterSize
overridesImageResolution
, but doesn't say anything aboutImageSize
. $\endgroup$