Mobile app version of vmapp.org
Login or Join
Deb5748823

: GIMP changes png on opening 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

@Deb5748823

Posted in: #Gimp #Png

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:



photoshop crop png file (no compression)



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



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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Deb5748823

1 Comments

Sorted by latest first Latest Oldest Best

 

@Caterina889

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:


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.
ICC profile
Similar issues as with gamma correction. Should not be relevant, since you do not use color management.
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:

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).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme