2011-08-18 24 views
8

我想對Python中的圖像應用離散餘弦變換(以及相反),我想知道做什麼和如何做的最好方法是什麼。我已經看過PIL和OpenCV,但我仍然不明白如何使用它。如何將DCT應用於Python中的圖像?

+0

不完全確定PIL和OpenCV,但同時應用DCT和反DCT基本上是將源塊與相關變換矩陣相乘。 – agibalov

回答

7

OpenCV

 
DCT(src, dst, flags) → None 

    Performs a forward or inverse Discrete Cosine transform of a 1D or 2D 
    floating-point array. 

    Parameters: 

     src (CvArr) – Source array, real 1D or 2D array 
     dst (CvArr) – Destination array of the same size and same type as the source 
     flags (int) – 

     Transformation flags, a combination of the following values 
      CV_DXT_FORWARD do a forward 1D or 2D transform. 
      CV_DXT_INVERSE do an inverse 1D or 2D transform. 
      CV_DXT_ROWS do a forward or inverse transform of every individual row of 
the input matrix. This flag allows user to transform multiple vectors simultaneously 
and can be used to decrease the overhead (which is sometimes several times larger 
than the processing itself), to do 3D and higher-dimensional transforms and so forth. 

Here is an example of it being used

該DCT也可在scipy.fftpack

+0

你能提供一個基本的程序來顯示它的用法嗎? Python似乎抱怨我的目標數組是空的。 – jmnwong

+0

您是否將目標數組重塑爲合適的大小? – agf

+0

基本上我所做的就是使用PIL調整輸入圖像的大小,然後使用cv.CreateImageHeader創建源以及空目標數組。不知道這是否正確。 – jmnwong

相關問題