7
$\begingroup$

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.

enter image description here

$\endgroup$
2
  • $\begingroup$ This doesn't happen for me on 12.1.1 Windows 10. Try 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$
    – flinty
    Commented Jul 28, 2020 at 21:59
  • $\begingroup$ I'm not sure this warrants the bugs tag. I have a feeling this is by design. $\endgroup$
    – Greg Hurst
    Commented Mar 10, 2023 at 13:52

1 Answer 1

10
$\begingroup$

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}
$\endgroup$
1
  • $\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$
    – Eric
    Commented Jul 29, 2020 at 1:41

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.