From cff796a4b7bfe72530e43ecc3e9288fc0dc57dee Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 12 Mar 2019 02:18:11 +0000 Subject: [PATCH] Add different interpolation techniques to the ERP to NxN conversion --- modules/ThreeSixtyDownsampling.cpp | 36 +++++++++++++++++++++++++----- modules/ThreeSixtyDownsampling.h | 3 ++- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/modules/ThreeSixtyDownsampling.cpp b/modules/ThreeSixtyDownsampling.cpp index 098e76b..a79a207 100644 --- a/modules/ThreeSixtyDownsampling.cpp +++ b/modules/ThreeSixtyDownsampling.cpp @@ -44,11 +44,19 @@ ThreeSixtyDownsampling::ThreeSixtyDownsampling() m_uiNumberOfFrames = 1; m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY | CLP_MODULE_REQUIRES_OPTIONS; - m_cModuleOptions.addOptions() /**/ - ( "Downsampling", m_bDownsampling, "ERP to NxN [true]" ); + m_cModuleOptions.addOptions() /**/ + ( "Downsampling", m_bDownsampling, "ERP to NxN [true]" ) /**/ + ( "Interpolation", m_iInterpolation, "Interpolation method (1-5) [1]" ); + + // INTER_NEAREST - a nearest-neighbor interpolation + // INTER_LINEAR - a bilinear interpolation (used by default) + // INTER_AREA - resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire’-free results. But when the image is zoomed, it is similar to the INTER_NEAREST method. + // INTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhood + // INTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhood + m_bDownsampling = true; + m_iInterpolation = 1; m_pcOutputFrame = NULL; - m_bDownsampling = true; } bool ThreeSixtyDownsampling::create( std::vector apcFrameList ) @@ -56,6 +64,24 @@ bool ThreeSixtyDownsampling::create( std::vector apcFrameList ) _BASIC_MODULE_API_2_CHECK_ m_pcOutputFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY ); m_isOdd = !( m_pcOutputFrame->getHeight() % 2 ); + + switch( m_iInterpolation ) + { + case 2: + m_iInterpolation = cv::INTER_LINEAR; + break; + case 3: + m_iInterpolation = cv::INTER_AREA; + break; + case 4: + m_iInterpolation = cv::INTER_CUBIC; + break; + case 5: + m_iInterpolation = cv::INTER_LANCZOS4; + break; + default: + m_iInterpolation = cv::INTER_NEAREST; + } return true; } @@ -92,14 +118,14 @@ CalypFrame* ThreeSixtyDownsampling::process( std::vector apcFrameLi // resize if( m_bDownsampling ) { - cv::resize( cvIn.row( ypos ), cvDownsample, cvDownsample.size() ); + cv::resize( cvIn.row( ypos ), cvDownsample, cvDownsample.size(), 0, 0, m_iInterpolation ); cvOutput = cvDownsample; } else { Mat cvauxin = cvIn.row( ypos ).colRange( xpos, xpos + lineWidth ); cvauxin.copyTo( cvDownsample ); - cv::resize( cvDownsample, cvUpsample, cvUpsample.size() ); + cv::resize( cvDownsample, cvUpsample, cvUpsample.size(), 0, 0, m_iInterpolation ); cvOutput = cvUpsample; } diff --git a/modules/ThreeSixtyDownsampling.h b/modules/ThreeSixtyDownsampling.h index 0319f39..c7d838e 100644 --- a/modules/ThreeSixtyDownsampling.h +++ b/modules/ThreeSixtyDownsampling.h @@ -32,8 +32,9 @@ class ThreeSixtyDownsampling : public CalypModuleIf { REGISTER_CLASS_FACTORY( ThreeSixtyDownsampling ) private: - bool m_bDownsampling; bool m_isOdd; + bool m_bDownsampling; + int m_iInterpolation; public: ThreeSixtyDownsampling();