Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading pgm images with cv2 in python

Tags:

python

opencv

pgm

I want to read pgm image in python. I use cv2.imread('a.pgm') but it returns wrong results. In Matlab, I use imread and get the right result which is a single channel 16-bit image. But cv2.imread in python returns a 3-channel image and the pixel values are also wrong. Why it happens? How should I read the 16-bit pgm images in python? And what libraries?

Thanks in advance.

like image 389
Liang Xiao Avatar asked Apr 05 '16 08:04

Liang Xiao


2 Answers

I got it.

cv2.imread('a.pgm',-1) 

works.

like image 140
Liang Xiao Avatar answered Sep 20 '22 23:09

Liang Xiao


You can also use skimage.io library

from skimage.io import imread
image = imread("a.pgm")
like image 42
burhan rashid Avatar answered Sep 17 '22 23:09

burhan rashid