I tried to discretize an image into black and white and came into some difficult. The difference between the letters and paper is pretty clear to our eyes:
However a simple thresholding trick doesn't work. Here we move everything below 0.4 intensity to 0 and everything above 0.4 to 1:
Now let's try moving the threshhold to 0.5 and some nasty artifacts occur:
I wish I could take the "best of both worlds" of trial 1 or trial 2. Here is the Python code I used... basically the introductory tutorial with a few changes:
from skimage import io from skimage import color import numpy as np import matplotlib.pyplot as plt %matplotlib inline plt.rcParams['figure.figsize'] = 7,7 poem = io.imread('IMG_20151120_113157.jpg') io.imshow(poem) io.show() poem_gray = color.rgb2gray(poem) t = 0.5 poem_gray[poem_gray < t] = 0 poem_gray[poem_gray > t] = 1 io.imshow(poem_gray) io.show()
Here is the histogram for black and white in my image, to justify my threshhold of about 0.45 My eyes are playing tricks on me!! Some of the "white section" is as dark as the text. Is there a more standard method for separating grayscale images?