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. Picture
Forum Updated to NodeBB v4.3 + New Features

Picture

Scheduled Pinned Locked Moved Solved General and Desktop
82 Posts 7 Posters 46.5k Views 3 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.
  • P Offline
    P Offline
    Payx
    wrote on 24 Oct 2016, 13:52 last edited by VRonin
    #1

    Hello guys,

    I got a project to do :

    i want display a picture (i have already do that) and i want to reduce the resolution of the picture by 4 and work with all this square, like know the main color of these square.

    so i work on it with :

    int step=4;
    	for (int i=0;i<pix.width();i=i+step){                                  // the name of my picture is "pix"
    		for (int j=0;j<pix.height();j=j+step){
                                                                                                        // its here where im blocked
    }
    }
    

    i know what i have to do but i dont know how i can traduce it in C
    like with "QImage copy(const QRect & rectangle = QRect()) const" i suppose

    can you help me ?

    J 1 Reply Last reply 24 Oct 2016, 14:36
    0
    • P Payx
      24 Oct 2016, 13:52

      Hello guys,

      I got a project to do :

      i want display a picture (i have already do that) and i want to reduce the resolution of the picture by 4 and work with all this square, like know the main color of these square.

      so i work on it with :

      int step=4;
      	for (int i=0;i<pix.width();i=i+step){                                  // the name of my picture is "pix"
      		for (int j=0;j<pix.height();j=j+step){
                                                                                                          // its here where im blocked
      }
      }
      

      i know what i have to do but i dont know how i can traduce it in C
      like with "QImage copy(const QRect & rectangle = QRect()) const" i suppose

      can you help me ?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 24 Oct 2016, 14:36 last edited by
      #2

      @Payx said in Picture:

      i want to reduce the resolution of the picture by 4 and work with all this square

      Sorry I don't understand your use case:
      "i want to reduce the resolution of the picture by 4 and work with all this square"
      Do you want to reduce the resolution of the picture or divide it into 4x4 sub-pictures?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply 24 Oct 2016, 14:58
      0
      • J jsulm
        24 Oct 2016, 14:36

        @Payx said in Picture:

        i want to reduce the resolution of the picture by 4 and work with all this square

        Sorry I don't understand your use case:
        "i want to reduce the resolution of the picture by 4 and work with all this square"
        Do you want to reduce the resolution of the picture or divide it into 4x4 sub-pictures?

        P Offline
        P Offline
        Payx
        wrote on 24 Oct 2016, 14:58 last edited by
        #3

        @jsulm Yes i want to cut the picture in square 4x4

        sorry

        P 1 Reply Last reply 24 Oct 2016, 18:35
        0
        • P Payx
          24 Oct 2016, 14:58

          @jsulm Yes i want to cut the picture in square 4x4

          sorry

          P Offline
          P Offline
          Payx
          wrote on 24 Oct 2016, 18:35 last edited by
          #4

          cut the picture in square 4x4 but with this 4x4 square i will just determinate the most contained color, and by the way do a simple pixel with it

          M 1 Reply Last reply 24 Oct 2016, 18:49
          0
          • P Payx
            24 Oct 2016, 18:35

            cut the picture in square 4x4 but with this 4x4 square i will just determinate the most contained color, and by the way do a simple pixel with it

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 24 Oct 2016, 18:49 last edited by
            #5

            @Payx said in Picture:

            and by the way do a simple pixel with it

            Hi can you explain more what you do with it?

            P 1 Reply Last reply 24 Oct 2016, 19:11
            1
            • M mrjj
              24 Oct 2016, 18:49

              @Payx said in Picture:

              and by the way do a simple pixel with it

              Hi can you explain more what you do with it?

              P Offline
              P Offline
              Payx
              wrote on 24 Oct 2016, 19:11 last edited by
              #6

              @mrjj i cut my picture in square 4x4, and with this square i just calculate the most contained color, i replace all this square by the color and it give me a simple square with just one color

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 24 Oct 2016, 19:31 last edited by
                #7

                Hi,

                Why not use QImage::scaled ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                P 1 Reply Last reply 24 Oct 2016, 19:58
                1
                • S SGaist
                  24 Oct 2016, 19:31

                  Hi,

                  Why not use QImage::scaled ?

                  P Offline
                  P Offline
                  Payx
                  wrote on 24 Oct 2016, 19:58 last edited by
                  #8

                  @SGaist I don't know if it will work (im a beginner) but the function return only one square ? or i can use this function to cut in 4x4 square my picture with a double "for" ?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 24 Oct 2016, 20:01 last edited by
                    #9

                    It was just for the resizing part.

                    For the processing itself, it might be better to use a library like OpenCV which likely already implement what you need.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    P 2 Replies Last reply 24 Oct 2016, 20:14
                    0
                    • S SGaist
                      24 Oct 2016, 20:01

                      It was just for the resizing part.

                      For the processing itself, it might be better to use a library like OpenCV which likely already implement what you need.

                      P Offline
                      P Offline
                      Payx
                      wrote on 24 Oct 2016, 20:14 last edited by
                      #10

                      @SGaist ok i will install OpenCV on Qt and come if i need more help

                      1 Reply Last reply
                      0
                      • S SGaist
                        24 Oct 2016, 20:01

                        It was just for the resizing part.

                        For the processing itself, it might be better to use a library like OpenCV which likely already implement what you need.

                        P Offline
                        P Offline
                        Payx
                        wrote on 26 Oct 2016, 18:10 last edited by
                        #11

                        @SGaist there is a lot of tutorial for install OpenCV, and they are all different... can you have a good tutorial to show me ?

                        M 1 Reply Last reply 26 Oct 2016, 18:19
                        0
                        • P Payx
                          26 Oct 2016, 18:10

                          @SGaist there is a lot of tutorial for install OpenCV, and they are all different... can you have a good tutorial to show me ?

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 26 Oct 2016, 18:19 last edited by
                          #12

                          @Payx
                          Hi
                          can i ask what effect you are after ?
                          It sounds like you want to make the image more pixelated?

                          P 1 Reply Last reply 26 Oct 2016, 19:24
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 26 Oct 2016, 19:16 last edited by
                            #13

                            What OS are you on ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • M mrjj
                              26 Oct 2016, 18:19

                              @Payx
                              Hi
                              can i ask what effect you are after ?
                              It sounds like you want to make the image more pixelated?

                              P Offline
                              P Offline
                              Payx
                              wrote on 26 Oct 2016, 19:24 last edited by
                              #14

                              @mrjj No,

                              I got an image, i just want to cut the image in square 4x4 (pixels) and with this square, i want to detect the most contained color. When i have this color i replace entirely the square by the color.

                              Exemple : if i got an image, if the first square 4x4 i have on the image is contained by 80% of red, that will replace the entirely square by red only.

                              This project is to have a "simple" picture.

                              with this simple picture i can reproduce it with candies (for exemple). Because if i got 800800 pixels i can't buy 800800 candies so i have to "reduce" it

                              Im on windows 10

                              K 1 Reply Last reply 27 Oct 2016, 01:21
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 26 Oct 2016, 19:42 last edited by
                                #15

                                Then you can use the OpenCV installer, just ensure that you have an OpenCV version built with the same compiler you are using with Qt.

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                P 1 Reply Last reply 26 Oct 2016, 20:15
                                0
                                • S SGaist
                                  26 Oct 2016, 19:42

                                  Then you can use the OpenCV installer, just ensure that you have an OpenCV version built with the same compiler you are using with Qt.

                                  P Offline
                                  P Offline
                                  Payx
                                  wrote on 26 Oct 2016, 20:15 last edited by
                                  #16

                                  @SGaist I spoke with my teacher, he told me we dont need OpenCV

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on 26 Oct 2016, 21:51 last edited by
                                    #17

                                    I never said you needed it just that it might be simpler through it.

                                    In any case, you can use QImage::pixelColor to get the color of one pixel of your image and then do the calculation with the surrounding pixels.

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    P 1 Reply Last reply 26 Oct 2016, 22:18
                                    1
                                    • S SGaist
                                      26 Oct 2016, 21:51

                                      I never said you needed it just that it might be simpler through it.

                                      In any case, you can use QImage::pixelColor to get the color of one pixel of your image and then do the calculation with the surrounding pixels.

                                      P Offline
                                      P Offline
                                      Payx
                                      wrote on 26 Oct 2016, 22:18 last edited by
                                      #18

                                      @SGaist said in Picture:

                                      QImage::pixelColor

                                      Ok, i will try to use it tomorrow, but i already have a question, i can't use a function in the "void MainWindow::on_push_clicked()" no ?

                                      J 1 Reply Last reply 27 Oct 2016, 04:26
                                      0
                                      • P Payx
                                        26 Oct 2016, 19:24

                                        @mrjj No,

                                        I got an image, i just want to cut the image in square 4x4 (pixels) and with this square, i want to detect the most contained color. When i have this color i replace entirely the square by the color.

                                        Exemple : if i got an image, if the first square 4x4 i have on the image is contained by 80% of red, that will replace the entirely square by red only.

                                        This project is to have a "simple" picture.

                                        with this simple picture i can reproduce it with candies (for exemple). Because if i got 800800 pixels i can't buy 800800 candies so i have to "reduce" it

                                        Im on windows 10

                                        K Offline
                                        K Offline
                                        kshegunov
                                        Moderators
                                        wrote on 27 Oct 2016, 01:21 last edited by
                                        #19

                                        @Payx said in Picture:

                                        I got an image, i just want to cut the image in square 4x4 (pixels) and with this square, i want to detect the most contained color. When i have this color i replace entirely the square by the color.
                                        Exemple : if i got an image, if the first square 4x4 i have on the image is contained by 80% of red, that will replace the entirely square by red only.
                                        This project is to have a "simple" picture.
                                        with this simple picture i can reproduce it with candies (for exemple). Because if i got 800800 pixels i can't buy 800800 candies so i have to "reduce" it

                                        It sounds to me you're after color space reduction after scaling. Just resample the image to the desired resolution with QImage::scaled as @SGaist suggested. Then the color space reduction boils down to calculating distances in 3 dimensional rectangular coordinate system (colors are vectors in RGB space). Suppose you have a table of 32 colors and an image:

                                        QImage image;
                                        
                                        const qint32 colorTableSize = 32;
                                        QColor colorTable[colorTableSize] = { Qt::Red, Qt::Blue, ... };
                                        

                                        Then for each pixel you choose the color from the table that's closest in the color space:

                                        // Just go around the image
                                        for (qint32 y = 0, height = image.height(); y < height; y++)  {
                                            for (qint32 x = 0, width = image.width(); x < width; x++)  {
                                                QColor pixel = image.pixelColor(x, y);
                                        
                                                // Find the closest match from the table
                                                qint32 colorIndex = 0;
                                                qreal minDistance = std::sqrt(3); // Initial value is the longest possible distance
                                                for (qint32 i = 0; i < colorTableSize; i++)  {
                                                    qreal distance = QVector3D(pixel.redF() - colorTable[i].redF(), pixel.greenF() - colorTable[i].greenF(), pixel.blueF() - colorTable[i].blueF()).length();
                                                    if (distance < minDistance)  {  // Found a closer color than the currently selected
                                                        minDistance = distance;
                                                        colorIndex = i;
                                                    }
                                                }
                                        
                                                // Now just replace the pixel color with the one from the table
                                                image.setPixelColor(x, y, colorTable[colorIndex]);
                                            }
                                        }
                                        

                                        This doesn't take into account the disparity of color sensitivity of the human eye. If you need to account for this then you need to dig deeper to find more accurate color distances, e.g. by implementing some sort of a chromaticity diagram.

                                        Kind regards.

                                        Read and abide by the Qt Code of Conduct

                                        1 Reply Last reply
                                        4
                                        • P Payx
                                          26 Oct 2016, 22:18

                                          @SGaist said in Picture:

                                          QImage::pixelColor

                                          Ok, i will try to use it tomorrow, but i already have a question, i can't use a function in the "void MainWindow::on_push_clicked()" no ?

                                          J Offline
                                          J Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on 27 Oct 2016, 04:26 last edited by
                                          #20

                                          @Payx said in Picture:

                                          i can't use a function in the "void MainWindow::on_push_clicked()" no ?

                                          Sure you can, why not?

                                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          1 Reply Last reply
                                          1

                                          10/82

                                          24 Oct 2016, 20:14

                                          72 unread
                                          • Login

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