假设您使用dct函数,然后不对数据进行操作并使用反转变换; 倒置数据不会与预转换数据相同吗?为什么浮点问题?是报告的问题还是正常行为?
In [21]: a = [1.2, 3.4, 5.1, 2.3, 4.5]
In [22]: b = dct(a)
In [23]: b
Out[23]: array([ 33. , -4.98384545, -4.5 , -5.971707 , 4.5 ])
In [24]: c = idct(b)
In [25]: c
Out[25]: array([ 12., 34., 51., 23., 45.])
Run Code Online (Sandbox Code Playgroud)
任何人都有解释为什么?当然,一个简单的c*10**-1方法可以解决这个问题,但是如果你重复调用函数来在几个维度上使用它,那么错误就会变大:
In [37]: a = np.random.rand(3,3,3)
In [38]: d = dct(dct(dct(a).transpose(0,2,1)).transpose(2,1,0)).transpose(2,1,0).transpose(0,2,1)
In [39]: e = idct(idct(idct(d).transpose(0,2,1)).transpose(2,1,0)).transpose(2,1,0).transpose(0,2,1)
In [40]: a
Out[40]:
array([[[ 0.48709809, 0.50624831, 0.91190972],
[ 0.56545798, 0.85695062, 0.62484782],
[ 0.96092354, 0.17453537, 0.17884233]],
[[ …Run Code Online (Sandbox Code Playgroud) 我正在尝试将赵科赫隐写术方法从 matlab 重写为 python,但我一开始就被卡住了。
前两个程序在 matlab 中:
第1步:
A = imread(casepath); # Reading stegonography case image and aquiring it's RGB values. In my case it's a 400x400 PNG image, so it gives a 400x400x3 array.
Run Code Online (Sandbox Code Playgroud)
第2步:
D = dct2(A(:,:,3)); # Applying 2D DCT to blue values of the image
Run Code Online (Sandbox Code Playgroud)
Python代码模拟:
from scipy import misc
from numpy import empty,arange,exp,real,imag,pi
from numpy.fft import rfft,irfft
arr = misc.imread('casepath')# 400x480x3 array (Step 1)
arr[20, 30, 2] # Getting blue pixel value
def dct(y): #Basic …Run Code Online (Sandbox Code Playgroud)