跳到內容
  • 版面
  • 最新
  • 標籤
  • 熱門
  • 使用者
  • 群組
  • 搜尋
  • Get Qt Extensions
  • Unsolved
Collapse
品牌標誌
  1. 首頁
  2. Qt Development
  3. General and Desktop
  4. Picture
Forum Updated to NodeBB v4.3 + New Features

Picture

已排程 已置頂 已鎖定 已移動 Solved General and Desktop
82 貼文 7 Posters 46.5k 瀏覽 3 Watching
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • P Payx

    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

    mrjjM 離線
    mrjjM 離線
    mrjj
    Lifetime Qt Champion
    寫於 最後由 編輯
    #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 條回覆 最後回覆
    1
    • mrjjM mrjj

      @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 離線
      P 離線
      Payx
      寫於 最後由 編輯
      #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 條回覆 最後回覆
      0
      • SGaistS 離線
        SGaistS 離線
        SGaist
        Lifetime Qt Champion
        寫於 最後由 編輯
        #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 條回覆 最後回覆
        1
        • SGaistS SGaist

          Hi,

          Why not use QImage::scaled ?

          P 離線
          P 離線
          Payx
          寫於 最後由 編輯
          #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 條回覆 最後回覆
          0
          • SGaistS 離線
            SGaistS 離線
            SGaist
            Lifetime Qt Champion
            寫於 最後由 編輯
            #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 條回覆 最後回覆
            0
            • SGaistS SGaist

              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 離線
              P 離線
              Payx
              寫於 最後由 編輯
              #10

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

              1 條回覆 最後回覆
              0
              • SGaistS SGaist

                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 離線
                P 離線
                Payx
                寫於 最後由 編輯
                #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 ?

                mrjjM 1 條回覆 最後回覆
                0
                • P Payx

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

                  mrjjM 離線
                  mrjjM 離線
                  mrjj
                  Lifetime Qt Champion
                  寫於 最後由 編輯
                  #12

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

                  P 1 條回覆 最後回覆
                  0
                  • SGaistS 離線
                    SGaistS 離線
                    SGaist
                    Lifetime Qt Champion
                    寫於 最後由 編輯
                    #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 條回覆 最後回覆
                    0
                    • mrjjM mrjj

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

                      P 離線
                      P 離線
                      Payx
                      寫於 最後由 編輯
                      #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

                      kshegunovK 1 條回覆 最後回覆
                      0
                      • SGaistS 離線
                        SGaistS 離線
                        SGaist
                        Lifetime Qt Champion
                        寫於 最後由 編輯
                        #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 條回覆 最後回覆
                        0
                        • SGaistS SGaist

                          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 離線
                          P 離線
                          Payx
                          寫於 最後由 編輯
                          #16

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

                          1 條回覆 最後回覆
                          0
                          • SGaistS 離線
                            SGaistS 離線
                            SGaist
                            Lifetime Qt Champion
                            寫於 最後由 編輯
                            #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 條回覆 最後回覆
                            1
                            • SGaistS SGaist

                              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 離線
                              P 離線
                              Payx
                              寫於 最後由 編輯
                              #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 ?

                              jsulmJ 1 條回覆 最後回覆
                              0
                              • P Payx

                                @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

                                kshegunovK 離線
                                kshegunovK 離線
                                kshegunov
                                Moderators
                                寫於 最後由 編輯
                                #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 條回覆 最後回覆
                                4
                                • P Payx

                                  @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 ?

                                  jsulmJ 離線
                                  jsulmJ 離線
                                  jsulm
                                  Lifetime Qt Champion
                                  寫於 最後由 編輯
                                  #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 條回覆 最後回覆
                                  1
                                  • P 離線
                                    P 離線
                                    Payx
                                    寫於 最後由 編輯
                                    #21

                                    I just dont understand what your program do..

                                    i got my image into my :

                                    void MainWindow::on_push_clicked()
                                    

                                    when i want to use it in :

                                    void MainWindow::on_push2_clicked()
                                    

                                    he say that my image isnt declared.

                                    @kshegunov sorry, I just dont understand what your program do..

                                    i thought use a thing like this :

                                    void MainWindow::on_push2_clicked()
                                       {
                                    
                                    
                                    
                                           for (int i=0;i<pix.width()+1;i=i+4){
                                               for (int j=0;j<pix.height()+1;j=j+4){
                                                   for(int x=0; x<i;x=x+1){
                                                      for (int z=0; z<j; z=z+1){
                                               
                                       }
                                    }
                                    }
                                    

                                    and in that i will calculate the most contained color ( i thought with RGB ) and if my square is contained by 80% of red, replace it with red.

                                    jsulmJ 1 條回覆 最後回覆
                                    0
                                    • P Payx

                                      I just dont understand what your program do..

                                      i got my image into my :

                                      void MainWindow::on_push_clicked()
                                      

                                      when i want to use it in :

                                      void MainWindow::on_push2_clicked()
                                      

                                      he say that my image isnt declared.

                                      @kshegunov sorry, I just dont understand what your program do..

                                      i thought use a thing like this :

                                      void MainWindow::on_push2_clicked()
                                         {
                                      
                                      
                                      
                                             for (int i=0;i<pix.width()+1;i=i+4){
                                                 for (int j=0;j<pix.height()+1;j=j+4){
                                                     for(int x=0; x<i;x=x+1){
                                                        for (int z=0; z<j; z=z+1){
                                                 
                                         }
                                      }
                                      }
                                      

                                      and in that i will calculate the most contained color ( i thought with RGB ) and if my square is contained by 80% of red, replace it with red.

                                      jsulmJ 離線
                                      jsulmJ 離線
                                      jsulm
                                      Lifetime Qt Champion
                                      寫於 最後由 編輯
                                      #22

                                      @Payx If you get your image in

                                      void MainWindow::on_push_clicked()
                                      

                                      and you need it in

                                      void MainWindow::on_push2_clicked()
                                      

                                      then in on_push_clicked() you need to store the image somewhere, so on_push2_clicked() can use it later. You can just add a member variable to MainWindow:

                                      class MainWindow...
                                      {
                                      ...
                                      private:
                                          QImage image;
                                      }

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

                                      P 1 條回覆 最後回覆
                                      3
                                      • jsulmJ jsulm

                                        @Payx If you get your image in

                                        void MainWindow::on_push_clicked()
                                        

                                        and you need it in

                                        void MainWindow::on_push2_clicked()
                                        

                                        then in on_push_clicked() you need to store the image somewhere, so on_push2_clicked() can use it later. You can just add a member variable to MainWindow:

                                        class MainWindow...
                                        {
                                        ...
                                        private:
                                            QImage image;
                                        }
                                        P 離線
                                        P 離線
                                        Payx
                                        寫於 最後由 編輯
                                        #23

                                        @jsulm ok thank you !

                                        For calculate the color of each pixel, what function can i use?

                                        jsulmJ 1 條回覆 最後回覆
                                        0
                                        • P Payx

                                          @jsulm ok thank you !

                                          For calculate the color of each pixel, what function can i use?

                                          jsulmJ 離線
                                          jsulmJ 離線
                                          jsulm
                                          Lifetime Qt Champion
                                          寫於 最後由 jsulm 編輯
                                          #24

                                          @Payx Do you mean to get the pixel value? http://doc.qt.io/qt-5/qimage.html#pixel-1
                                          It returns http://doc.qt.io/qt-5/qcolor.html#QRgb-typedef containing the RGB values, then you can calculate what ever you need.
                                          #AARRGGBB

                                          quint32 rgb = static_cast<quint32>(image.pixel(x, y));
                                          int blue = rgb & x000000FF;
                                          int green = (rgb & 0x0000FF00)>>8;
                                          int red = (rgb & 0x00FF0000)>>16;
                                          

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

                                          kshegunovK 1 條回覆 最後回覆
                                          2

                                          • 登入

                                          • Login or register to search.
                                          • 第一個貼文
                                            最後的貼文
                                          0
                                          • 版面
                                          • 最新
                                          • 標籤
                                          • 熱門
                                          • 使用者
                                          • 群組
                                          • 搜尋
                                          • Get Qt Extensions
                                          • Unsolved