當前位置: 首頁>>代碼示例>>Python>>正文


Python Imath.PixelType方法代碼示例

本文整理匯總了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 
開發者ID:uzh-rpg,項目名稱:rpg_davis_simulator,代碼行數:26,代碼來源:dataset_utils.py

示例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 
開發者ID:joeylitalien,項目名稱:noise2noise-pytorch,代碼行數:20,代碼來源:utils.py

示例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)) 
開發者ID:zju3dv,項目名稱:pvnet-rendering,代碼行數:18,代碼來源:render_utils.py

示例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 
開發者ID:prgumd,項目名稱:EVDodgeNet,代碼行數:26,代碼來源:dataset_utils.py

示例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 
開發者ID:uzh-rpg,項目名稱:rpg_davis_simulator,代碼行數:10,代碼來源:dataset_utils.py

示例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() 
開發者ID:tensorflow,項目名稱:graphics,代碼行數:32,代碼來源:exr.py

示例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 
開發者ID:chenhsuanlin,項目名稱:3D-point-cloud-generation,代碼行數:11,代碼來源:convertEXR.py

示例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 
開發者ID:wentaoyuan,項目名稱:pcn,代碼行數:9,代碼來源:process_exr.py

示例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 
開發者ID:seanbell,項目名稱:opensurfaces,代碼行數:45,代碼來源:synthetic.py

示例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) 
開發者ID:prgumd,項目名稱:EVDodgeNet,代碼行數:49,代碼來源:flow.py


注:本文中的Imath.PixelType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。