IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenCV Discussion :

Augmentation d'image par transformée de Fourier


Sujet :

OpenCV

  1. #1
    Membre à l'essai
    Inscrit en
    Avril 2008
    Messages
    41
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 41
    Points : 21
    Points
    21
    Par défaut Augmentation d'image par transformée de Fourier
    Salut,
    je suis entrain de faire l'augmentation de d'image d'empreinte digitale en utilisant
    le Transformée de Fourier TF dont le principe est le suivant:
    on divise l'image en blocs de 32*32 pixels et à chaque bloc, on applique le TF on obtient F(u,V), ensuite on le multuplie par son amplitude puissance k=1.4, enfin on applique au resultat le Inverse de TF on obtient donc l'image augmenté.

    je suis besoin d'aide pour le coder.j'ai déja commencé mais je me suis bloqué au niveau de multiplication de spectre par l'amplitude^k.

    Merci d'avance

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 14
    Points : 13
    Points
    13
    Par défaut
    Est ce que tu peut écrire ton code pour t'aider

  3. #3
    Membre à l'essai
    Inscrit en
    Avril 2008
    Messages
    41
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 41
    Points : 21
    Points
    21
    Par défaut
    Salut,voila le code:

    #include <cxcore.h>
    #include <cv.h>
    #include <highgui.h>

    IplImage *copySubImage(IplImage *img,int xorigine,int yorigine,int width,int height)
    {
    CvRect roi;
    IplImage *resultat;
    roi.x= xorigine;
    roi.y=yorigine;
    roi.width=width;
    roi.height=height;
    cvSetImageROI(img,roi);
    resultat=cvCreateImage(cvSize(roi.width,roi.height),img->depth,img->Channels );
    cvCopy(im,resultat);
    cvResetImageROI(img);
    return resultat;
    }

    // Rearrange the quadrants of Fourier image so that the origin is at
    // the image center
    // src & dst arrays of equal size & type
    void cvShiftDFT(CvArr * src_arr, CvArr * dst_arr )
    {
    CvMat * tmp;
    CvMat q1stub, q2stub;
    CvMat q3stub, q4stub;
    CvMat d1stub, d2stub;
    CvMat d3stub, d4stub;
    CvMat * q1, * q2, * q3, * q4;
    CvMat * d1, * d2, * d3, * d4;

    CvSize size = cvGetSize(src_arr);
    CvSize dst_size = cvGetSize(dst_arr);
    int cx, cy;

    if(dst_size.width != size.width ||
    dst_size.height != size.height){
    cvError( CV_StsUnmatchedSizes, "cvShiftDFT", "Source and Destination arrays must have equal sizes", __FILE__, __LINE__ );
    }

    if(src_arr==dst_arr){
    tmp = cvCreateMat(size.height/2, size.width/2, cvGetElemType(src_arr));
    }

    cx = size.width/2;
    cy = size.height/2; // image center

    q1 = cvGetSubRect( src_arr, &q1stub, cvRect(0,0,cx, cy) );
    q2 = cvGetSubRect( src_arr, &q2stub, cvRect(cx,0,cx,cy) );
    q3 = cvGetSubRect( src_arr, &q3stub, cvRect(cx,cy,cx,cy) );
    q4 = cvGetSubRect( src_arr, &q4stub, cvRect(0,cy,cx,cy) );
    d1 = cvGetSubRect( src_arr, &d1stub, cvRect(0,0,cx,cy) );
    d2 = cvGetSubRect( src_arr, &d2stub, cvRect(cx,0,cx,cy) );
    d3 = cvGetSubRect( src_arr, &d3stub, cvRect(cx,cy,cx,cy) );
    d4 = cvGetSubRect( src_arr, &d4stub, cvRect(0,cy,cx,cy) );

    if(src_arr!=dst_arr){
    if( !CV_ARE_TYPES_EQ( q1, d1 )){
    cvError( CV_StsUnmatchedFormats, "cvShiftDFT", "Source and Destination arrays must have the same format", __FILE__, __LINE__ );
    }
    cvCopy(q3, d1, 0);
    cvCopy(q4, d2, 0);
    cvCopy(q1, d3, 0);
    cvCopy(q2, d4, 0);
    }
    else{
    cvCopy(q3, tmp, 0);
    cvCopy(q1, q3, 0);
    cvCopy(tmp, q1, 0);
    cvCopy(q4, tmp, 0);
    cvCopy(q2, q4, 0);
    cvCopy(tmp, q2, 0);
    }
    }

    int main(int argc, char ** argv)
    {

    IplImage * im;
    IplImage * img;

    IplImage * realInput;
    IplImage * imaginaryInput;
    IplImage * complexInput;
    int dft_M, dft_N;
    CvMat* dft_A, tmp;
    IplImage * image_Re;
    IplImage * image_Im;

    double m, M;

    img = cvLoadImage( "fingerprint.jpg", CV_LOAD_IMAGE_GRAYSCALE );
    if( !img )
    return -1;
    im = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1);
    im=copySubImage(img,0,0,32,32);
    realInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1);
    imaginaryInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1);
    complexInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 2);

    cvScale(im, realInput, 1.0, 0.0);
    cvZero(imaginaryInput);
    cvMerge(realInput, imaginaryInput, NULL, NULL, complexInput);

    dft_M = cvGetOptimalDFTSize( im->height - 1 );
    dft_N = cvGetOptimalDFTSize( im->width - 1 );

    dft_A = cvCreateMat( dft_M, dft_N, CV_64FC2 );
    image_Re = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1);
    image_Im = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1);

    // copy A to dft_A and pad dft_A with zeros
    cvGetSubRect( dft_A, &tmp, cvRect(0,0, im->width, im->height));
    cvCopy( complexInput, &tmp, NULL );
    if( dft_A->cols > im->width )
    {
    cvGetSubRect( dft_A, &tmp, cvRect(im->width,0, dft_A->cols - im->width, im->height));
    cvZero( &tmp );
    }

    // no need to pad bottom part of dft_A with zeros because of
    // use nonzero_rows parameter in cvDFT() call below

    cvDFT( dft_A, dft_A, CV_DXT_FORWARD, complexInput->height );

    cvNamedWindow("win", 0);
    cvNamedWindow("magnitude", 0);
    cvShowImage("win", im);

    // Split Fourier in real and imaginary parts
    cvSplit( dft_A, image_Re, image_Im, 0, 0 );

    // Compute the magnitude of the spectrum Mag = sqrt(Re^2 + Im^2)
    cvPow( image_Re, image_Re, 2.0);
    cvPow( image_Im, image_Im, 2.0);
    cvAdd( image_Re, image_Im, image_Re, NULL);
    cvPow( image_Re, image_Re, 0.5 );
    IplImag *Mg=cvCloneImage(image_Re);
    // Compute log(1 + Mag)
    cvAddS( image_Re, cvScalarAll(1.0), image_Re, NULL ); // 1 + Mag
    cvLog( image_Re, image_Re ); // log(1 + Mag)


    // Rearrange the quadrants of Fourier image so that the origin is at
    // the image center
    cvShiftDFT( image_Re, image_Re );

    cvMinMaxLoc(image_Re, &m, &M, NULL, NULL, NULL);
    cvScale(image_Re, image_Re, 1.0/(M-m), 1.0*(-m)/(M-m));
    cvShowImage("magnitude", image_Re);
    //multiplication par l'amplitude^k avec k=1.4
    cvPow(Mg,Mg,1.4);
    for(int x=0;x<image_Re->height;x++)
    for(int y=0;y<image_Re->width;y++)
    cvSetReal2D(image_Re,x,y,cvGetReal2D(image_Re,x,y)* cvGetReal2D(Mg,x,y));

    cvDFT(image_Re,image_Re,CV_DXT_INVERSE);
    cvNamedWindow("inverse DFT", 0);
    cvShowImage("inverse DFT", image_Re);


    cvWaitKey(-1);
    return 0;
    }

    j'ai besoin de me vérifier si l'image Mg est l'amplitude de TF ou non et est ce que mon manipulation d'image surtout pour le TF inverse est correct ou non.
    NB: ce code traite uniquement un bloc.

    Merci d'avance de m'aider.

  4. #4
    Membre à l'essai
    Inscrit en
    Avril 2008
    Messages
    41
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 41
    Points : 21
    Points
    21
    Par défaut
    Salut,
    c'est urgent svp si quelqu'un peux m'aider.

Discussions similaires

  1. Segmentation d'images par transformée en ondelettes
    Par ayachimi dans le forum Traitement d'images
    Réponses: 0
    Dernier message: 07/02/2013, 19h52
  2. Réponses: 6
    Dernier message: 07/10/2008, 03h15
  3. décomposition d'image par la transformée en ondelettes
    Par tapouni dans le forum Traitement d'images
    Réponses: 1
    Dernier message: 07/04/2008, 09h33
  4. Recalage d'image par la Transformée de Fourier (Prob de Dimension des images)
    Par Programmeur_Aladdin dans le forum Traitement d'images
    Réponses: 7
    Dernier message: 26/02/2008, 15h14

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo