0

I've been assigned to write a tool that stitches exr files together (in a grid of any size, be it 2x2 or 4x4). When writing the output image, the memory footprint should be small. enter image description here

How do I write the output image one scan line at a time?

This is my code so far:

for i in range(1, len(exr_files_list)):
   if i == 1:
      merged = exr_file_list[0]
   else:
      merged = merge_images(merged, exr_files_list[i])

merged_image_array = np.array(merged)
write_exr('a.exr', merged_image_array, ['R', 'G', 'B']

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()
  • what happens if you have 3 images? or the images are different sizes? or is it all ways 1,4,9,16 number of images? – Joran Beasley Sep 30 '22 at 07:17
  • The rows and columns are specified in file names. If the files are ```u1_v1.exr, u1_v2.exr```, they are stitched in a single row. If the files are ```u1_v1.exr, u1_v2.exr, u2_v1.exr, u2_v2.exr```, they are stitched in a 2x2 grid. The grid can be any size. The images in the same row must have the same heights. Images in the same column must have the same widths. – Ahmad Uzzam Masood Sep 30 '22 at 07:22
  • Why have you tagged `photoshop` and `opencv`? Where are your `import` statements? Thank you. – Mark Setchell Oct 03 '22 at 21:59

0 Answers0