Results 1 to 2 of 2

Thread: QImage::pixelIndex out of range warning

  1. #1
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QImage::pixelIndex out of range warning

    HI everybody!

    i want create Morphological operation Dilation and erosion, i m using Format_Mono for create binary image this is my code:
    Qt Code:
    1. QImage BinaryImage::createProbe(int width, int height, bool *data[])
    2. {
    3. QImage temp(width,height,QImage::Format_Mono);
    4. for(int i=0; i<width;i++)
    5. for(int j=0; j<height;j++)
    6. temp.setPixel(i,j,(uint) data[i][j]);
    7.  
    8. return temp;
    9. }
    10.  
    11. bool **data;
    12. data = new bool*[3];
    13. for(int i=0;i<3;i++)
    14. data[i] = new bool[3];
    15.  
    16. for(int i=0;i<3;i++)
    17. for(int j=0;j<3;j++)
    18. data[i][j] = 1;
    19.  
    20. BinaryImage::createProbe(3,3,data);
    To copy to clipboard, switch view to plain text mode 

    this work great, i convert a Rgb32 image to Binary image with this code:
    Qt Code:
    1. void BinaryImage::convertToBinary(QImage* image,float treshholding)
    2. {
    3. QImage temp(image->width(),image->height(),QImage::Format_Mono);
    4.  
    5. if(image->isNull()) return;
    6.  
    7. for(int i=0; i < image->height();i++)
    8. {
    9. QRgb* p =(QRgb *)image->scanLine(i);
    10. for(int j=0;j<image->width();j++)
    11. {
    12. int c = (qRed(p[j])+qGreen(p[j])+qBlue(p[j]))/3;
    13. c = (c > treshholding * 1000)? 1 : 0;
    14. temp.setPixel(j,i,c);
    15. }
    16. }
    17.  
    18. *image = temp;
    19. }
    To copy to clipboard, switch view to plain text mode 

    this works great too.

    but my function for create dilation image is like this:
    Qt Code:
    1. Morphology::Morphology(QImage image, QImage probe)
    2. {
    3. if(image.format() == QImage::Format_Mono || probe.format() == QImage::Format_Mono)
    4. {
    5. this->image = image;
    6. this->probe = probe;
    7. }
    8. }
    9.  
    10. QImage Morphology::applyDilation()
    11. {
    12. QImage dest(image.width(),image.height(),QImage::Format_Mono);
    13.  
    14. QVector<uchar> pix_values;
    15. int i,j;
    16.  
    17. for(int row =0;row<image.height();row++)
    18. {
    19. //uchar* dst_row_ptr = dest.scanLine(row);
    20. for(int column = 0; column < image.width(); column++)
    21. {
    22. pix_values.clear();
    23. for(int prow = 0; prow < probe.height(); prow++)
    24. {
    25. i = prow + row - probe.height() / 2;
    26. //uchar* img_row_ptr = image.scanLine(i);
    27. //uchar* prb_row_ptr = probe.scanLine(prow);
    28.  
    29. for(int pcolumn = 0; pcolumn < probe.width(); pcolumn++)
    30. {
    31. j = column + pcolumn - probe.width() / 2;
    32. if(i >= 0 && i < image.height() && j >= 0 && j < image.width())
    33. if(probe.pixelIndex(prow, pcolumn) == 1)
    34. pix_values.push_back(image.pixelIndex(i, j));
    35. }
    36. }
    37. dest.setPixel(row,column,(uint)*std::max_element(pix_values.begin(), pix_values.end())); //the max goes in the destination
    38. }
    39. }
    40.  
    41. return dest;
    42. }
    43.  
    44. //run code is this
    45. BinaryImage::convertToBinary(img,0.17);
    46.  
    47. bool **data;
    48. data = new bool*[3];
    49. for(int i=0;i<3;i++)
    50. data[i] = new bool[3];
    51.  
    52. for(int i=0;i<3;i++)
    53. for(int j=0;j<3;j++)
    54. data[i][j] = 1;
    55. Morphology morph(*img,BinaryImage::createProbe(3,3,data));
    56. imageLabel->setPixmap(QPixmap::fromImage(morph.applyDilation()));
    57. imageLabel->adjustSize();
    To copy to clipboard, switch view to plain text mode 
    this function is work too but get a lot of warnings QImage:ixelInde() that is out of range and run program too slow.
    what is the problem?
    what i can do for i havent any warning and run program fast?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QImage::pixelIndex out of range warning

    Qt Code:
    1. dest.setPixel(row,column,(uint)*std::max_element(pix_values.begin(), pix_values.end())); //the max goes in the destination
    To copy to clipboard, switch view to plain text mode 
    has to be
    Qt Code:
    1. dest.setPixel(column,row,(uint)*std::max_element(pix_values.begin(), pix_values.end())); //the max goes in the destination
    To copy to clipboard, switch view to plain text mode 
    And some other calls before that line has to be changed also.

  3. The following user says thank you to Lykurg for this useful post:

    danics (10th March 2010)

Similar Threads

  1. Out of range detection
    By zgulser in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2009, 09:32
  2. Index out of Range
    By santhoshv84 in forum Qt Programming
    Replies: 2
    Last Post: 19th August 2008, 15:33
  3. QLineEdit set min max range?
    By whitefurrows in forum Qt Programming
    Replies: 29
    Last Post: 10th June 2006, 23:51
  4. Elements out of Range!!
    By Kapil in forum Newbie
    Replies: 9
    Last Post: 3rd April 2006, 10:28
  5. Replies: 3
    Last Post: 15th March 2006, 11:44

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.