RGB to HSV in numpy
问题 I'm trying to implement RGB to HSV conversion from opencv in pure numpy using formula from here: def rgb2hsv_opencv(img_rgb): img_hsv = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2HSV) return img_hsv def rgb2hsv_np(img_rgb): assert img_rgb.dtype == np.float32 height, width, c = img_rgb.shape r, g, b = img_rgb[:,:,0], img_rgb[:,:,1], img_rgb[:,:,2] t = np.min(img_rgb, axis=-1) v = np.max(img_rgb, axis=-1) s = (v - t) / (v + 1e-6) s[v==0] = 0 # v==r hr = 60 * (g - b) / (v - t + 1e-6) # v==g hg = 120 +