Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Image processing and sizes
Forum Updated to NodeBB v4.3 + New Features

Image processing and sizes

Scheduled Pinned Locked Moved General and Desktop
15 Posts 3 Posters 9.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    ZapB
    wrote on last edited by
    #6

    What does QImage::format() return for an image that works and one that doesn't?

    Nokia Certified Qt Specialist
    Interested in hearing about Qt related work

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Anticross
      wrote on last edited by
      #7

      I've got massages in output window of my debbuger
      QImage::pixel: coordinate (0,2336) out of range
      QImage::pixel: coordinate (0,2337) out of range
      QImage::pixel: coordinate (0,2338) out of range
      QImage::pixel: coordinate (0,2339) out of range
      QImage::pixel: coordinate (0,2340) out of range
      QImage::pixel: coordinate (0,2341) out of range
      ...
      So it's happens when I processed 3504*2336 image. why it not limited by size of image or I have a mistake in my loops limits?

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #8

        You have you're i and j loop counters back to front in the call to image.pixel(). It should be:

        @
        QRgb currentPixel = image.pixel( j, i );
        @

        since you are using j to loop over the x-coord and i to iterate over the y coord. See how the debugger helps you ;-)

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #9

          You have made the same mistake in the call to setPixel() too.

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #10

            So with all the above in place your code should look like this:

            @
            void ImageWidget::proccessImage(QColor color)
            {
            // Search algorithm

            QImage image = m_image;
            int match = 5;

            for(int i = 0; i<image.height(); i++)
            {
            for(int j = 0; j<image.width(); j++)
            {
            QRgb currentPixel = image.pixel(j,i);

            QColor pixColor = QColor::fromRgb(currentPixel);

            if(qAbs(pixColor.red()-color.red()) > match && 
               qAbs(pixColor.green()-color.green()) > match &&
               qAbs(pixColor.blue()-color.blue()) > match)
                image.setPixel(j,i,qRgb(255,255,255));
            

            }
            }
            m_imageLabel->setPixmap(QPixmap::fromImage(image));
            }
            @

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Anticross
              wrote on last edited by
              #11

              Damn, it's so easy :) I need to be more attentive. Thanks for the help and some code optimization.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #12

                Hi Anticross,

                One idea to make the code a bit more readable und to easier find such problems (use x and y instead of i and j), make some renaming. You can also use QRgb directly.

                @
                void ImageWidget::proccessImage(QColor color)
                {
                // Search algorithm

                QImage image = m_image;
                int difference = 5;
                
                for(int y = 0; y < image.height(); y++)
                {
                    for(int x = 0; x < image.width(); x++)
                    {
                        QRgb currentPixel = image.pixel(x,y);
                
                        if( qAbs(qRed(currentPixel) - color.red()) > difference &&
                            qAbs(qGreen(currentPixel) - color.green()) > difference &&
                            qAbs(qBlue(currentPixel) - color.blue()) > difference)
                        {
                            image.setPixel(x,y,qRgb(255,255,255));
                        }
                    }
                }
                m_imageLabel->setPixmap(QPixmap::fromImage(image));
                

                }
                @

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  ZapB
                  wrote on last edited by
                  #13

                  I usually tend to use i for iterating over x and j for iterating over ysince it reminds me of i and j unit vectors. I also tend to use epsilon or delta for small values such as your match or difference variables. It's just taste though and this is my background in mathematics prejudicing me. ;-)

                  Nokia Certified Qt Specialist
                  Interested in hearing about Qt related work

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #14

                    As we are talking about coordinates, and height and width, it's usually x and y. That's why I changed that. i is usually (with the developers I work with :-) ) a variable for a normal for loop. For cascading, I normally use row and column or s9imilar things, por x and y if they are coordinated (which they are in this case).

                    But it's a matter of taste.

                    And match was (for me) just nothing that was clear from the name. match for me would be a boolean (matches or not)

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0
                    • Z Offline
                      Z Offline
                      ZapB
                      wrote on last edited by
                      #15

                      Yeah for me it also depends upon the context in which the loop(s) occur. If I am iterating over rows then I'll use "row". Usually I try to use something that makes it obvious to which the counter refers.

                      Nokia Certified Qt Specialist
                      Interested in hearing about Qt related work

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved