Announcement

Collapse
No announcement yet.

How do I compare two images pixel by pixel? or list the RGB values for evey pixel?

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

    How do I compare two images pixel by pixel? or list the RGB values for evey pixel?

    I want to compare two images to be certain that each pixel in each image is identical. Or analyse one image to be certain that each pixel has values where R=G=B for every pixel.

    I am debugging a problem with a colour printer and I need to be certain that all pixels sent to the printer are definitely greyscale - ie the RGB is [27, 27, 27] (which will print using the black ink) and not, say, [27, 27, 28] (which will print using the coloured inks). I can capture the actual image being sent to the printer by printing to a PDF.

    The starting image is an IV greyscale image so has every pixel where R=G=B. The image gets processed by an application before being sent to the printer and I want to compare the image being sent to the printer with the original image to be certain that all pixels are still R=G=B.

    I cannot see a way to do this in IrfanView. Can anyone suggest a (preferably simple :-)) method? I googled for image analysis, list pixels in image etc, and didn't have much success.

    One way would be to write out the image as a list of pixels and their colour values (1: [27 27 27]; 2: [28 28 28]; ... etc) and examine the list in a spreadsheet. I thought I would find a simple utility to create the list of pixel values but I cannot.

    All help will be gratefully appreciated.
    Last edited by John_Ha; 16.06.2014, 08:46 AM. Reason: typo corrected

    #2
    You basically want to manipulate the image as a 2D matrix, element by element. The best (if not only) way to do this is in mathematics software, like matlab (look at scilab, octave, freemat for freeware options).

    Some basic programming skills will help. In matlab you could use these commands:
    X = imread('image.jpg');
    if (X(1,1,1) == X(1,1,2)) & (X(1,1,2) == X(1,1,3)), disp('Valid greyscale pixel'), end;

    Then e.g. do that comparison in two loops to address every pixel:
    for i = 1:size(X,1),
    for j = 1:size(X,2),
    if (X(i,j,1) == X(i,j,2)) & (X(i,j,2) == X(i,j,3)),
    disp('Valid greyscale pixel');
    count = count + 1;
    end;
    end;
    end;

    Comment


      #3
      ^Kudos. But perhaps the easiest way is the manual one: you just need an appropriate image, such as this or this, and then you can easily examine the output with e.g. Color Seizer or Pixeur. The problem is, if you find color deviation, it's likely caused by the PDF printer. You typically have rather limited control over its image handling; you can (and must in this case) disable lossy compression, but that's still no guarantee. I'm using and old version of Foxit PDF creator and after testing now I can tell you that pixel color values are not identical to the source image.
      If your ultimate goal is to ensure grayscale printing, every printer driver I've used had the option of printing color images as grayscale - doesn't yours, John? By checking that option you could make certain that the image sent to the printer is grayscale, unless the driver itself is buggy.

      Comment


        #4
        export image RGB values to CSV / text / excel table using irfanview

        It kept bugging me. There must be a simpler way for non-programmers - and there is!

        1. Use Irfanview to "save as" PPM (portable pixelmap) file and select ascii encoding ("show options dialog" checkbox must be checked).
        2. Open a new workbook in excel, go to data ribbon, click "From Text", and open your PPM file (change dropdown from "Text files..." to "All files..." to be able to see your .ppm file)
        3. Text import wizard step 1: choose "delimited", import from row 5, and file origin ??? (doesn't seem to matter, probably default or "windows (ANSI)" or "US-ASCII")
        4. Text import wizard step 2: choose only "space" as delimiter, you can also play with the "treat consecutive delimiters as one" setting - I don't think this should matter but could for large images
        5. Text import wizard step 3: data format "General" and finish
        6. Place at $A$1 in the "Import data" pop-up box (FYI also look at the "properties" button)

        The data should now be in the format R G B R G B R G B R G B, pixel by pixel, ordered left to right then top to bottom, and ~5 pixels per excel row.
        You can then use standard excel tricks and formulas to format and shape the data in the way you prefer. E.g. use "=IF(AND(A1 = A2, A2 = A3),0,1)" to detect invalid greyscale values.

        Note this method will best work for relatively small images. Large images will generate huge tables, which will be slow to process and require at least Excel 2007 or newer (which still only allows ~1048573 rows to be imported from a PPM file. This limit equates to max ~5 megapixel images, or about 2289x2289 for square images).

        Comment


          #5
          As Gownaar said, the PDF printer may actually interfere with your analysis. Also look at FinePrint as a intermediate print-file capturer.

          FinePrint is awesome. About the first thing I install on a new computer, after IrfanView of course .

          Comment


            #6
            You are truly a master of simplicity. But kudos once again.

            @John_Ha: I just wanted to add that if you have reason to suspect a specific invalid color is appearing, in IV you can make it visually easily distinguishable with Image->Replace Color, e.g. 27,27,28 to 255,0,255 (tolerance=0).

            Comment


              #7
              If you convert a colored image to Grayscale in Irfanview , you can look at the palette. (Image> Palette> Edit palette). It will normally show all 256 levels of grayscale from 0,0,0 to 255,255,255. The Image information will also show the number of unique colors as 256. (Image> Information).
              You can also Export the palette as a .pal file. (Image> Palette > Export palette). The .pal file is a text file that you can open with Notepad and see the list of R,G,B values.

              Some processes in Irfanview will introduce colors. The number of unique colors will show as greater then 256 and you will no longer be able to look at the palette.
              If you can still view the palette then you can also Export it again and compare the list of R,G,B colors with what you had before.

              Comment


                #8
                I do apologise for my not replying earlier to this post - I have been having PC problems (as will be seen from my most recent post!).

                Thank you for the suggestions. It turned out that the printer was faulty. I hadn't realised that colour inkjets print a tiny bit of colour even when printing in B&W to keep the colour jets clear, and this seemed to have got out of hand!

                However, your suggestions are still very welcome as I have often wanted to analyse images at the pixel level and, whereas doing so for a few pixels is simple, doing so for a whole image is rather more difficult. Listing pixel values is very convenient.

                I had wondered if there was a "subtract this image from that" capability; or a "find the pixels which are different in these two images".

                As to the "produce the PDF process", I have tripped across those problems before. I use OpenOffice to produce a magazine, and have up till now been leaving the images at full pixel count in the OO file, and relying on OpenOffice to resample them down to the printer resolution, and saving the PDF as lossless. I discovered that IV resampling (Lanczos, don't tick Use fastest resample) gives a significantly better quality image with far fewer artefacts than OpenOffice.

                Comment

                Working...
                X