I am working on image processing and want to colorize a gray level image with my own algorithm. I work on the primary data in numpy array and based on my algorithm, I color the image in space HSV and convert it to space RGB. But the speed of my algorithm is low. Is there a way to implement my own algorithm with numpy functions instead of working with loops and conditions on the array? for example use of: np.where my code:
row, col = num1.shape
for i in range(row):
for j in range(col):
if num12[i][j]>=250:
im[i][j][0] = 0
im[i][j][1] = 0
im[i][j][2] = num12[i][j]
else:
if num1[i][j] <=0:
color[i][j]=0
im[i][j][0] = 0
im[i][j][1] = 0
im[i][j][2] = 0
else:
if num1[i][j]< num2[i][j]:
if(num1[i][j]-num2[i][j]<-0.5):
im[i][j][0] = 107
else:
im[i][j][0] = 33
else:
if num2[i][j] >= np.multiply(num1[i][j] , 1.1):
im[i][j][0] = 33
elif num2[i][j] <= np.multiply(num1[i][j] , 1.1) and num2[i][j] >= np.multiply(num1[i][j] , 1):
im[i][j][0] = 107
elif num2[i][j] <= np.multiply(num1[i][j] , 1):
im[i][j][0] = 209
im[i][j][1] = num12[i][j]
im[i][j][2] = 255
im[i][j][0], im[i][j][1], im[i][j][2] = HSV(im[i][j][0], im[i][j][1], im[i][j][2], max_sva=255).rgb()