-1

I have generated the edges using Canny edge detector now want to crop source image by those edges.

Is there any way to get.

  1. Left and Top Most 255 pixel location of image.
  2. Right and Top Most 255 pixel location of image.
  3. Left and Bottom Most 255 pixel location of image.
  4. Right and Bottom Most 255 pixel location of image.

And crop that image based on that location. Using open cv or any other library using python.

Shan Khan
  • 9,667
  • 17
  • 61
  • 111

1 Answers1

0

There may be better solutions but I think you can implement an algorithm.

Start by drawing a square that FULLY captures the child set of pixels. Then, slowly bringing in the sides one at a time until they encounter a 255 pixel. Once you've fully pulled in all 4 sides, you will have your desired area to crop.

You could also use four simple (one-liner) For loops to check for "first white pixel". Since pixels x-pos starts at top/left, Using x++ to check forward and x-- to check backwards (from right-side).

VC.One
  • 14,790
  • 4
  • 25
  • 57
Nick Dima
  • 348
  • 1
  • 10