I have a line-drawing that I would like to trace into a vector graphic, but cannot find documentation on how to perform some of the basic graphic functions necessary to do this. Here is an example screenshot:

sub line drawing

Here I have pasted a line drawing of a submarine into a cell. I want to trace some of the lines from this drawing, add some new lines, then make some measurements using the scale in the drawing (20m).

To do this I tried first to lighten the image so it would be a very light gray--that way when I draw my vector line polygon I can clearly see it. Even better would be to change the color of black in the drawing to a pale yellow. Then it would be easy to see my black trace line. How can I lighten the drawing and/or change the color of the drawing from black to pale yellow?

For example, I tried using the "lighter" control shown in the screen shot, but it did not appear to do anything. I also tried using the "fill opacity" in the graphics toolbox (not shown), but that did not work either. (I think that must only apply to objects that I draw, not to pasted images.)

If I have a line I have drawn on top of the image, how can measure its length according to the scale in the drawing?

When I try to Binarize the image (according the answer below) it does not work for me, but produces this:

enter image description here


2 Answers 2


You can use Colorize to make the black lines yellow (or any other color).

Colorize[Binarize[img], ColorRules -> {0 -> Yellow, 1 -> White}]

enter image description here

  • $\begingroup$ If I paste an image into a cell, how do I refer to the object (get a handle to it), so I can apply a function like Colorize? $\endgroup$ Mar 1, 2016 at 21:05
  • $\begingroup$ @TylerDurden Write something like img = , paste your picture after the equal sign, then evaluate. Also look at the Generalized Input Tutorial. $\endgroup$
    – MarcoB
    Mar 1, 2016 at 21:21
  • $\begingroup$ This does not work for me. When I do this, the image is inverted and the background is yellow and the whole outline of the sub disappears. $\endgroup$ Mar 1, 2016 at 22:44
  • $\begingroup$ Observe how I did it above: The command "img= ... " sets img to be the name of the image. Then in the next line, this image is binarized and colorized. If you wish, copy/paste my code and it will work as above. If you want to work with a negative image, try ColorNegate. $\endgroup$
    – bill s
    Mar 1, 2016 at 23:34

I was able to get the yellow outline with the following expression:

ColorReplace[img, Black -> Lighter[Yellow, 0.6]]

This still leaves the problem of how to trace bezier curves on my object and then determine the length of particular lines. Eventually I gave up and did it in Adobe Illustrator. Kind of disappointing I could not do it in Mathematica.


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.