Announcement

Collapse
No announcement yet.

Import palette - use nearest color

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Import palette - use nearest color

    I am trying to import 16col palette using Irfanview 4.33.
    Setting for nearest color doesn't seem to work as results are the same as when this setting s off. For example the palette contains white color but it white doesn't stay as white after import, tried different file formats.



    Code:
    JASC-PAL
    0100
    16
    0 0 0
    128 0 0
    0 128 0
    128 128 0
    0 0 128
    128 0 128
    0 128 128
    128 128 128
    192 192 192
    255 0 0
    0 255 0
    255 255 0
    0 0 255
    255 0 255
    0 255 255
    255 255 255
    Last edited by Oto; 24.08.2012, 06:38 PM.

    #2
    It all appears correct to me. I created a 16 color palette identical with the one you have listed above. If I open any image, reduce it to 16 colors and import the palette then the colors in the image all change correctly to those in the palette, and the white in the image and in the palette are exactly the same. I even tried importing the palette to a 256 color image and then an 8 color image. Both accepted the 16 bit imported palette and the colors in the image become those in the palette. White was still pure white, black was still pure black.

    I think you had better explain in more detail what you are doing. I cannot understand what you mean by "setting for nearest color" for example or what are the "results" that you expect to be the same as something else.

    Comment


      #3
      OK. I think I have guessed what this is about. The clue is in the title. You expected that the colors that exist in the original image would be converted to the "nearest" color in the palette that is being imported?

      In fact I think that what you expected would be quite useful, but sadly it is not what actually happens. AFAIK the image is converted where necessary to have the right number of colors in the palette without any regard to what is in the import palette. Then the colors are just replaced one for one in the same order as they happen to be in their respective palettes.

      I notice now that you can even choose to import a palette directly into a 24bit truecolor image such as you get from a jpeg file. It is quite difficult to see why you might want to do that given the way Irfanview actually works.

      Comment


        #4
        I read in Irfanview Help:
        Import palette
        A dialog asks you for a PAL file (Paint Shop Pro palette). The palette will be applied to the image.

        See also Properties, Browsing/Editing if you want to apply original palette 1:1 or look for nearest color.

        Import palette: by default, the image colors will be changed 1:1 to colors in the PAL file, this option[Use nearest color] will search for the best/nearest color in the PAL file.

        Changelog:
        Version 4.10 (Release date: 2007-10-15)
        - New option for Import palette: Use nearest color (Properties->Misc 3)
        I tried setting this on and off and still no changes. It is on by default.

        original
        Click image for larger version

Name:	irfanview-icon.png
Views:	1
Size:	24.6 KB
ID:	80819
        Result of 16col pal import nearest on/off
        Click image for larger version

Name:	irfanview-icon_16col.png
Views:	1
Size:	3.3 KB
ID:	80820
        White background turned green, no near at all.

        Click image for larger version

Name:	irfanview_nearest_pal.png
Views:	1
Size:	116.0 KB
ID:	80821

        Comment


          #5
          OK, Oto. I have to admit that I had no idea that option existed in Properties, Browsing/Editing. Having now tried it I can confirm that it does not work.

          I tried it first by importing your palette directly into a jpeg image with the option checked and then unchecked. As you say no difference whatever is selected.

          To be certain though, I then reduced the color depth of the jpeg to 16 colors using the feature in the Edit menu and saved the image as a 16 color PNG. I chose an image with near blacks and whites and not much color. The various whites were all converted to one near white color as I expected (RGB 231, 241, 228) at index no 7 in the palette. I then imported the palette with the option in Browsing/Editing checked and the whites all ,became the blue/green color at index 7 in your palette. I then repeated that operation with the option unchecked and the result is exactly the same. Again the whites are replaced by the blue/green color at index 7. I pasted a copy of the palette in use for each of the steps in the panorama below.

          I think that is pretty conclusive but I will wait a few days for others to have a look if they wish before reporting it to Irfan.

          Click image for larger version

