Using Inset
to place an image inside a Graphics
expression with Frame -> True
provides a simple way to add a scale bar, or ruler, to the image. However, I cannot find a way to get the resulting graphics to display with a one-to-one correspondence between image pixels and screen pixels. For certain images this creates nasty artifacts.
Here's an example of an image which shouldn't be resampled:
i = Image[Array[Boole[OddQ[#1 + #2]] &, {200, 200}]]
Suppose this image represents a region of space 0.2 m wide. To show a "ruler" I can insert the image into a graphics frame like this:
With[{x = 0.2},
Graphics[Inset[i, {0, 0}, Center, x], Frame -> True, PlotRange -> x/2]]
The problem is quite clear - that checkerboard effect is not present in the original image. By adding an ImageSize
option or manually resizing the graphics I can change the unwanted pattern, but I can't get rid of it completely.
My question is whether there is a way to embed an image into graphics so that the image is displayed at its "natural" size, i.e. with one image pixel per screen pixel. Alternatively, is there a better way to display a scale bar or ruler alongside the image?
Texture
seems to be using some other resampling algorithm (that also is destructive){Texture[i], Polygon[{{-x/2, -x/2}, {x/2, -x/2}, {x/2, x/2}, {-x/2, x/2}}, VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}
$\endgroup$