simon
simon

Reputation: 2841

How can I crop black corners from a scanned image?

Scans/photocopies often miss the corner which comes out black. How can these black corners be made white using python with numpy, pillow or skimage?

Upvotes: 1

Views: 98

Answers (1)

Stefan van der Walt
Stefan van der Walt

Reputation: 7263

  1. Create a mask with all black objects (mask = image < threshold)
  2. Remove objects touching the border (new_mask = segmentation.clear_border(mask))
  3. Which objects were removed? objs = (new_mask != mask)
  4. Fill those objects with white: image[objs] = 1 (or 255, if dtype int).

If you need to make sure that the objects replaced by white are triangles, you can use skimage.measure.regionprops to further examine each one.

Upvotes: 3

Related Questions