title: How can I quickly and reliably estimate blur severity in a photo of a document?
body: <p>Suppose I have a 20 MP photo of some document, containing printed or handwritten text. The text, of course, and background, can be mildly distorted by shadows, halo from flash lightning or a lamp, etc. </p>
  
  <p>I want to estimate the blur in the top half and in the bottom half of the image. Since I know that printed (and hopefully, handwritten) text is much too sharp to detect in general-purpose camera resolutions/settings, I assume text-to-background boundaries are infinitely sharp. I am thinking of detecting the minimum number (or 1st percentile) of pixels that form the boundary between minBrightness+5% (text color) and maxBrightness-5% inside a local brightness window - because the dynamic range and lightning conditions change in different localities of the photo. So, if I need at best 3 pixels to cross from <code>BlackPoint</code> to <code>WhitePoint</code>, I would infer that my blur size is roughly 2 pixels.</p>
  
  <p>There are a few problems with my idea. The algorithm I am thinking of seems way slower than a filter. It could give misleading results if I run it on a region that has no text at all (e.g. a document, whose lower half is entirely blank), and so it relies on hardcoded minimum dynamic range (e.g. if maxBrightness-minBrightness &lt; 100, there is no text; do not try to estimate blur). Thirdly, the algorithm I have does not seem very robust in regards to noise, shadows, etc, and it could fail if the actual text font is not black-white, but is grayscale for aesthetic purposes.</p>
  
  <p>Given my concerns, is there a fast and robust, moderately accurate algorithm that will do the task better than the algorithm I have in mind?</p>
  
  <p>PS for now I am assuming uniform blur as opposed to directional blur because the direction of the blur is not central to my task.</p>