25

I have a photo of a pencil drawing made on paper, taken with a hotshoe flash on the DSLR and two polarising filters (cross polariser technique for canvas photography).

The problem now is that when getting closer to the drawing, lighting becomes uneven since the lens casts a shadow on part of the image. This creates a gradient over the image that is approximately, but not quite, linear.

Below is an example image; the original is around 3 cm wide.

How can this be edited such that the background is evenly white?

Source image with uneven lighting

—Edit—

Scanned results below, uncorrected and corrected. While this looks quite promising at first, it unfortunately is full resolution what you see here (600 px wide); the scanner can do 300 dpi, and the drawing is roughly one inch wide. This is a bit less compared to the 5000 px from camera.

Also, the uncorrected scan hints that graphite indeed reflects a good part of the light, as opposed to the cross-polariser technique.

Scan uncorrected Scan with corrected curve

4
  • Is there any reason you're taking a photo of it instead of scanning it?
    – Cole Tobin
    Feb 9, 2015 at 1:13
  • Yes; the canvas can be larger than A4. But I'm going to compare the results in the evening. I'm a bit suspicious about reflection that could occur on graphite. Feb 9, 2015 at 7:41
  • @ColeJohnson Scan added above. Feb 9, 2015 at 21:07
  • Something else to try: get a light table, or just hang up your drawing and shine a bright light at it from the rear side, and photograph it with the light shining through it (letting the paper itself act as a diffuser). Of course, this won't work with opaque paints, or if there's anything drawn on the reverse side, but for one-sided pencil, crayon, ink or watercolor pictures it may be worth a try. Feb 9, 2015 at 21:27

4 Answers 4

8

The method I've used myself is similar to yours, but uses the Resynthesizer plug-in (for GIMP) or Content-Aware Fill (for Photoshop) to reconstruct the gradient:

  1. Create a selection that completely covers the drawing. You can do this by hand, or you can use high-pass filtering to compute a selection mask like this:

    • Start by using an edge-detection filter like Difference of Gaussians on (a copy of) your scan to crudely extract the drawing:

      Step 1.1: Extract drawing with Difference of Gaussians

    • If the result lacks contrast, use the Levels tool to darken it:

      Step 1.2: Adjust levels

    • Apply some Gaussian Blur:

      Step 1.3: Apply Gaussian blur

    • Use the Threshold tool to get a mask covering the entire drawing, and use Select by Color to select it:

      Step 1.4: Use the threshold tool to obtain mask

  2. Once you have a selection covering the drawing, make a copy of the original scan layer and use Heal Selection / Content-Aware Fill to fill it in. Ideally, your copied layer should now look like a picture of a blank sheet of paper:

    Step 2: Heal selection to reconstruct blank paper

  3. Set the edited layer's mode to Divide, as in your own answer. If you wish to retain some of the paper texture and/or shading, you may wish to reduce the layer's opacity a little, and perhaps apply a small amount of blur:

    Step 3: Divide by blank paper layer

    (The picture above has the filled-in layer Gaussian blurred by 10px, and opacity set to 95%.)

  4. Optionally, after merging the layers, adjust the levels to set the black point (tip: use the logarithmic histogram view) and increase contrast:

    Step 4: Adjust levels

(Ps. Click the half-size images to view them at full size.)

The nice thing about this method is that it can work fairly well even for quite non-linear shading gradients. Of course, it's not perfect — if the paper has, say, an irregular stain whose boundary lies partly under the drawing, the content-aware fill is unlikely to reconstruct it correctly. Still, as seen above, it often gives pretty decent results.

9
  • That's very cool and actually what I wanted to do first, but I did not find the Resynthesizer! Going to try this tomorrow with some drawings. Curious about one where larger parts of the drawing are covered. Your result looks great already. Feb 9, 2015 at 21:11
  • It seems I cannot get Heal Selection registered in Gimp, unfortunately … Feb 10, 2015 at 19:24
  • That's odd. Are you on Windows or Linux? One possibility is that you may not have Python available, or GIMP may not find it for some reason. In that case, Heal Selection may not work, but the basic Filter > Map > Resynthesize (which can do everything Heal Selection can, even if the UI may not be so convenient) should still be available. Feb 10, 2015 at 19:29
  • I am on Linux and had to compile the plugin myself. Map > Resynthesize is indeed available. How can I check if Gimp finds the required python version? I have 2.7.5 and 3.3.2 installed. Feb 10, 2015 at 19:31
  • I'm not really sure; I use Ubuntu myself, and just let APT take care of things. Does the Python-Fu submenu appear for you at all? If not, you might need to install GIMP-Python (if it's available separately from GIMP itself) and/or recompile GIMP with Python support enabled. Then again, I'm really just guessing here. Feb 10, 2015 at 20:10
