I am making a code that partially normalizes intensity of an input image. Since I could not find corresponding function of Numpy library, I made a code like following:
def arealNorm(img,kernel_size = 7): #Img should me gray
img_norm = np.zeros(img.shape)
for v in range(kernel_size,img.shape[0]-kernel_size):
for u in range(kernel_size,img.shape[1]-kernel_size):
MaxV = np.max(img[v-kernel_size:v+kernel_size,u-kernel_size:u+kernel_size])
minV = np.min(img[v-kernel_size:v+kernel_size,u-kernel_size:u+kernel_size])
newval = (img[v,u]-minV)/(MaxV-minV)
img_norm[v,u] = newval
return img_norm
Since it should access every pixel of the image this code works very slowly.
Is there any numpy-like way to convert my code to work faster ?