1
$\begingroup$

As a 'painter', I use photos. To get a good projection of a photo on the canvas I use a grid. I draw this grid both on the canvas and on the photo. It is an easy way to get the proportions right that way.

I use Mathematica for image manipulation. It would be nice if I could directly integrate the grid to be used in the photo. Then I can print the result. The tricky thing is that the proportions of the Grid keep changing. So after printing, I want a photo with a grid with the height and width of the cells of, for example, 1 CM.

In this example, I use a picture of water.

ImageCompose[water, Graphics[Frame -> True
  , FrameStyle -> Directive[Orange, 20]
  , FrameTicks -> {{Table[i, {i, 0, 100, 10}], 
     Table[i, {i, 0, 100, 10}]}, {Table[i, {i, 0, 100, 10}], 
     Table[i, {i, 0, 100, 10}]}}
  , GridLines -> {Table[i, {i, 0, 100, 10}], Table[i, {i, 0, 100, 10}]}
  , GridLinesStyle -> Directive[Red, Thickness[.001]]
  , PlotRange -> {{0, 100}, {0, 100}}]]

enter image description here

My question is, how do I get the gridline so the distances between the gridlines are 1 centimeter?

$\endgroup$

2 Answers 2

3
$\begingroup$

Since Mathematica is not primarily oriented towards image processing for printing, it can be a bit tricky. I suggest using PDF as a template to get correct dimensions which can easily be validated using external PDF viewer. In the following example, we will place an image and a grid on a A4 paper.

mm = 1/25.4;  (* 1 in = 25.4 mm *)
sizeA4 = {210, 297} mm; 

(* Prepare blank page with balck border of A4 paper size *)
page = Graphics[{EdgeForm[Black], Transparent, 
    Rectangle[{0, 0}, sizeA4]}, PlotRangePadding -> 0, 
   ImageMargins -> 0, ImagePadding -> 0, ImageSize -> 100 sizeA4];

(* Prepare grid *)
ticks = Table[{i mm, i}, {i, 0, 100, 10}];
gridlines = Table[i, {i, 0, 100 mm, 10 mm}];

grid = Graphics[{Transparent, 
    Rectangle[{-10, -10} mm, {110, 110} mm]}, Frame -> True, 
   FrameStyle -> Directive[Orange, 20], 
   FrameTicks -> {{ticks, ticks}, {ticks, ticks}}, 
   GridLines -> {gridlines, gridlines}, 
   GridLinesStyle -> Directive[Red, Thickness[.001]], 
   PlotRange -> {{-0, 100} mm, {-0, 100} mm}, 
   FrameTicksStyle -> (FontSize -> 10), 
   ImageSize -> 100 {120, 120} mm, ImagePadding -> 100*10 mm, 
   ImageMargins -> 0, PlotRangePadding -> 0, 
   PlotRangeClipping -> False];

(* Image to be printed *)
img = ExampleData[{"TestImage", "Boat"}];

(* Place image and grid to paper at specified positions. *)
out = Show[page, Prolog -> Inset[img, {20, 150} mm, {0, 0}, 5], 
   Epilog -> Inset[grid, {20, 150} mm, {0, 0}]];

(* Export to PDF *)
Export["page.pdf", out];

Using PDF viewer, you can see that the deviation in paper size is negligible. Page size

By showing the ruler, you can verify that the gridlines are indeed $\rm 1 \; cm$ wide. Ruler

When printing, turn off any rescaling.

Rescaling

Final confirmation with a ruler.

Final

$\endgroup$
1
$\begingroup$
  • Mathematica has no control on how one chooses to display or print an image. Many display and printing processes change aspect ratios.
  • I would suggest that you examine the AspectRatio documentation page.

Of course, I may have missed something.

$\endgroup$
2
  • $\begingroup$ Unfortunately, this post does not really answer or help anyhow to solve the problem. You can still control the resolution and size of objects in exported PDF, which is what the user actually wants. $\endgroup$
    – Domen
    Commented Mar 7, 2023 at 17:06
  • $\begingroup$ Mathematica has no control on how one chooses to display or print an image. Many display and printing processes change aspect ratios. The question said nothing about using PDF specifically. AspectRatio most certainly does control the aspect ratio of the plot that is overlaid onto the image. $\endgroup$
    – anon
    Commented Mar 7, 2023 at 22:08

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.