2

Is there any way to add scale bar to a image for example. I just need to add a bar and a text on top of it to all my images without having to rewrite

Graphics[{Thick, Thick, Yellow, Line[{{100, 100}, {166, 100}}], 
        Text[Style["10 μ", Yellow, Bold, 25], {120, 110}]}]

for every image.

I just want to put this bar and text at left corner of the images I have.

1

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
Rene Duchamp
  • 1,419
  • 10
  • 20
  • 3
    I'm soooo photogenic! – Dr. belisarius Nov 05 '13 at 01:39
  • But ... do you want to measure the white bar and resize your yellow scale accordingly? – Dr. belisarius Nov 05 '13 at 01:45
  • Sorry Yes! I do want to change the numneric as the size of the bar varies. But how can I do that in terms of the horizontal pixel of the image. lets say its a 640x480 image. And a 100 pixels in 640 relates to 10 micron. If I change the bar length to 200 it should show 20. – Rene Duchamp Nov 05 '13 at 01:47

1 Answers1

3

Provided you have this image is in the same directory that your notebook with the name im.jpg, try this:

im = Import[NotebookDirectory[] <> "im.jpg"];
Show[{im}, 
 Epilog -> 
  Inset[Graphics[{Thick, Thick, Yellow, 
     Line[{{100, 100}, {166, 100}}], 
     Text[Style["10 \[Mu]", Yellow, Bold, 25], {120, 110}]}], 
   Scaled[{0.15, 0.9}]]]

The result is here:enter image description here

Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96