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. QImage reduce color to nearest indexed palette
Forum Updated to NodeBB v4.3 + New Features

QImage reduce color to nearest indexed palette

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 5 Posters 7.3k Views 2 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.
  • Shadowblitz16S Shadowblitz16

    @kshegunov I see you didn't use the QImage.bits() method like i did can you explain why?

    kshegunovK Offline
    kshegunovK Offline
    kshegunov
    Moderators
    wrote on last edited by kshegunov
    #13

    QImage::bits returns internal data, thus it requires me to know what is the image's format and data padding (if any). Using the pixel modification API does not, on the other hand. Moreover, as this all boils down to interpolation in RGB space, having a color value represented in other color spaces isn't as useful, because the "finding closest" approximation requires a bit more work. For example if I used CMYK I'd have to use 4D color space, if I were to work in HSV I'd have to calculate distances in cylindrical coordinate system, which while possible makes it more complicated for no good reason.

    Read and abide by the Qt Code of Conduct

    1 Reply Last reply
    2
    • Shadowblitz16S Offline
      Shadowblitz16S Offline
      Shadowblitz16
      wrote on last edited by
      #14

      thankyou kshegunov however when I add an image and try to reduce its color by lowering the color count it doesn't do anything can you explain why?

      kshegunovK 1 Reply Last reply
      0
      • Shadowblitz16S Shadowblitz16

        thankyou kshegunov however when I add an image and try to reduce its color by lowering the color count it doesn't do anything can you explain why?

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #15

        You mean for my toy application?
        The color count should be a power of two, so 16, 32, 64, 128 are valid, but not say 3, 9, 11.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        0
        • Shadowblitz16S Offline
          Shadowblitz16S Offline
          Shadowblitz16
          wrote on last edited by
          #16

          oh I see why its called color reduction now...
          it doesn't index the image it just reduces the color..

          kshegunovK 1 Reply Last reply
          0
          • Shadowblitz16S Shadowblitz16

            oh I see why its called color reduction now...
            it doesn't index the image it just reduces the color..

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #17

            @Shadowblitz16 said in QImage reduce color to nearest indexed palette:

            it doesn't index the image it just reduces the color..

            I don't follow, what's the difference?
            An index-colored image is a table of colors (again 8, 16, 32 etc. in number) and instead of assigning RGB values directly to the pixels you assign them indices from that table. My toy app does the table, but instead of saving the table and using index-colored format it just uses the colors directly, but it's basically the same principle. If you open the image histogram you'll see only that number of colors that would otherwise be in the color table.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0
            • Shadowblitz16S Offline
              Shadowblitz16S Offline
              Shadowblitz16
              wrote on last edited by
              #18

              but it should round the colors to the nearest color on the palette if the palette size isn't big enough to hold all the colors.

              kshegunovK 1 Reply Last reply
              0
              • Shadowblitz16S Shadowblitz16

                but it should round the colors to the nearest color on the palette if the palette size isn't big enough to hold all the colors.

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by kshegunov
                #19

                It does - here

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                0
                • Shadowblitz16S Offline
                  Shadowblitz16S Offline
                  Shadowblitz16
                  wrote on last edited by Shadowblitz16
                  #20

                  hmm its not doing it for me.. for example I gave it an image and specified a palette size of 4.
                  after it was done processing it just recolored parts of the image..

                  EDIT: now it doesn't look like its doing anything.

                  EDIT2: ok so when I open the file browser to load an image, all my images are listed as paint.net images when they are not.
                  I think its getting the file extension confused with the default program that opens the file.

                  kshegunovK 1 Reply Last reply
                  0
                  • Shadowblitz16S Shadowblitz16

                    hmm its not doing it for me.. for example I gave it an image and specified a palette size of 4.
                    after it was done processing it just recolored parts of the image..

                    EDIT: now it doesn't look like its doing anything.

                    EDIT2: ok so when I open the file browser to load an image, all my images are listed as paint.net images when they are not.
                    I think its getting the file extension confused with the default program that opens the file.

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #21

                    @Shadowblitz16 said in QImage reduce color to nearest indexed palette:

                    hmm its not doing it for me.. for example I gave it an image and specified a palette size of 4.
                    after it was done processing it just recolored parts of the image..

                    What do you suppose an index based image is to look like?
                    Open any image, put it in photoshop, gimp or w/e make it index-based with a palette size of 4 and observe what happens.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    1
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #22

                      Hi
                      Unless you use Dithering, a palette of 4 color will destroy most images :)
                      ![alt text](0_1493897430493_upload-216d44af-ee00-457b-b63b-636f672371d1 image url)

                      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