Including hand-drawn technical figure in LaTeX but without background
October 30, 2018 9:08 PM   Subscribe

There are plenty of programs (or so I'm told) that let you sketch a figure on your computer, but the learning curve is way too steep for my occasional needs. What I'm doing is sketching a figure by hand on a piece of paper. I get an off-white background for my figure when I photograph and import it, and I'd like to remove that background so that the figure looks more "natural" and with a plain white background.

Here's my workflow. I draw my figure by hand, and then I'm taking a photograph of that paper with my iPhone, transferring the photo to my Mac, dragging it on my desktop (where it's now a .jpg file) and then using the command \includegraphics to import it into my LaTeX file. There are questions and answers online (such as this question and also this one) about how to use TiKz to simulate hand-drawn diagrams. My question is different from those; I don't want to reproduce my photo using some drawing program, I just want to use the actual photo, but replacing the off-white background in the photo with a regular white background so that it won't look like a photo anymore, if that makes sense. I think I might need to do some "filling" or something? The problem is that I have no knowledge of how to use any graphics or photoshop programs. I'm on a Mac and I have iPhoto and ... I think that's it? I'm not averse to downloading some open-source program if there's an easy workflow to do what I have in mind.
posted by math to Computers & Internet (12 answers total) 1 user marked this as a favorite
Do you have a sample image? I'm only a dabbler rather than an expert, but imagine you'll get varying solutions depending on, say, whether it's pure black line art, or multi-coloured with shading. A demo pic will help keep answers focused. If it's pure B&W, you might be able to get away with just upping the brightness and contrast, and a little cleaning up, but again, I'm no expert, and a demo pic will probably be helpful.
posted by quinndexter at 9:21 PM on October 30, 2018

I think you can open the photo in preview and use instant alpha to remove the background (I think you want a transparent background, not white). Then save the image and you should be good to go. (This is not a LaTeX issue.)
posted by leahwrenn at 9:24 PM on October 30, 2018 [7 favorites]

The easiest way for you would be to use a 'scanning app' such as Genius Scan or Scanner Pro to do it on your iPhone. There are a lot of different scanning apps, they're all pretty similar, and some will automatically convert them into PDFs, etc.

While scanning apps are often designed for documents, they do well with diagrams -- they'll up the contrast and make the background uniformly white.

Your biggest variable will be your lighting. Find a place that is very well-lit and evenly lit so that there are no shadows, and it will turn out pretty well.
posted by suedehead at 9:25 PM on October 30, 2018 [2 favorites]

One way of doing what you want is “tracing”, the process of automatically converting a bitmapped/raster graphic—like a scanned or photographed image—into a vector graphic—like what you'd create from a computer illustration program.

There's an open source command-line tool called potrace which can do tracing in black & white or greyscale. (I think you'd want a black & white trace if what you're working with is essentially line art)

Then, some versions of the illustration program Inkscape I've seen on Linux have potrace built in and callable from a menu. If the Mac version of Inkscape also has potrace built in (or perhaps it could be added through a plugin or something? I think there's an Inkscape plugin system now) that might be the easiest way to do it, if you're not accustomed to the command line.
posted by XMLicious at 9:25 PM on October 30, 2018 [1 favorite]

Oh and I think ImageMagick can also do tracing, of color images as well, but that's an even more complicated command-line tool.
posted by XMLicious at 9:27 PM on October 30, 2018

Oh, yeah, using GeniusScan is a great idea—PDFLaTeX is great, and I imagine you’d be happier embedding pdfs into your LaTeX document anyway. Also, using preview to clip your images to size/make better bounding boxes is good. (For a long time, my workflow was “make diagram in Geometer’s Sketchpad, copy, open from clipboard in Preview, crop in Preview if necessary, save as pdf, \includegraphics{...} into my LaTeX document.”)
posted by leahwrenn at 9:29 PM on October 30, 2018 [1 favorite]

ScannerPro (paid, for color) and GeniusScan (free, for sharp B&W) for the win! Thanks so much!
posted by math at 10:04 PM on October 30, 2018 [1 favorite]

Cool, I was going to say that you open it up in a paint program, turn it into 16/256 grayscale and then you take the palette and start making dark things pure black and light things pure white. There are ImageMagick scripts to do this to raw images, you have to look for people trying to clean up photos of whiteboard drawings/notes. You can automate this into pop jpeg into script and get transparent + text/drawings/etc.
posted by zengargoyle at 10:33 PM on October 30, 2018 [1 favorite]

I was going to say that you open it up in a paint program, turn it into 16/256 grayscale and then you take the palette and start making dark things pure black and light things pure white.

My tool of choice for this kind of work is GIMP, and instead of messing with quantizing the palette to 16 levels I just go straight for the Colors -> Curves tool. Very quick and easy to wash out a background while leaving ink substantially unchanged.
posted by flabdablet at 12:53 AM on October 31, 2018 [1 favorite]

Yeah I was going to suggest any image editor that has a curves tool. Photoshop obviously does, but it's overkill. GIMP is also a bit of a learning curve, but you really only need to know that one tool. GraphicConverter has been my low-budget image editor of choice for decades, but I suspect there are other tools around these days.

Really all you need to do is play with the Curves in order to increase the contrast and blow the background up to pure white, and the drawing to pure black. You can also use the Threshold tool or its equivalent.
posted by Kadin2048 at 11:27 AM on October 31, 2018

If you don't mind some command-line stuff, MeFi's Own™ mzucker's noteshrink is really good for this. It doesn't vectorize, but makes a clean reduced-palette version
posted by scruss at 12:47 PM on October 31, 2018 [1 favorite]

« Older What is this dryer sump-pump wire connector called...   |   Potential mentor didn't respond after introduction... Newer »

You are not logged in, either login or create an account to post comments