I have a 6600X5100 numpy array which represents a black & white image. I want to clear this image from black pixels noise- remove all black pixle lines (vertically and horizontally) that are shorter than 2 pixels.
So if I have something like this:
[0, 0, 0, 0, 0, 255]
[0, 255,255, 255, 255, 0 ]
[0, 255,255, 255, 0, 0 ]
[0, 255,255 ,255, 0, 255]
[0, 255,255, 255, 0, 255]
[0, 0, 0, 0, 0, 0 ]
The output array will be like this:
[0, 0, 0, 0, 0, 0 ]
[0, 255,255, 255, 0 , 0 ]
[0, 255,255, 255, 0, 0 ]
[0, 255,255 ,255, 0, 0 ]
[0, 255,255, 255, 0, 0 ]
[0, 0, 0, 0, 0, 0 ]
Performance is critical here so a simple loop over the array won't do. Is there a way to quickly find and replace subarray inside an array? So if [0, 255, 255, 0] or [0, 255, 0] is in the image array, replace those parts with 0.
Or if you have a better solution for this task, I will be grateful.