OpenCV strip sRGB profile when imdecode image Python

拥有回忆 提交于 2019-12-11 09:03:19

问题


I am reading in images which I fetch from the internet and then immediately read into OpenCV in python as below:

# read in image as bytes from page
image = page.raw_stream.read()
frame = cv2.imdecode(np.asarray(bytearray(image)), 0)

and I am getting the libpng warning:

libpng warning: iCCP: known incorrect sRGB profile

How can I strip the sRGB profile before imread? People are suggesting to do it via imagemagick on the png files before reading them but this is not possible for me. Is there no way to do this in python directly?

EDIT:

I am unable to get the code in the answer below to fix my problem, if I run it with the file at https://uploadfiles.io/m1w2l and use the code:

import cv2
import numpy as np

with open('data/47.png', 'rb') as test:
   image = np.asarray(bytearray(test.read()), dtype="uint8")
   image = cv2.imdecode(image, cv2.IMREAD_COLOR)

I get the same warning


回答1:


Using urllib:

import cv2
import urllib

resp = urllib.request.urlopen('https://i.imgur.com/QMPkIkZ.png')
image = np.asarray(bytearray(resp.read()), dtype="uint8")
image = cv2.imdecode(image, cv2.IMREAD_COLOR)

Using skimage:

import cv2
from skimage import io

image = io.imread('https://i.imgur.com/QMPkIkZ.png')
image = cv2.cvtColor(image, cv2.COLOR_RGBA2BGRA)

If you get a weird display using OpenCV cv2.imshow, keep in mind that OpenCV does not display alpha channels.



来源:https://stackoverflow.com/questions/50528389/opencv-strip-srgb-profile-when-imdecode-image-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!