Trim scanned images with PIL?

后端 未结 2 1593
独厮守ぢ
独厮守ぢ 2021-01-07 06:55

What would be the approach to trim an image that\'s been input using a scanner and therefore has a large white/black area?

2条回答
  •  无人及你
    2021-01-07 07:48

    For starters, Here is a similar question. Here is a related question. And a another related question.

    Here is just one idea, there are certainly other approaches. I would select an arbitrary crop edge and then measure the entropy* on either side of the line, then proceed to re-select the crop line (probably using something like a bisection method) until the entropy of the cropped-out portion falls below a defined threshold. As I think, you may need to resort to a brute root-finding method as you will not have a good indication of when you have cropped too little. Then repeat for the remaining 3 edges.

    *I recall discovering that the entropy method in the referenced website was not completely accurate, but I could not find my notes (I'm sure it was in a SO post, however.)

    Edit: Other criteria for the "emptiness" of an image portion (other than entropy) might be contrast ratio or contrast ratio on an edge-detect result.

提交回复
热议问题