Results 1 to 2 of 2

Thread: computation problem

  1. #1
    Join Date
    Jan 2016
    Posts
    22
    Thanks
    13

    Default computation problem

    Hello everone,
    please if someone can help me, i want to compute the fourier transform of an image and display it in a Qtable view, but i don't know why it dosn't give an image that i expected. it give me a white image

    here the .cpp
    Qt Code:
    1. #include "fenprin.h"
    2. #include <QVector>
    3. #include "math.h"
    4.  
    5. FenPrin::FenPrin()
    6. {
    7. QWidget *zoneCentrale = new QWidget();
    8. layout = new QVBoxLayout(this);
    9. ok = new QPushButton("Charger image",this);
    10. histogram = new QPushButton("calculer histogramme");
    11. fourier = new QPushButton("calcule fourier");
    12. label = new QLabel(this);
    13. table = new QStandardItemModel(90, 90);
    14. view = new QTableView;
    15. layout->addWidget(ok);
    16. // layout->addWidget(histogram);
    17. layout->addWidget(fourier);
    18. layout->addWidget(label);
    19. layout->addWidget(&label2);
    20. layout->addWidget(view);
    21. zoneCentrale->setLayout(layout);
    22. setCentralWidget(zoneCentrale);
    23. QObject::connect(ok, SIGNAL(clicked(bool)), this, SLOT(afficher()));
    24. //connect(histogram, SIGNAL(clicked(bool)), this, SLOT(histograme()));
    25. connect(fourier, SIGNAL(clicked(bool)), this, SLOT(fourierTransform()));
    26. }
    27. void FenPrin::afficher()
    28. {
    29. myImage = QFileDialog::getOpenFileName(this, "Choisir image","C:/Users/amine/Desktop");
    30. label->setPixmap(QPixmap(myImage));
    31. }
    32. double FenPrin::max(double **matrix, int h, int w)
    33. {
    34. double max = 0.0;
    35. for(int i=0; i<h; i++)
    36. for(int j=0; j<w; j++)
    37. {
    38. if (matrix[i][j] > max)
    39. max = matrix[i][j];
    40. }
    41. return max;
    42. }
    43. double FenPrin::logOperator(double m)
    44. {
    45. double c;
    46. c = 255 / log(1 + abs(m));
    47. return c;
    48. }
    49.  
    50. void FenPrin::histograme()
    51. {
    52. int i = 0,j =0;
    53. int grayLev;
    54. int *hist;
    55. hist = new int[256];
    56. for(int i = 0; i<256; i++)
    57. hist[i] = 0;
    58.  
    59. while(i < image->height()){
    60. while(j < image->width())
    61. {
    62. grayLev = (qRed(image->pixel(j,i)) + qBlue(image->pixel(j,i)) + qGreen(image->pixel(j,i)))/3;
    63. hist[grayLev] += 1;
    64. j++;
    65. }
    66. i++;
    67. }
    68. // paindre sur une image
    69. for(int i=0; i<256; i++)
    70. table->setItem(0, i, new QStandardItem(QString::number(hist[i])));
    71. label2.setText(QString::number(hist[0]));
    72. view->setModel(table);
    73. // déclaration d'un tableau dynamique à 2 dimensions
    74.  
    75. QPixmap pixmap;
    76. pixmap.convertFromImage(*image);
    77. label->setPixmap(pixmap);
    78.  
    79. // afficher l'histogramme
    80. }
    81. void FenPrin::fourierTransform()
    82. {
    83. image = new QImage(myImage);
    84. double sumRe=0, sumI=0;
    85. double sumR[90];
    86. double sumIm[90];
    87. double angle;
    88. double **fourierR;
    89. double **fourierI;
    90. double **fourierMag;
    91. double *fourier1D;
    92. fourierR = new double *[image->height()];
    93. for(int i=0; i<image->height(); i++)
    94. fourierR[i] = new double[image->width()];
    95. fourierI = new double *[image->height()];
    96. for(int i=0; i<image->height(); i++)
    97. fourierI[i] = new double[image->width()];
    98. // calcule de la transforme de fourier
    99.  
    100. for(int i=0; i<image->height();i++){
    101. for(int j=0; j<image->width();j++){
    102. for(int h=0; h<image->height(); h++){
    103. for(int l=0; l<image->width(); l++){
    104. int grayLev = (qRed(image->pixel(l,h)) + qBlue(image->pixel(l,h)) + qGreen(image->pixel(l,h)))/3;
    105. angle = (i*h)/image->height() + (j*l)/image->width();
    106. sumRe += (grayLev) * cos(-2*M_PI*angle);
    107. sumI += (grayLev) * sin(-2*M_PI*angle);
    108. }
    109. }
    110. fourierR[i][j] = sumRe;
    111. fourierI[i][j] = sumI;
    112. sumRe = 0;
    113. sumI = 0;
    114. }
    115. }
    116.  
    117.  
    118. for(int i=0; i<image->height();i++)
    119. for(int l=0; l<image->height();l++)
    120. {
    121. int grayLev = (qRed(image->pixel(l,i)) + qBlue(image->pixel(l,i)) + qGreen(image->pixel(l,i)))/3;
    122. sumRe += (grayLev) * cos(-2*M_PI*i*l);
    123. }
    124.  
    125. fourierMag = new double *[image->height()];
    126. for (int i=0; i<image->height();i++)
    127. fourierMag[i] = new double[image->width()];
    128. for(int i=0; i<image->height();i++)
    129. for(int j=0; j<image->width();j++)
    130. fourierMag[i][j] = sqrt(pow(fourierR[i][j],2) + pow(fourierI[i][j],2));
    131. double maxi = max(fourierMag, image->height(), image->width());
    132.  
    133. for(int i=0; i<image->height();i++)
    134. for(int j=0; j<image->width();j++)
    135. fourierMag[i][j] = logOperator(maxi) * log(1 + abs(fourierMag[i][j]));
    136.  
    137. for(int i=0; i<image->height();i++)
    138. for(int j=0; j<image->width();j++)
    139. image->setPixel(j, i, qRgb(fourierMag[i][j],fourierMag[i][j],fourierMag[i][j]));
    140.  
    141. QPixmap pixmap;
    142. pixmap.convertFromImage(*image);
    143. label->setPixmap(pixmap);
    144. label2.setText(QString::number(fourierMag[0][0]));
    145. for(int i=0; i<90; i++)
    146. for( int j=0; j< image->width(); j++)
    147. table->setItem(i, j, new QStandardItem(QString::number(fourierMag[i][j])));
    148. view->setModel(table);
    149. }
    To copy to clipboard, switch view to plain text mode 
    thank you.
    Last edited by rafik; 16th October 2016 at 16:56.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: computation problem

    image->setPixel(j, i, qRgb(fourierMag[i][j],fourierMag[i][j],fourierMag[i][j]));
    qRgb() expects integer arguments in the range 0 - 255. You are giving it float arguments, and I doubt these are in that same range.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 4
    Last Post: 11th December 2008, 18:35
  2. Screen refresh during heavy computation
    By martinb0820 in forum Qt Programming
    Replies: 5
    Last Post: 17th November 2008, 23:20
  3. Replies: 11
    Last Post: 7th July 2006, 14:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.