5

My ideas are:

  • 1.0. [unsolved, hard image-detection] Breaking image into squares and removing borders, surely other techniques!

  • 1.1. [unsolved] Imagemagick: crop (instructions here), remove certain borders -- this may take a lot of time to locate the grid, image detection problem (comparing white/black here) -- or there may be some magic wand style filter.

  • 1.2. [unsolved] Python: you probably need thisfrom PIL import Image.

Obivously, Gimp's eraser is the wrong way to solve this problem since it's slow and error-prone. How would you remove the grid programmatically?

enter image description here

P.s. Casual discussion about this problem in Graphics.SE here that contains more physical and mechanical hacks.

Community
  • 1
  • 1
hhh
  • 50,788
  • 62
  • 179
  • 282
  • The methods so far do not work if you have non cubic-shapes of the same color as the grid. – hhh Jul 05 '12 at 18:06

3 Answers3

4

If all images consist of black lines over a gray grid, you could adjust the white threshold to remove the grid (e.g. with ImageMagick):

convert -white-threshold 80% with-grid.png without-grid.png

You will probably have to experiment with the exact threshold value. 80% worked for me with your sample image. This will make the lines pixelated. But perhaps resampling can reduce that to an acceptable amount, e.g. with:

convert -resize 200% -white-threshold 80% -resize 50% with-grid.png without-grid.png
emulbreh
  • 3,421
  • 23
  • 27
  • +1 smart idea! Suppose grids were red, can you remove grids of certain color? I am now interested to know whether it would result into better quality picture. – hhh Jul 05 '12 at 11:46
3

In your image the grid is somewhat lighter than the drawing, so we can set a threshold, and filter the image such that all 'light' pixels are set to white. Using PIL it could look like this:

import Image

def filter(x):
    #200 is our cutoff, try adjusting it to see the difference.
    if x > 200:
        return 255
    return x

im = Image.open('bird.png')
im = im.point(filter)
im.show()

Processing your uploaded image with this code gives:

enter image description here

Which in this case is a pretty good result. Provided your drawing is darker than the grid, you should be able to use this method without too many problems.

fraxel
  • 34,470
  • 11
  • 98
  • 102
  • Can you somehow specify here the color? – hhh Jul 08 '12 at 02:40
  • @hhh - sure, you can do that quite easily, take a look at the [PIL documentation](http://www.pythonware.com/library/pil/handbook/index.htm). One way would be to use `split()` and split the image into its seperate `RGB` channels, and then use the above function only on one of these channels. – fraxel Jul 08 '12 at 08:57
0

Feedback to the answers: emulbreh and fraxel

The python -version utilizes the ImageMagick so let's consider the ImageMagick. It does not work with colored version like the below due to different color-channel -profiles. Let's investigate this a bit further.

enter image description here

enter image description here

$ convert -white-threshold 0% bird.png without.png

enter image description here

This picture shows the amount of noise in the original scanned picture.

Puzzle: removing the right -hand corner as an example

I inversed the colors $ convert -negate whiteVersion.png blackVersion.png to make it easier to vizualise. Now with the below black photo, I wanted to remove the blue right corner i.e. make it black -- it means that I want to set BG channels to 0 of BG with 100% channel -value.

$ convert -channel BG -threshold 100% bbird.png without.png

enter image description here

enter image description here

Now the only thing left is of course Red -channel, I removed GB but white still have Red left. Now how can I remove just the right-hand -corner? I need to specify area and then do the earlier -operations.

How can I get this working with arbitrary photo where you want to remove certain color but leave some colors intact?

I don't know an easy way. The first problem is color-detection problem -- you specify some condition for colors (R,G,B) with some inequality. If the condition is true, you remove it in just the part. Now you do this for all basic colors i.e. when (R,G,B)=(100%,0,0), (R,G,B)=(0,100%,0) and (R,G,B)=(0,0,100%). Does there exist some ready implementation for this? Probably but it is much nicer to do it yourself, puzzle set!

Prerequisite knowledge

  • Tutorials here and here about Imagemagick.

  • In order to understand this topic, we need to know some basic physics: white color is a mixture of all colors and black consists of no colors.

hhh
  • 50,788
  • 62
  • 179
  • 282
  • 1
    converting to a different color space such as `HSV` will make wome of these things easier for you, `PIL` lets you do that too. – fraxel Jul 08 '12 at 13:46
  • @fraxel: I found the tutorial [here](http://www.imagemagick.org/script/color.php) about HSV in ImageMagick (not yet found how to use the hsb(v1,v2,v3) -- needs some option AND cannot yet find the python PIL documentation about HSV), investigating. Ideas where to find the API about the HBS/HSV? – hhh Jul 08 '12 at 22:19
  • apologies, I thought you could, but you can't convert to `HSV` with `PIL`, I normally use [`opencv`](http://opencv.willowgarage.com/wiki/) for that. However [this post](http://stackoverflow.com/questions/7274221/changing-image-hue-with-python-pil) may help.. – fraxel Jul 09 '12 at 07:46