gpt4 book ai didi

python - DCT with cv2和scipy

转载 作者:行者123 更新时间:2023-12-02 16:38:57 24 4
gpt4 key购买 nike

我需要使用图像色彩空间的DCT。

我有RGB imagem,需要将其转换为YUV Space并进行DCT。

这是我的代码:

import cv2
import scipy

# reading the imagem and salving it at bgr var.
bgr = cv2.imread('C:\imgtest\DSC_0091.jpg')
# Vars B, G, R, receive the information of bgr.
b,g,r = cv2.split(bgr)
# bgr will split the colorspace information in their respective variables.
bgr = cv2.merge((b,g,r))
# Var YUV will receive the result of the cvtColor function, which is transforming the RGB(now bgr) image in YUV
yuv = cv2.cvtColor(bgr,cv2.COLOR_BGR2YUV)
# Y, U, V will receive the YUV information, which is the oringinal image in YUV color channel.
y,u,v = cv2.split(yuv)
# The information will be shared in their respective color channels.
yuv = cv2.merge ((y,u,v))
# Then, i try make the DCT of the var R.
scipy.fftpack.dct(r, type=2, n=None, axis=-1, norm=None, overwrite_x=False)
# Print r
print r

但是,当我运行此代码时,出现此错误:
ValueError                                Traceback (most recent call last)
C:\Python\6.00.1x Files\cvtcolor.py in <module>()
20 # Mostra a Imagem em YUV na Tela.
21 # cv2.imshow('YUV',yuv)
---> 22 scipy.fftpack.dct(r, type=2, n=None, axis=-1, norm=None, overwrite_x=False)
23 print r

C:\Users\Tiago\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\fftpack\realtransforms.pyc in dct(x, type, n, axis, norm, overwrite_x)
133 raise NotImplementedError(
134 "Orthonormalization not yet supported for DCT-I")
--> 135 return _dct(x, type, n, axis, normalize=norm, overwrite_x=overwrite_x)
136
137

C:\Users\Tiago\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\fftpack\realtransforms.pyc in _dct(x, type, n, axis, overwrite_x, normalize)
243 raise ValueError("Type %d not understood" % type)
244 else:
--> 245 raise ValueError("dtype %s not supported" % tmp.dtype)
246
247 if normalize:

ValueError: dtype uint8 not supported

我不知道代码中是否有错误,或者是因为B,G,R,Y变量未正确显示。

有什么可以帮助我的吗?

谢谢。

最佳答案

您应该将图像数组类型转换为“float”,不支持“uint8”类型。

bgr = cv2.imread('C:\imgtest\DSC_0091.jpg').astype('float32')
那就OK了

关于python - DCT with cv2和scipy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32105569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com