optimization - optimize python nested loops for YUV2RGB conversion -


we derived yuv2rgb algorithm hikvision. our 720h x 1280w screen resolution python conversion takes long (15 seconds) 720x1280=921,600 rounds of calculations 1 single rgb frame. 1 knows how optimized following 2 large nested loop? yuv2rgb algorithm is:

def yuv2rgb (y1, u1, v1, dwheight, dwwidth): # function call

rgb1 = np.zeros(dwheight * dwwidth * 3, dtype=np.uint8)  # create 1 dimensional empty np array 720x1280x3  in range (0, dwheight):    #0-720     j in range (0, dwwidth): #0-1280           # print "cv"          y = y1[i * dwwidth + j];          u = u1[(i / 2) * (dwwidth / 2) + (j / 2)];          v = v1[(i / 2) * (dwwidth / 2) + (j / 2)];          r = y + (u - 128) + (((u - 128) * 103) >> 8);          g = y - (((v - 128) * 88) >> 8) - (((u - 128) * 183) >> 8);          b = y + (v - 128) + (((v - 128) * 198) >> 8);          r = max(0, min(255, r));          g = max(0, min(255, g));          b = max(0, min(255, b));          rgb1[3 * (i * dwwidth + j)] = b;          rgb1[3 * (i * dwwidth + j) + 1] = g;          rgb1[3 * (i * dwwidth + j) + 2] = r;   rgb = np.reshape(rgb1, (dwheight, dwwidth, 3))  print ("rgb.shape:") print rgb.shape  return rgb 

"for in range (0, dwheight): #0-720 j in range (0, dwwidth): #0-1280 "

is large. way optimize this. thanks.

matthew


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -