My algorithm consists in convoluting a fixed size kernel around an image and at each step look at the borders of the portion of the image. If all the borders are equal to zero, set all the portion of the image to zero, else, do nothing.
Code:
def iterForms(img):
height, width = img.shape
size = 14
for i in range(0, height - size - 2):
for j in range(0, width - size - 2):
crop = img[i : i + size + 2, j : j + size + 2]
cleanCrop(crop)
return img
def cleanCrop(crop):
h, w = crop.shape
borders = np.vstack((crop[0,:], crop[h-1,:], crop[:,0], crop[:,w-1]))
if np.all(borders == 0):
crop[:, :] = 0
I was wondering if there is a optimized function that can convolute around an image and for each step execute a function (in this case the function is 'cleanCrop'). If it does not exist, can I use multi-threding to optimize this process? Thanks in advance.
EDIT : It's not technically Convolution. Let's just call it Sliding around the image.