如何解决python:切片的值分配出错
我正在尝试学习关于图像处理的课程,并且作为其中的一部分,如果使用 cv2.下面是我的代码:
def DoJpegCompression(img):
(h,w) = img.shape[:2]
for x in range(0,h,8):
for y in range(0,w,8):
avg3x3 = img[x:x+8,y:y+8]
(h1,w1) = avg3x3.shape[:2]
if h1%2 == 0 and w1%2 == 0:
#print(avg3x3,file = open("input.txt",'a'))
iDct = numpy.zeros(avg3x3.shape[:2],dtype = numpy.float32)
getDctimage(avg3x3.astype(numpy.float32),iDct)
#print(iDct,file = open("dct.txt",'a'))
iQuant = getQuantizedImage(iDct,2)
print(iQuant,file = open("Quantized.txt",'a'))
img[x:x+8,y:y+8] = iQuant.astype(int)
pass
pass
pass
print(img,file = open("Compressed.txt",'a'))
在这里,我看到“Quantized.txt”中的值与“Compressed.txt”中的值不同,并且差异很大。从某种意义上说,“Compressed.txt”中存在某些值在量化值中只是零。
这里可能出了什么问题:img[x:x+8,y:y+8] = iQuant.astype(int)
?
任何线索表示赞赏。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。