What is the best way to dewarp pages with Python?

Viewed 22

It seems that the following is the only python software that dewarps pages:

https://pypi.org/project/page-dewarp/

Correct me if I'm wrong but I tried looking up whether pytesseract automatically dewarps pages and I'm pretty sure they don't since they simply linked to the above site. In any case, after I dewarp a page I want to OCR it with pytesseract. My problem is that the above dewarping software while although it does dewarp rather well, it so reduces the clarity of the image that it does not improve the OCR. For example, here are two images, the second one is dewarped. not dewarped

dewarped

As you can see, although the second image has a DPI of 300 pixels it is still very faded and it results in a lot of OCR errors. I'm thinking maybe the page-dewarp software 'subtracts' some of the pixels since it would be too slow to include every pixel that is included in the original. Well, I can scan the books while I'm asleep if need be, I don't care if takes 8 hours to dewarp a book. However, I can't figure out what the parameters mean so as to tweak them. I've tried reaching out to the software designer but received no reply. Here are the parameters listed on the github site with the obviously unhelpful parameters removed.

github repo

-ta TEXT_MIN_ASPECT, --min-text-aspect TEXT_MIN_ASPECT
                        Filter out text contours below this w/h ratio
  -tk TEXT_MAX_THICKNESS, --max-text-thickness TEXT_MAX_THICKNESS
                        Max reduced px thickness of detected text contour
  -wz ADAPTIVE_WINSZ, --adaptive-winsz ADAPTIVE_WINSZ
                        Window size for adaptive threshold in reduced px
  -ri RVEC_IDX, --rotation-vec-param-idx RVEC_IDX
                        Index of rvec in params vector (slice: pair of values)
  -ti TVEC_IDX, --translation-vec-param-idx TVEC_IDX
                        Index of tvec in params vector (slice: pair of values)
  -ci CUBIC_IDX, --cubic-slope-param-idx CUBIC_IDX
                        Index of cubic slopes in params vector (slice: pair of
                        values)
  -sw SPAN_MIN_WIDTH, --min-span-width SPAN_MIN_WIDTH
                        Minimum reduced px width for span
  -sp SPAN_PX_PER_STEP, --span-spacing SPAN_PX_PER_STEP
                        Reduced px spacing for sampling along spans
  -eo EDGE_MAX_OVERLAP, --max-edge-overlap EDGE_MAX_OVERLAP
                        Max reduced px horiz. overlap of contours in span
  -el EDGE_MAX_LENGTH, --max-edge-length EDGE_MAX_LENGTH
                        Max reduced px length of edge connecting contours
  -ec EDGE_ANGLE_COST, --edge-angle-cost EDGE_ANGLE_COST
                        Cost of angles in edges (tradeoff vs. length)
  -ea EDGE_MAX_ANGLE, --max-edge-angle EDGE_MAX_ANGLE
                        Maximum change in angle allowed between contours

I don't know what these mean nor do I have a good idea for what would constitute a good number to change those parameters. For example, suppose an image is 1401 pixels high, I have a feeling that one of those parameters reduces that number maybe to 300 by taking the average of 4 pixels and if I could find out how to prohibit the software from doing that I might have my solution.

Alternatively, if anyone knows of a better way to dewarp images with Python then I'm all ears.

0 Answers
Related