How should I write a function that takes two images as inputs?

Can I write a function that takes two images as inputs and calculates the min pixel this way? I am following the deepcopy example. Thanks

template <typename TImage>
void
Min_of_Image(typename TImage::Pointer input, typename TImage::Pointer input_2, typename TImage::Pointer output)
{
  output->SetRegions(input->GetLargestPossibleRegion());
  output->Allocate();

  itk::ImageRegionConstIterator<TImage> inputIterator(input, input->GetLargestPossibleRegion());
  itk::ImageRegionConstIterator<TImage> inputIterator_2(input_2, input_2->GetLargestPossibleRegion());
  itk::ImageRegionIterator<TImage>      outputIterator(output, output->GetLargestPossibleRegion());

  while (!inputIterator.IsAtEnd())
  {
    outputIterator.Set(std::min(inputIterator.Get(),inputIterator_2.Get()));
    ++inputIterator;
    ++inputIterator_2;
    ++outputIterator;
  }
}

I think this would work. But an immediate style suggestion is: instead of taking output as a third parameter, you could return typename TImage::Pointer from your function:

template <typename TImage>
typename TImage::Pointer
Min_of_Image(typename TImage::Pointer input, typename TImage::Pointer input_2)
{
  typename TImage::Pointer output = TImage::New();
  output->CopyInformation(input);
  output->SetRegions(input->GetLargestPossibleRegion());
  output->Allocate();
  // etc;
  return output;
}

Finally, why not use BinaryGeneratorImageFilter? You would only need to provide a lambda function which operates on two pixels. It will run in parallel, and can probably be streamed.