Sharpening text

Last night, I dreamed about a deconvolution-like method for printed text (scanned documents, license plates images). Since I don’t have time to test it (and I’m mildly interested into OCR and text processing), I will just drop it here, and if anyone can test it I would be happy to hear about the results.

Let U be the recorded unsharp image, L the latent sharp image to recover, epsilon the iterative update factor (usually in the neighbourhood of 0.001). Let GF be Kaiming He’s guided filter, aka content-aware variance-thresholded surface blur. Let M be a mask built ourselves by thresholding.

Let T_l and T_h be 2 users parameters that represent respectively the higher luminance threshold for the text (for example T_l = 0.1) and the lower luminance for the paper background (for example T_h = 0.9). We set them such that all text lies below T_l and all background lies above T_h.

while (user not happy || convergence criterion not met):
{
  # sharpen bright background
  for each pixel at coordinates (i, j):
  {
     M(i, j) = 1. if U(i, j) > T_h, else 0. # build the background mask
  }
  U = U - epsilon * GF(M, U) 

  # invert image
  for each pixel at coordinates (i, j):
  {
    U(i, j) = 1. - U(i, j) # assumes display-referred encoding, needs exposure normalization in scene-referred
  }

  # sharpen dark text
  for each pixel at coordinates (i, j):
  {
     M(i, j) = 1. if U(i, j) > (1. - T_l), else 0. # build the foreground mask
  }

  U = U - epsilon * GF(M, U)

  # invert image
  for each pixel at coordinates (i, j):
  {
    U(i, j) = 1. - U(i, j) # assumes display-referred encoding, needs exposure normalization in scene-referred
  }

}

L = U

Notes:

Since the guided filter relies on variance thresholding, and variance depends on the magnitude of the signal, the guided filter is not exposure-invariant (as discovered by @rawfiner). Therefore, it will blur the signal more aggressively for low magnitudes than for high magnitudes.

We use that property to blur more aggressively the part of the image excluded from the mask, and invert the image when the mask is designed to select low-magnitudes parts, such that the luminance range of interest is always in the high-sensitivity range of the guided filter.

This method, I believe, should help sharpening text without drilling holes in letters when the printing is not perfect (with newspaper or magazine paper texture patterns). Not drilling in letters should make OCR easier.

I have no idea whether this would work or not, but things coming out of my dreams often tend to work.

Pinging @David_Tschumperle just in case.

2 Likes

This is a general, rather than a specific reply.

I was for a long time a systems administrator and programmer in large corporations. On multiple occasions, I was working on difficult problems, and I would have possible solutions come to me in dreams. I cannot think of a single time when the dreamed solution did not actually work.

My thinking on this is that our conscious minds have various blocks and other issues, but our subconscious mind knows and sometimes tells us.

2 Likes

Ah, so I’m not alone. Good to know :slight_smile:

Could you provide a sample input image? What are your other settings (e.g. guided filter)? An initial assessment shows that this requires lots of iterations.

Here a fun related example. Text with turbulence.

_input

_output