8

Voglio applicare una Trasformata Coseno Discreta (e l'inverso) a un'immagine in Python e mi chiedo quale sia il modo migliore per farlo e come. Ho guardato PIL e OpenCV ma ancora non capisco come usarlo.Come applicare un DCT a un'immagine in Python?

+0

Non sono esattamente sicuro di PIL e OpenCV, ma l'applicazione di DCT e DCT inversa sta praticamente moltiplicando il blocco sorgente per le relative matrici di trasformazione. – agibalov

risposta

7

Da 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.

Il DCT è disponibile anche in scipy.fftpack.

+0

Potresti fornire un programma di base per visualizzarne l'utilizzo? Python sembra lamentarsi del fatto che il mio array di destinazione sia vuoto. – jmnwong

+0

hai rimodellato la matrice di destinazione con le dimensioni corrette? – agf

+0

Essenzialmente quello che ho fatto è usare PIL per ridimensionare un'immagine di input e quindi usare cv.CreateImageHeader per creare l'origine e una matrice di destinazione vuota. Non sono sicuro se questo è corretto. – jmnwong

Problemi correlati