pgm

Numpy and 16-bit PGM

ⅰ亾dé卋堺 提交于 2019-11-27 13:40:11
What is an efficient and clear way to read 16-bit PGM images in Python with numpy? I cannot use PIL to load 16-bit PGM images due to a PIL bug . I can read in the header with the following code: dt = np.dtype([('type', 'a2'), ('space_0', 'a1', ), ('x', 'a3', ), ('space_1', 'a1', ), ('y', 'a3', ), ('space_2', 'a1', ), ('maxval', 'a5')]) header = np.fromfile( 'img.pgm', dtype=dt ) print header This prints the correct data: ('P5', ' ', '640', ' ', '480', ' ', '65535') But I have a feeling that is not quite the best way. And beyond that, I'm having trouble how to figure out how to read in the

How to read a .pgm image file in a 2D double array in C

混江龙づ霸主 提交于 2019-11-27 07:32:31
问题 The question is quite simple: How to read a .pgm image file into a 2D double array in C. I do not have a .pgm buffer in memory. I would like to read it from the disk into memory. Would really appreciate if I could get a code snippet. Thank You. 回答1: You probably won't get someone writing you all the code, but here are some useful links that might point you in the right direction: pgm.c pgm.h PGM Format Specification http://www.cplusplus.com/forum/general/2393/ 回答2: If its saved as ASCII you

Numpy and 16-bit PGM

不打扰是莪最后的温柔 提交于 2019-11-26 16:26:47
问题 What is an efficient and clear way to read 16-bit PGM images in Python with numpy? I cannot use PIL to load 16-bit PGM images due to a PIL bug. I can read in the header with the following code: dt = np.dtype([('type', 'a2'), ('space_0', 'a1', ), ('x', 'a3', ), ('space_1', 'a1', ), ('y', 'a3', ), ('space_2', 'a1', ), ('maxval', 'a5')]) header = np.fromfile( 'img.pgm', dtype=dt ) print header This prints the correct data: ('P5', ' ', '640', ' ', '480', ' ', '65535') But I have a feeling that is