0

I'm building a dataset of surfaces images based on the opensurfaces dataset but there are several images which have weird and small shapes that are not useful for my use case.

So I'm trying to use OpenCV/Numpy to get from this:

Complete image

To this:

Desired crop

So what I need to do is to extract the largest contiguous fragment of pixels (different to the white ones) forming an square or rectangle.

I can get all the white pixels with something like this:

image_mastered = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
image_copy = image_mastered.copy()
non_surface = np.all(image_copy == [255,255,255], axis=-1)
image_copy[non_surface] = [255,255,255]

But I don't know how to get the desired fragment.

Rod0n
  • 1,019
  • 2
  • 14
  • 33
  • _"largest contiguous fragment of pixels"_ - by what metric? Is a `10x10` rectangle "larger" or the same "largeness" as a `2x50` rectangle? – Eric Nov 20 '18 at 22:34
  • A very similar question, but in matlab: https://stackoverflow.com/questions/30133895 – Eric Nov 20 '18 at 22:35
  • Linked question takes in your `non_surface` array and outputs the coordinates in the image of the rectangle – Eric Nov 20 '18 at 22:38
  • @Eric thanks for the reference to a similar question, I'll give it a try. – Rod0n Nov 20 '18 at 23:06

0 Answers0