我的遗传算法有一个HSV图像作为输入,当我编译代码时,我有以下警告
RuntimeWarning: overflow encountered in ubyte_scalars
警告是因为我想计算两个像素之间的距离
def HSV_binaryList(imageSubMatrix, threshold):
weight, height, channels = imageSubMatrix.shape
binaryRule = []
centerPixel = imageSubMatrix[1][1]
h0 , s0, v0 = centerPixel[0], centerPixel[1], centerPixel[2]
for i in range(weight):
for j in range(height):
h1, s1, v1 = imageSubMatrix[i][j][0], imageSubMatrix[i][j][1],imageSubMatrix[i][j][2]
dh = abs(h1 - h0) / 180.0
ds = abs(h1 - h0) / 255.0
dv = abs(h1 - h0) / 255.0
distance = math.sqrt(dh ** 2 + ds ** 2 + dv ** 2) / math.sqrt(3)
if distance > threshold:
binaryRule.append(1)
else:
binaryRule.append(0)
return binaryRule
imageSubMatrix是HSV图像的3*3区域,阈值是介于0和1之间的值
我试图纠正警告,我阅读了图像并更改了数据类型。更改后,适应度得分为0。在更改像素类型(dtype='float64')之前,我的健康评分很好
startImage = cv2.imread("image1.jpg")
dst = cv2.fastNlMeansDenoisingColored(startImage,None,10,10,7,21)
resized = cv2.resize(dst,(256, 256))
initImageHSV = numpy.array(cv2.cvtColor(resized, cv2.COLOR_BGR2HSV), dtype='float64')
我能在不影响体能得分的情况下消除警告吗
目前没有回答
相关问题 更多 >
编程相关推荐