2011-08-18 11 views
8

Chcę zastosować dyskretną transformację kosinusową (jak również odwrotną) do obrazu w Pythonie i zastanawiam się, jaki jest najlepszy sposób na zrobienie tego i jak. Spojrzałem na PIL i OpenCV, ale nadal nie rozumiem, jak z niego korzystać.Jak zastosować DCT do obrazu w Pythonie?

+0

Niezupełnie pewna co do PIL i OpenCV, ale zastosowanie DCT i DCT odwrotnego polega w zasadzie na pomnożeniu bloku źródłowego przez powiązane macierze transformacji. – agibalov

Odpowiedz

7

Od 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 jest również dostępny pod numerem scipy.fftpack.

+0

Czy możesz podać podstawowy program do wyświetlenia jego użycia? Python wydaje się narzekać, że moja docelowa tablica jest pusta. – jmnwong

+0

czy przekształciłeś docelową tablicę na prawidłowy rozmiar? – agf

+0

Zasadniczo to, co zrobiłem, to użycie PIL do zmiany rozmiaru obrazu wejściowego, a następnie użycie cv.CreateImageHeader do utworzenia źródła, jak również pustej tablicy docelowej. Nie jestem pewien, czy to jest poprawne. – jmnwong

Powiązane problemy