Artifacts from PNG files


I’m seeing strange artifacts when using imread and imshow from PNG files.

If I load a JPEG image it is displayed correctly. However, even if I convert the correctly displayed JPEG image to PNG (using Photoshop for example), I get a very distorted image when loaded using OpenCV.

This a JPEG image exported as PNG (used Photoshop’s “Quick Export as PNG”) and displayed using OpenCV:

Screenshot 2021-09-01 at 15.13.27_png

Any ideas what could be the cause here? This happens with every PNG file I try to load.

I did build the OpenCV lib myself – could this be caused by wrong build settings?


(OpenCV (4.5.2), macOS 11.5.2)

jpeg artefacts dont go away, if you save it as png.
once they’re in, its too late.
(even if you dont see them immediately)

definitely not. its not even related to opencv

Thanks, berak,

But there are no artifacts in the JPEG version. This is how a JPEG looks like:

Screenshot 2021-09-01 at 15.13.27

post a minimal reproducible example. post the data that causes this (no screenshots, the data).

I suspect that you’re messing with the data itself, corrupting the file, but you aren’t showing what you did.

PNG ordinarily can’t cause what you showed. it’s lossless.

apologies, i did not see the 1st screenshot.
those are definitely not jpg artefacts.

i’d assume, that Photoshop’s “Quick Export as PNG” thing is doing something creative there

also, what are those images you show us ? screenshots of a window showing an image ? cmon …

This is a screenshot of what OpenCV’s imshow outputs. The same PNG is displayed correctly if I open it with Preview or Photoshop, so there is no other way to clearly illustrate the problem.

I’ll share a minimal reproducible example soon.

While working on a reproducible example I figured out the cause of the issue. My project uses wxWidgets for UI, which for some reason was affecting how OpenCV handles PNG files. Specifically, if I link to “-lwxpng-3.1” then the PNG corruption appears. If I remove it then the PNG files are displayed correctly.

Since my project is not compiling without “-lwxpng-3.1”, I discovered that if I link to OpenCV’s libraries first and wxWidgets’ libraries second, then the PNG issue is resolved.