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:
To this:
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.