2

I have been using photoshop to cut out small parts of screenshots. I then use python OpenCV to test whether those suqares that I cut out can be found somewhere in the original screenshot.

With photoshop they can be found with a 100% match, which is expected, but when I save the png with GIMP he cannot find them. Does GIMP somehow alter the png files on opening? I have no color management or anything else activated. What could be the reason why gimp seems to alter my files when they are opened?

UPDATE: Here are the the files. I cropped part of the original file in photoshop and in gimp and it becomes evident very quickly that the gimp file is much smaller.

original:

enter image description here

photoshop crop png file (no compression)

enter image description here

gimp crop png file of similar position (original settings but compression to 0)

enter image description here

I have to admit that I'm unable to reproduce the problem I had before. Both crops can now be matched back to the original. In my original problem the images were much smaller, so any changes would have a much larger effect. So I'm still interested if anybody can see if there's a fundamental difference in these two crops.

  • What do you mean by "when I save the png with GIMP he cannot find them"? If you open a PNG in Gimp and then try to save it, it will save it as an XFC file, which is Gimp's native format. To save a PNG in Gimp, you need to use Export instead. – Scribblemacher Sep 26 '16 at 11:51
  • Can you attach sample files? – Michael Schumacher Sep 26 '16 at 13:16
  • 1
    To clarify: I open the png of a screenshot I took, then export part of it (a cropped part) as another png. When I have a python script checking if my newly cropped png is part of the original it says no, there is no perfect match – Nickpick Sep 26 '16 at 13:17
  • Thanks for the images. I updated my post. May I ask how you created the screenshot? Neither my Windows nor my Linux embed color profiles into the screenshots. – Socowi Sep 30 '16 at 17:29
3

I do not think that Gimp alters the image on import*. The problem is more likely related to the PNG export. I see the following possibilites:

  1. Gamma correction
    PNGs can contain a gamma factor which is not taken into account by every application (see also this question). You can set/unset the checkbox »save gamma« in Gimp's PNG export dialog and see whether your script behaves differently.

  2. ICC profile
    Similar issues as with gamma correction. Should not be relevant, since you do not use color management.

  3. Color value of tranparent pixels
    If parts of the image are fully transparent (for instance, if you made a screenshot of just one window) then the issue could be related to the transparent pixels.

    3.1 Color of full transparent pixels
    Gimp's PNG export offers the option »save color values from transparent pixels«. Assume you have the color channels (r,g,b,a) where a is the alpha channel and a=0 means fully transparent. To the viewer it does not matter whether a pixel has the value (1,2,3,0) or (4,5,6,0) – the pixel appears to be fully transparent – but your script may think that (1,2,3,0) ≠ (4,5,6,0).

    3.2 Background Color
    If your script does not use a alpha channel for comparison, OpenCV may replace (half)transparent pixels with the background color stored in the PNG. If Gimp stores another background color than photoshop, the non-transparent versions of Gimp's and photoshop's PNGs will differ. Set/unset the checkbox »save background color« in Gimp's PNG export dialog or change the background color in Gimp's main window.

Let's have a look at the actual files:

The original and the photoshop version have the same properties:

  • 8-bit RGB channels
  • no alpha channel
  • background color white
  • embedded color profile »IEC 61966-2.1 Default RGB colour space - sRGB« (!)

The gimp version differs for the following properties:

  • 1 bit alpha channel
  • no color profile

I am baffled by the fact, that gimp does not ask me to convert the image using the embeded profile as it usually does for images with embeded color profiles.

* You can check whether Gimp alters the image on import by exporting to a simpler file format instead of PNG. »Portable Pixmap« (PPM) would be very good, since PPM does not have different modes or additional data fields.

Edit: Apparently, PPM also has different modes. Try to store the images as ASCII-PPMs and make sure to use the same resolution per sample (for instance 0-255). Until now, I only found one image file format which is always encoded the same: farbfeld. Unfortunately, it is not supported; neither by photoshop, nor by Gimp.

Edit 2: For small images without transparency, instead of using any Gimp export at all, you could also zoom 1:1 and make a screenshot of Gimp. Then crop the screenshot in Photoshop and run your script.

Edit 3:

I cannot use photoshop and am looking for a free picture editing program that does not distort the images the way gimp does

There are plenty of free gimp/photoshop alternatives. You just have to try them. I did not want to install additional software, but I tried using GraphicsMagick (a console program). GraphicsMagick used the original format for saving the result.

The following command extracts a 60x60 patch at position x=222 and y=33.

convert -crop 60x60+222+33 screenshot.png crop.png

crop.png looks like this: GraphicsMagick crop

Since cropping on the console might be bit cumbersome, you can use GraphicMagick's rudementary GUI. Type display screenshot.png into the console. The image will be displayed. Click on the image. A menu will appear. Click Transform > Crop, draw a rectangle, and hit enter. Save the result.

This answer recommended a specialized cropping tool, build upon ImageMagick (which probably will preserve the original format too).

  • Added sample images – Nickpick Sep 29 '16 at 20:03
  • The problem is that I cannot use photoshop and am looking for a free picture editing program that does not distort the images the way gimp does. I also need to use png as this is the format the software requires for which I create the images. – Nickpick Oct 18 '16 at 18:22
  • @nickpick I updated the answer. See Edit 3. – Socowi Oct 18 '16 at 22:09
  • Thanks, ideally we can notify gimp so they can fix this bug – Nickpick Oct 19 '16 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.