#ifndef IMAGE_CONV_H
#define IMAGE_CONV_H

#include "image.h"
#include "multi_array_conv.h"

namespace mimas {

/** Correlation of two images.
    This method provides correlation of two images. The
    resulting image will have the same size as the input-image \c x.
    Elements outside of the image-boundaries are assumed to be zero.

    The algorithm is intented to be used for convoluting an image with
    a small filter. If the filter is very big, it may be more efficient, to
    perform the correlation in fourier-space.

    @param x First array.
    @param y Second array.
    @return Result of correlation.
    @see arrayOp
    @see fourierTransforms */
  template< typename T, typename TPtr, typename UPtr >
    inline image< T > correlate( const const_image_ref< T, TPtr > &x,
                                 const const_image_ref< T, UPtr > &y )
{
  image< T > retVal; retVal.init( x.getWidth(), x.getHeight() );
  boost::multi_array_ref< T, 2 >
    dr( retVal.rawData(),
        boost::extents[ retVal.getHeight() ][ retVal.getWidth() ] );
  boost::const_multi_array_ref< T, 2 >
    dx( x.rawData(), boost::extents[ x.getHeight() ][ x.getWidth() ] ),
    dy( y.rawData(), boost::extents[ y.getHeight() ][ y.getWidth() ] );
  dr = correlate( dx, dy );
  return retVal;
}

#ifdef HAVE_LIBLAPACK

template< typename T, typename TPtr, typename UPtr >
image< T > correlate_separable( const const_image_ref< T, TPtr > &x,
                                const const_image_ref< T, UPtr > &f )
{
  return image< T >( correlate_separable< T >( x.rawData(), f.rawData() ) );
}

#endif

}

#endif