本文整理汇总了Python中png.Reader方法的典型用法代码示例。如果您正苦于以下问题:Python png.Reader方法的具体用法?Python png.Reader怎么用?Python png.Reader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类png
的用法示例。
在下文中一共展示了png.Reader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: flow_read_png
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def flow_read_png(fpath):
"""
Read KITTI optical flow, returns u,v,valid mask
"""
if not has_png:
print('Error. Please install the PyPNG library')
return
R = png.Reader(fpath)
width,height,data,_ = R.asDirect()
# This only worked with python2.
#I = np.array(map(lambda x:x,data)).reshape((height,width,3))
I = np.array([x for x in data]).reshape((height,width,3))
u_ = I[:,:,0]
v_ = I[:,:,1]
valid = I[:,:,2]
u = (u_.astype('float64')-2**15)/64.0
v = (v_.astype('float64')-2**15)/64.0
return u,v,valid
示例2: load_png
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def load_png(file_path):
"""
Read from KITTI .png file
Args:
file_path string: file path(absolute)
Returns:
data (numpy.array): data of image in (Height, Width, 3) layout
"""
flow_object = png.Reader(filename=file_path)
flow_direct = flow_object.asDirect()
flow_data = list(flow_direct[2])
(w, h) = flow_direct[3]['size']
flow = np.zeros((h, w, 3), dtype=np.float64)
for i in range(len(flow_data)):
flow[i, :, 0] = flow_data[i][0::3]
flow[i, :, 1] = flow_data[i][1::3]
flow[i, :, 2] = flow_data[i][2::3]
invalid_idx = (flow[:, :, 2] == 0)
flow[:, :, 0:2] = (flow[:, :, 0:2] - 2 ** 15) / 64.0
flow[invalid_idx, 0] = 0
flow[invalid_idx, 1] = 0
return flow.astype(np.float32)
示例3: read_disp_png
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def read_disp_png(file_name):
"""
Read optical flow from KITTI .png file
:param file_name: name of the flow file
:return: optical flow data in matrix
"""
image_object = png.Reader(filename=file_name)
image_direct = image_object.asDirect()
image_data = list(image_direct[2])
(w, h) = image_direct[3]['size']
channel = len(image_data[0]) / w
flow = np.zeros((h, w, channel), dtype=np.uint16)
for i in range(len(image_data)):
for j in range(channel):
flow[i, :, j] = image_data[i][j::channel]
return flow[:, :, 0] / 256
示例4: read_png_file
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def read_png_file(flow_file):
"""
Read from KITTI .png file
:param flow_file: name of the flow file
:return: optical flow data in matrix
"""
flow_object = png.Reader(filename=flow_file)
flow_direct = flow_object.asDirect()
flow_data = list(flow_direct[2])
(w, h) = flow_direct[3]['size']
print("Reading %d x %d flow file in .png format" % (h, w))
flow = np.zeros((h, w, 3), dtype=np.float64)
for i in range(len(flow_data)):
flow[i, :, 0] = flow_data[i][0::3]
flow[i, :, 1] = flow_data[i][1::3]
flow[i, :, 2] = flow_data[i][2::3]
invalid_idx = (flow[:, :, 2] == 0)
flow[:, :, 0:2] = (flow[:, :, 0:2] - 2 ** 15) / 64.0
flow[invalid_idx, 0] = 0
flow[invalid_idx, 1] = 0
return flow
示例5: read_flow_png
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def read_flow_png(flow_file):
"""
Read optical flow from KITTI .png file
:param flow_file: name of the flow file
:return: optical flow data in matrix
"""
flow_object = png.Reader(filename=flow_file)
flow_direct = flow_object.asDirect()
flow_data = list(flow_direct[2])
(w, h) = flow_direct[3]['size']
flow = np.zeros((h, w, 3), dtype=np.float64)
for i in range(len(flow_data)):
flow[i, :, 0] = flow_data[i][0::3]
flow[i, :, 1] = flow_data[i][1::3]
flow[i, :, 2] = flow_data[i][2::3]
invalid_idx = (flow[:, :, 2] == 0)
flow[:, :, 0:2] = (flow[:, :, 0:2] - 2 ** 15) / 64.0
flow[invalid_idx, 0] = 0
flow[invalid_idx, 1] = 0
return flow
开发者ID:ChenyangLEI,项目名称:Fully-Automatic-Video-Colorization-with-Self-Regularization-and-Diversity,代码行数:23,代码来源:myflowlib.py
示例6: accept
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def accept(self, path, ext, operator):
if operator == "resize":
return 'NG'
elif operator == "save":
return 'OK'
else:
if ext == '.png':
f = path if hasattr(path, "read") else open(path, "rb")
r = png.Reader(file=f)
width, height, pixels, metadata = r.asDirect()
f.seek(0)
bit_depth = metadata.get("bitdepth")
if bit_depth not in [8, 16]:
return "NG"
else:
return "Recommended"
else:
return "NG"
示例7: load_images
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def load_images(path, ID):
"""
Load a color and a depth image by path and image ID
"""
global camera_intrinsics
img_file = path + 'JPEGImages/%s.jpg' % (ID*LABEL_INTERVAL)
cad = cv2.imread(img_file)
depth_file = path + 'depth/%s.png' % (ID*LABEL_INTERVAL)
reader = png.Reader(depth_file)
pngdata = reader.read()
# depth = np.vstack(map(np.uint16, pngdata[2]))
depth = np.array(tuple(map(np.uint16, pngdata[2])))
pointcloud = convert_depth_frame_to_pointcloud(depth, camera_intrinsics)
return (cad, pointcloud)
示例8: read_png_file
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def read_png_file(flow_file):
"""
Read from KITTI .png file
:param flow_file: name of the flow file
:return: optical flow data in matrix
"""
flow_object = png.Reader(filename=flow_file)
flow_direct = flow_object.asDirect()
flow_data = list(flow_direct[2])
(w, h) = flow_direct[3]['size']
print "Reading %d x %d flow file in .png format" % (h, w)
flow = np.zeros((h, w, 3), dtype=np.float64)
for i in range(len(flow_data)):
flow[i, :, 0] = flow_data[i][0::3]
flow[i, :, 1] = flow_data[i][1::3]
flow[i, :, 2] = flow_data[i][2::3]
invalid_idx = (flow[:, :, 2] == 0)
flow[:, :, 0:2] = (flow[:, :, 0:2] - 2 ** 15) / 64.0
flow[invalid_idx, 0] = 0
flow[invalid_idx, 1] = 0
return flow
示例9: read_png_flow
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def read_png_flow(flow_file):
flow_object = png.Reader(filename=flow_file)
flow_direct = flow_object.asDirect()
flow_data = list(flow_direct[2])
(w, h) = flow_direct[3]['size']
flow = np.zeros((h, w, 3), dtype=np.float64)
for i in range(len(flow_data)):
flow[i, :, 0] = flow_data[i][0::3]
flow[i, :, 1] = flow_data[i][1::3]
flow[i, :, 2] = flow_data[i][2::3]
invalid_idx = (flow[:, :, 2] == 0)
flow[:, :, 0:2] = (flow[:, :, 0:2] - 2 ** 15) / 64.0
flow[invalid_idx, 0] = 0
flow[invalid_idx, 1] = 0
return flow[:, :, 0:2], (1 - invalid_idx * 1)[:, :, None]
示例10: load_depth
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def load_depth(path):
# PyPNG library is used since it allows to save 16-bit PNG
r = png.Reader(filename=path)
im = np.vstack(map(np.uint16, r.asDirect()[2])).astype(np.float32)
# itertools.imap is removed in py3
return im
示例11: load_depth
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def load_depth(path):
# PyPNG library is used since it allows to save 16-bit PNG
r = png.Reader(filename=path)
im = np.vstack(itertools.imap(np.uint16, r.asDirect()[2])).astype(np.float32)
return im
示例12: load
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def load(image, filename):
"""load a PNG file"""
reader = png.Reader(filename=filename)
image.width, image.height, pixels, _ = reader.asRGBA8()
image.pixels = Image.create_array(image.width, image.height)
index = 0
for row in pixels:
for r, g, b, α in zip(row[::4], row[1::4], row[2::4], row[3::4]):
image.pixels[index] = Image.color_for_argb(α, r, g, b)
index += 1
示例13: load_im
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def load_im(path):
im = scipy.misc.imread(path)
# Using PyPNG
# r = png.Reader(filename=path)
# im = np.vstack(itertools.imap(np.uint8, r.asDirect()[2]))
return im
示例14: read_png_file
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def read_png_file(filepath):
data = png.Reader(filename=filepath).asRGBA8()
width = data[0]
height = data[1]
rows = list(data[2])
return width, height, rows
示例15: open_flow_png_file
# 需要导入模块: import png [as 别名]
# 或者: from png import Reader [as 别名]
def open_flow_png_file(file_path_list):
# Funtion from Kilian Merkelbach.
# Decode the information stored in the filename
flow_png_info = {}
assert len(file_path_list) == 2
for file_path in file_path_list:
file_token_list = os.path.splitext(file_path)[0].split("_")
minimal_value = int(file_token_list[-1].replace("minimal", ""))
flow_axis = file_token_list[-2]
flow_png_info[flow_axis] = {'path': file_path,
'minimal_value': minimal_value}
# Open both files and add back the minimal value
for axis, flow_info in flow_png_info.items():
import png
png_reader = png.Reader(filename=flow_info['path'])
flow_2d = np.vstack(map(np.uint16, png_reader.asDirect()[2]))
# Add the minimal value back
flow_2d = flow_2d.astype(np.int16) + flow_info['minimal_value']
flow_png_info[axis]['flow'] = flow_2d
# Combine the flows
flow_x = flow_png_info['x']['flow']
flow_y = flow_png_info['y']['flow']
flow = np.stack([flow_x, flow_y], 2)
return flow