Name:	Importing palettes.jpg
Views:	1
Size:	503.9 KB
ID:	80822

          Comment


            #6
            Did I understand correctly that you will report this bug to Irfan on my behalf?
            Thanks

            Comment


              #7
              Yes. I contacted him and he has replied. It seems that the "nearest color" option only works for 256 color palettes. The only way he can suggest is that you import a 256 color palette and then reduce color depth to 16 colors.
              I gave it a try and it seemed to work.
              I extended your palette to 256 colors by adding 240 black ones on the end and then imported it into my "City hall" image with the option checked and the result was roughly as I expected it should be. Reducing to 16 colors did not affect the appearance although I notice that only 11 of your original colors were now included in the palette.

              Anyway, give it a try for yourself.

              Click image for larger version

Name:	City hall.png
Views:	1
Size:	234.1 KB
ID:	80824

              Palette extended.txt

              Comment


                #8
                Thanks. Works better now. Only it makes some pictures greyish(grayscale) as doesn't choose nearest color but chooses gray or black in its place.

                Click image for larger version

Name:	down.php?i=upasizq&n=irfan_16pal.png
Views:	1
Size:	2.5 KB
ID:	80826

                Comment


                  #9
                  I suppose it might be argued that the lighter reds around 246,151,151 are nearer to 192,192,192 than to 255,0,0
                  Including 255,128,128 as well as 255,0,0 in the palette produces a better result.

                  There are other issues related to decreasing color depth that I spotted while looking at your problem and I have told Irfan about those too. Whether he will consider them important enough to do anything about them, I cannot say. I suspect there will always have to be compromises in doing a color reduction like this.

                  Comment


                    #10
                    Irfan has now changed the code so that "Import palette" will now work in 16 color as well as 256 color mode. It will appear in the next issue, or if you cannot wait, send me a private message and I will send you his link to the modified test version.

                    However I should warn you that it is not easy to reduce color depth to 16 colors using this method. The "Nearest color" is often not the one you expect it to be when there is such a small palette to choose from.

                    Comment


                      #11
                      Euclidian distance is a mess for small color sets in RGB. HSV dithers are working much better.

                      Comment


                        #12
                        Just to make it clear, with Irfan's new version the Nearest-color option in the Import palette function does appear to work reasonably well when converting from one palette to another. However Irfanview also allows you to apply the Import palette function to a 24 bit color image that does not have a palette. That is when I came across some problems, even when the original image contained only a small number of colors.

                        Irfan explained that ".....the Nearest-color feature is from Windows ... it is pretty simple: the function gets the palette (that you import) and a color (from the old palette) as input. Then it tries to find the best matching color in the new palette."

                        That makes me suspect that when converting from a 24 bit color image, Irfan probably applies the Decrease color depth function first to create an image with a palette of the correct size and then applies Import palette using Nearest-color to complete the process.

                        We have discussed the shortcomings of Decrease color depth previously with particular reference to the case when the function is applied to a 24bit image to change it to a GIF image format. Users have complained that although the 24 bit image contained the same number or fewer colors than are required for the GIF palette, those colors are changed quite appreciably, even though there is clearly no need for any color changes to be made in this case. So I imagine that the problems I saw when applying Import palette to a 24 bit image are probably just another product of the Decrease color depth issue.

                        Irfan said that he does have it in mind to add options for alternative methods that can be used for Decrease color depth (I have been pressing him to include the Xiaolin Wu filter), but that it is well down a very long list of things he has to do.

                        Comment


                          #13
                          Originally posted by Mij View Post
                          Irfan said that he does have it in mind to add options for alternative methods that can be used for Decrease color depth (I have been pressing him to include the Xiaolin Wu filter), but that it is well down a very long list of things he has to do.
                          I always wanted to give Wu a try. Still using Octree to do the quantization.

                          Comment

                          Working...
                          X