19

Edit: I wrote a Gimp script that does the steps below, and another one for Ilmaris answer. Both scripts are available for download on GitHub. The suggested way to go is this one.


I’m answering this right here because I have been searching for a solution for quite some time and found a simple and working one. Let’s get to the result right away:

  1. Create a background layer by copying a vertical stripe of the background only and stretching it to the size of the original image.

    In Gimp: Select r a rectangle from top to bottom containing background, paste Shift+Ctrl+V to a new image, and expand Filter > Map > Tile it to image size, run a gaussian blur over it, then copy it back to the image as new layer.

  2. Set the layer mode to Division.

  3. Reduce layer opacity as desired, e.g. to 90 %. Keeping it on 100 % is usually a bit too bright.

Division steps

What this does, in essence, is that the background layer defines the RGB value w of “white” on each pixel. The division layer mode then stretches the value on the image from [0,w] to [0,255] (see GIMP layer modes) per pixel.

(Bad) Example using curves and linear gradient

First attempts were always about duplicating the layer, changing the brightness such that the darkest part on the bottom were lit properly, and adding a layer mask with a linear gradient to lighten up the darker regions only. The stronger the gradient, the worse it looked.

Attempt with a linear gradient

(Better) Example using division

Division yields much better results; lighting is fixed evenly, and there are no burnt areas as especially in the left part of the drawing.

Using division

7
  • Or just change the levels setting in photoshop
    – SaturnsEye
    Feb 9, 2015 at 9:57
  • 3
    For even better results, especially in the case of non-constant/non-linear shadows in both directions, it can work to take a photo of a white sheet of paper, apply some slight blur to get rid of the camera noise, and use that as an adjustment layer base.
    – PlasmaHH
    Feb 9, 2015 at 12:04
  • 1
    @SaturnsEye Try it with the input image above. Does not work ;) If the paper were an even grey, like 10 %, then yes, that would be the easiest way. Feb 9, 2015 at 20:50
  • @PlasmaHH This would require me to use a tripod to get consistent distance, but is a nice solution especially for heavily painted photographs. The back of the paper is usually white anyway, so it could be used for the adjustment layer. (We use different kinds of paper with different shades of grey/brown). Feb 9, 2015 at 21:13
  • @SimonA.Eugster: If I was to do these things more than once in a while I would use a tripod and a recreatable light setup for consisten results anyways.
    – PlasmaHH
    Feb 9, 2015 at 21:19
5

This answer describes the fastest reliable approach I know atm, based on the answer by Ilmari Kanoren. It is semi-automatic; the automatic mask does not work for hard images like the one below because there are no edges in some parts of the drawing.

This Gimp script automates steps 3 and 4 (note that Resynthesizer is required), so the workflow is just: Create selection, run script. It takes 6 seconds for the script to complete a 15 MP image on my 3-years-old laptop.

enter image description here

Step 1 (optional): Adjust curves for deep black

Black point

Step 2: Select the object

In Gimp, the Quick Mask Shift+Q is a fast way. Use the pencil N and paint the object white, press Shift+Q again to convert the mask to a selection.

Object selected

Step 3: Recreate the background

  • Duplicate the image and scale to 400×400 px
  • Use Heal Selection or Content-aware fill to heal the object away (only background remains)
  • Use Gaussian Blur, 40×40 px
  • Scale the image back to original size and copy it back as layer to the original image

Background

Step 4: Division mode

Set the layer mode to Division and reduce opacity a bit, if desired.

Fixed image

2

This is the photography forum, so I will take a photographic approach. Of course for a perfect white you probably still need some post production tweaks.

Instead of using a flash you can try using natural light. Avoid direct sunlight, don't stay too close to the window either, but like 2 meters away from the window. This is to reduce the difference in light between the closest and furthest part of the drawing. (But as this is a small image that distance may not be that important.)

You can point a tripod facing down and put your drawing on the floor.

Or if you don't have a tripod you can arrange a book cover or a cereal box to hold the image vertically on a table, and put your camera steadily on the same table. (Put a white sheet of paper behind your drawing to avoid seeing the background images or textures.)

The polarizer technique you are mentioning is in the case you have the drawing behind a glass, and when you have bright objects or reflections. But if your source light is in an oblique angle you probably don't need to use a filter.

1
  • I'm aware of ambient lighting. It would likely produce better results regarding the gradient, although at this distance the lens would most likely start casting a shadow on the paper already. The polarizer is actually required here because the paper surface is not even, and graphite does surprisingly well at reflecting light the darker you want the area to be ;) Also, pressing a bit harder with the pencil may create indentations where ambient light can reflect again. Feb 10, 2015 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.