我正在尝试将标准化的RGB图像转换为HSV或LAB颜色空间。 这是归一化函数:
这是基本代码
print ('original image shape: ', image.shape)
print ('normlaised image shape: ', needed_multi_channel_img.shape)
# Converting to LAB color space
lab_image = cv.cvtColor(needed_multi_channel_img, cv.COLOR_RGB2HSV)
cv.imshow('Lab_space.jpg',lab_image.astype('float32'))
cv.waitKey(0)
cv.destroyAllWindows()
这是输出跟踪:
/home/centura/gitlab/Acne_model/Acne Model/rosaceaexperiment1.py:82: RuntimeWarning: invalid value encountered in true_divide
norm.append(image[i,j,a]/rooted_matrix[i,j])
/home/centura/gitlab/Acne_model/Acne Model/rosaceaexperiment1.py:82: RuntimeWarning: divide by zero encountered in true_divide
norm.append(image[i,j,a]/rooted_matrix[i,j])
original image shape: (375, 600, 3)
normlaised image shape: (375, 600, 3)
Traceback (most recent call last):
File "/home/centura/gitlab/Acne_model/Acne Model/rosaceaexperiment1.py", line 121, in <module>
lab_image = cv.cvtColor(needed_multi_channel_img, cv.COLOR_RGB2HSV)
cv2.error: OpenCV(3.4.3) /io/opencv/modules/imgproc/src/color.hpp:257: error: (-2:Unspecified error) in function 'cv::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::Set<3, 4>; VDcn = cv::Set<3>; VDepth = cv::Set<0, 5>; cv::SizePolicy sizePolicy = (cv::SizePolicy)2u; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
> Unsupported depth of input image:
> 'VDepth::contains(depth)'
> where
> 'depth' is 6 (CV_64F)
对于零除法错误,我将其替换为0,并将nan也替换为0。
我还搜索了StackOverflow,但找不到任何信息对其进行调试。 我不了解此错误的含义以及纠正方法。
答案 0 :(得分:7)
根据此答案https://stackoverflow.com/a/45956247/7683041,尝试:
img_float32 = np.float32(needed_multi_channel_img)
lab_image = cv.cvtColor(img_float32, cv.COLOR_RGB2HSV)