Image with grid lines
You can use Show
with gridlines specs combined with Method -> {"GridLinesInFront" -> True}
:
img = ExampleData[{"TestImage", "Lena"}];
Show[img, GridLines -> {Range[0, #, #/10], Range[0, #2, #2/5]} & @@
ImageDimensions[img], GridLinesStyle -> Directive[Thick, Red],
Method -> {"GridLinesInFront" -> True}]
You can also use PlotStyle->Texture[img]
with, say, RegionPlot
:
RegionPlot[0 <= x <= 1 && 0 <= y <= 1, {x, 0, 1}, {y, 0, 1},
PlotStyle -> Texture[img], PlotRangePadding->0,
GridLines -> {Range[0, 1, .1], Range[0, 1, .2]},
GridLinesStyle -> Directive[Thick, Red], Frame -> False,
Method -> { "GridLinesInFront" -> True}]
Finally, you can use Mesh
instead of GridLines
:
RegionPlot[0 <= x <= 1 && 0 <= y <= 1, {x, 0, 1}, {y, 0, 1},
PlotStyle -> Texture[img], Mesh -> {9, 4},
MeshStyle -> Directive[Thick, Red], Frame -> False]
img = ExampleData[{"TestImage", "Lena"}];
grid = Graphics[{}, GridLines -> Automatic, PlotRangePadding -> None,
GridLinesStyle -> Directive[Red, Thick], ImageSize -> ImageDimensions@img];
Overlay[{img, grid}]
For arbitrary numbers n+1
and m+1
of equidistant gridlines with automatic dependence on the ImageDimensions
of img
(which does not have to be a square either):
n = 13;
m = 7;
sub1 = Subdivide[-1, 1, n];
sub2 = Subdivide[-1, 1, m];
grid = Graphics[{}, GridLines -> {sub1, sub2},
PlotRangePadding -> None, GridLinesStyle -> Directive[Red, Thick],
ImageSize -> ImageDimensions@img];
Overlay[{img, grid}]