My scripts that use HighlightImage stopped working after upgrading to 12. I discovered that HighlightImage doubles the Dimensions of the image, see below. Bug ?? workaround ? I need the exact same image as the original, only with a marker superimposed.
1 Answer
$\begingroup$
$\endgroup$
1
HighlightImage
returns a Graphics
object, not an Image
.
HighlightImage[img, {120, 120}] // Head
Graphics
When you call ImageDimensions
, Rasterize
is invoked internally to create an Image
object to find the dimensions of. I believe it was V12 that Rasterize
got an overhaul to work with high dpi screens.
A regular screen is 72 dpi (or 96 on Windows I think). Modern macs are 144 though:
$OperatingSystem
"MacOSX"
CurrentValue["ConnectedDisplays"]
{{"Region" -> {{0., 1680.}, {23., 1050.}}, "FullRegion" -> {{0., 1680.}, {0., 1050.}}, "PixelDimensions" -> {3360, 2100}, "BitDepth" -> 32, "Resolution" -> 144., "Scale" -> 2.}}
We can fix this by calling Rasterize
with a custom dpi setting:
img2 = Rasterize[im, ImageResolution -> 72];
ImageDimensions[img2]
{240, 240}
-
$\begingroup$ Thank you so much for that, Chip ! I was pulling my hair out. I am close to a hard deadline and this was going to kill me dead, $\endgroup$– EricCommented Jul 29, 2020 at 1:41
Options[img2, PlotRange]
to see if it's inflating the plot range. It's either that, or the image is scaled after marking it. $\endgroup$