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