本文整理汇总了Python中Imath.PixelType方法的典型用法代码示例。如果您正苦于以下问题:Python Imath.PixelType方法的具体用法?Python Imath.PixelType怎么用?Python Imath.PixelType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Imath
的用法示例。
在下文中一共展示了Imath.PixelType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: extract_grayscale
# 需要导入模块: import Imath [as 别名]
# 或者: from Imath import PixelType [as 别名]
def extract_grayscale(img, srgb=False):
dw = img.header()['dataWindow']
size = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)
precision = Imath.PixelType(Imath.PixelType.FLOAT)
R = img.channel('R', precision)
G = img.channel('G', precision)
B = img.channel('B', precision)
r = np.fromstring(R, dtype = np.float32)
g = np.fromstring(G, dtype = np.float32)
b = np.fromstring(B, dtype = np.float32)
r.shape = (size[1], size[0])
g.shape = (size[1], size[0])
b.shape = (size[1], size[0])
rgb = cv2.merge([b, g, r])
grayscale = cv2.cvtColor(rgb, cv2.COLOR_BGR2GRAY)
if srgb:
grayscale = lin2srgb(grayscale)
return grayscale
示例2: load_hdr_as_tensor
# 需要导入模块: import Imath [as 别名]
# 或者: from Imath import PixelType [as 别名]
def load_hdr_as_tensor(img_path):
"""Converts OpenEXR image to torch float tensor."""
# Read OpenEXR file
if not OpenEXR.isOpenExrFile(img_path):
raise ValueError(f'Image {img_path} is not a valid OpenEXR file')
src = OpenEXR.InputFile(img_path)
pixel_type = Imath.PixelType(Imath.PixelType.FLOAT)
dw = src.header()['dataWindow']
size = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)
# Read into tensor
tensor = torch.zeros((3, size[1], size[0]))
for i, c in enumerate('RGB'):
rgb32f = np.fromstring(src.channel(c, pixel_type), dtype=np.float32)
tensor[i, :, :] = torch.from_numpy(rgb32f.reshape(size[1], size[0]))
return tensor
示例3: exr_to_png
# 需要导入模块: import Imath [as 别名]
# 或者: from Imath import PixelType [as 别名]
def exr_to_png(exr_path):
depth_path = exr_path.replace('.png0001.exr', '.png')
exr_image = OpenEXR.InputFile(exr_path)
dw = exr_image.header()['dataWindow']
(width, height) = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)
def read_exr(s, width, height):
mat = np.fromstring(s, dtype=np.float32)
mat = mat.reshape(height, width)
return mat
dmap, _, _ = [read_exr(s, width, height) for s in exr_image.channels('BGR', Imath.PixelType(Imath.PixelType.FLOAT))]
dmap = Image.fromarray((dmap != 1).astype(np.int32))
dmap.save(depth_path)
exr_image.close()
os.system('rm {}'.format(exr_path))
示例4: extract_rgb
# 需要导入模块: import Imath [as 别名]
# 或者: from Imath import PixelType [as 别名]
def extract_rgb(img, srgb=False):
dw = img.header()['dataWindow']
size = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)
precision = Imath.PixelType(Imath.PixelType.FLOAT)
R = img.channel('R', precision)
G = img.channel('G', precision)
B = img.channel('B', precision)
r = np.fromstring(R, dtype = np.float32)
g = np.fromstring(G, dtype = np.float32)
b = np.fromstring(B, dtype = np.float32)
r.shape = (size[1], size[0])
g.shape = (size[1], size[0])
b.shape = (size[1], size[0])
rgb = cv2.merge([b, g, r])
# grayscale = cv2.cvtColor(rgb, cv2.COLOR_BGR2GRAY)
# if srgb:
# grayscale = lin2srgb(grayscale)
return rgb
示例5: extract_depth
# 需要导入模块: import Imath [as 别名]
# 或者: from Imath import PixelType [as 别名]
def extract_depth(img):
dw = img.header()['dataWindow']
size = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)
precision = Imath.PixelType(Imath.PixelType.FLOAT)
Z = img.channel('Z', precision)
z = np.fromstring(Z, dtype = np.float32)
z.shape = (size[1], size[0])
return z
示例6: write_exr
# 需要导入模块: import Imath [as 别名]
# 或者: from Imath import PixelType [as 别名]
def write_exr(filename, values, channel_names):
"""Writes the values in a multi-channel ndarray into an EXR file.
Args:
filename: The filename of the output file
values: A numpy ndarray with shape [height, width, channels]
channel_names: A list of strings with length = channels
Raises:
TypeError: If the numpy array has an unsupported type.
ValueError: If the length of the array and the length of the channel names
list do not match.
"""
if values.shape[-1] != len(channel_names):
raise ValueError(
'Number of channels in values does not match channel names (%d, %d)' %
(values.shape[-1], len(channel_names)))
header = OpenEXR.Header(values.shape[1], values.shape[0])
try:
exr_channel_type = Imath.PixelType(_np_to_exr[values.dtype.type])
except KeyError:
raise TypeError('Unsupported numpy type: %s' % str(values.dtype))
header['channels'] = {
n: Imath.Channel(exr_channel_type) for n in channel_names
}
channel_data = [values[..., i] for i in range(values.shape[-1])]
exr = OpenEXR.OutputFile(filename, header)
exr.writePixels(
dict((n, d.tobytes()) for n, d in zip(channel_names, channel_data)))
exr.close()
示例7: readEXR
# 需要导入模块: import Imath [as 别名]
# 或者: from Imath import PixelType [as 别名]
def readEXR(fname,RESOLUTION):
channel_list = ["B","G","R"]
file = OpenEXR.InputFile(fname)
dw = file.header()["dataWindow"]
height,width = RESOLUTION,RESOLUTION
FLOAT = Imath.PixelType(Imath.PixelType.FLOAT)
vectors = [np.array(array.array("f",file.channel(c,FLOAT))) for c in channel_list]
depth = vectors[0].reshape([height,width])
return depth
示例8: read_exr
# 需要导入模块: import Imath [as 别名]
# 或者: from Imath import PixelType [as 别名]
def read_exr(exr_path, height, width):
file = OpenEXR.InputFile(exr_path)
depth_arr = array.array('f', file.channel('R', Imath.PixelType(Imath.PixelType.FLOAT)))
depth = np.array(depth_arr).reshape((height, width))
depth[depth < 0] = 0
depth[np.isinf(depth)] = 0
return depth
示例9: open_multilayer_exr_layers
# 需要导入模块: import Imath [as 别名]
# 或者: from Imath import PixelType [as 别名]
def open_multilayer_exr_layers(inputfile, layers):
"""
Load a list of images, each corresponding to a layer of an OpenEXR file.
Note that "layer" does not correspond to a single color channel, like "R",
but rather, a group of 3 color channels.
:param inputfile: string filename
:param layers: list of string layer names
"""
f = OpenEXR.InputFile(inputfile)
header = f.header()
dw = header['dataWindow']
cols, rows = dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1
# load channels
FLOAT = Imath.PixelType(Imath.PixelType.FLOAT)
images = []
for layer in layers:
channels = LAYER_CHANNELS[layer]
image = np.empty((rows, cols, 3), dtype=np.float32)
for (i, c) in enumerate(channels):
data = f.channel(c, FLOAT)
image[:, :, i] = np.fromstring(data, dtype=np.float32) \
.reshape((rows, cols))
images.append(image)
return images
#def denoise_indirect_image(img):
#denoised = np.empty_like(img)
#for c in xrange(3):
#denoised[:, :, c] = median_filter(
#img[:, :, c],
#mode='reflect',
#footprint=[
#[0, 1, 0],
#[1, 1, 1],
#[0, 1, 0],
#]
#)
#return denoised
示例10: rigid_flow
# 需要导入模块: import Imath [as 别名]
# 或者: from Imath import PixelType [as 别名]
def rigid_flow(self):
V, Omega, dt = self.compute_velocity_from_msg(self.pose_data[200,:], self.pose_data[204,:])
# print(self.depth_data[1][1])
depth_image0 = OpenEXR.InputFile(self.depth_data[200][1])
dw0 = depth_image0.header()['dataWindow']
size0 = (dw0.max.x - dw0.min.x + 1, dw0.max.y - dw0.min.y + 1)
pt0 = Imath.PixelType(Imath.PixelType.FLOAT)
depth0 = np.fromstring(depth_image0.channel("Z"), dtype=np.float32)
depth0.shape = (size0[1], size0[0]) # Numpy arrays are (row, col)
depth_image1 = OpenEXR.InputFile(self.depth_data[204][1])
dw1 = depth_image1.header()['dataWindow']
size1 = (dw1.max.x - dw1.min.x + 1, dw1.max.y - dw1.min.y + 1)
pt1 = Imath.PixelType(Imath.PixelType.FLOAT)
depth1 = np.fromstring(depth_image1.channel("Z"), dtype=np.float32)
depth1.shape = (size1[1], size1[0]) # Numpy arrays are (row, col)
depth = (depth0+depth1)/2
flow_x_dist, flow_y_dist = self.compute_flow_single_frame(V,
Omega,
depth,
dt)
print(flow_x_dist, flow_y_dist)
flow = np.dstack((flow_x_dist, flow_y_dist))
flow = np.float32(flow)
# verfication
img1 = cv2.imread(self.image_data[200][1],1)
# img1 = np.float32(img1)
print(img1.shape)
img2 = cv2.imread(self.image_data[204][1], 1)
# img2 = np.float32(img2)
print(img1.shape, flow.dtype)
warpped_img1 = self.warp_image(img2, flow)
# warpped_img1 = self.warp_flow(img2, flow)
cv2.imshow('warpped_img1', cv2.subtract(img1, warpped_img1))
first_img = self.colorize_image(flow_x_dist, flow_y_dist)
cv2.imshow('image',first_img)
cv2.waitKey(0)