2
$\begingroup$

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

$\endgroup$
3
  • 3
    $\begingroup$ I'm soooo photogenic! $\endgroup$ Nov 5, 2013 at 1:39
  • $\begingroup$ But ... do you want to measure the white bar and resize your yellow scale accordingly? $\endgroup$ Nov 5, 2013 at 1:45
  • $\begingroup$ 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. $\endgroup$ Nov 5, 2013 at 1:47

1 Answer 1

3
$\begingroup$

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

$\endgroup$

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.