PCL
SeparableConvolution.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.1.19
6 // ----------------------------------------------------------------------------
7 // pcl/SeparableConvolution.h - Released 2019-11-07T10:59:34Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2019 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (http://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_SeparableConvolution_h
53 #define __PCL_SeparableConvolution_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
60 #include <pcl/AutoPointer.h>
62 #include <pcl/ParallelProcess.h>
63 #include <pcl/SeparableFilter.h>
64 
65 #define __PCL_SEPARABLE_CONVOLUTION_TINY_WEIGHT 1.0e-20
66 
67 namespace pcl
68 {
69 
70 // ----------------------------------------------------------------------------
71 
79  public ParallelProcess
80 {
81 public:
82 
87 
92 
99  SeparableConvolution() = default;
100 
111  {
112  SetFilter( filter );
113  }
114 
120  ParallelProcess( x ),
121  m_weight( x.m_weight ),
122  m_highPass( x.m_highPass ), m_rawHighPass( x.m_rawHighPass ), m_rescaleHighPass( x.m_rescaleHighPass ),
123  m_convolveRows( x.m_convolveRows ), m_convolveCols( x.m_convolveCols )
124  {
125  if ( !x.m_filter.IsNull() )
126  m_filter = x.m_filter->Clone();
127  }
128 
133 
138  {
139  }
140 
145  {
146  if ( &x != this )
147  {
148  (void)InterlacedTransformation::operator =( x );
149  (void)ParallelProcess::operator =( x );
150  if ( x.m_filter.IsNull() )
151  m_filter.Destroy();
152  else
153  m_filter = x.m_filter->Clone();
154  m_weight = x.m_weight;
155  m_highPass = x.m_highPass;
156  m_rawHighPass = x.m_rawHighPass;
157  m_rescaleHighPass = x.m_rescaleHighPass;
158  m_convolveRows = x.m_convolveRows;
159  m_convolveCols = x.m_convolveCols;
160  }
161  return *this;
162  }
163 
167  SeparableConvolution& operator =( SeparableConvolution&& ) = default;
168 
176  const SeparableFilter& Filter() const
177  {
178  PCL_PRECONDITION( !m_filter.IsNull() )
179  return *m_filter;
180  }
181 
191  coefficient_vector Filter( int phase ) const
192  {
193  PCL_PRECONDITION( !m_filter.IsNull() )
194  return m_filter->Filter( phase );
195  }
196 
200  void SetFilter( const SeparableFilter& filter )
201  {
202  m_filter = filter.Clone();
203  CacheFilterProperties();
204  }
205 
215  double FilterWeight() const
216  {
217  return m_weight;
218  }
219 
231  bool IsHighPassFilter() const
232  {
233  return m_highPass;
234  }
235 
255  {
256  return m_rescaleHighPass;
257  }
258 
264  void EnableHighPassRescaling( bool enable = true )
265  {
266  m_rescaleHighPass = enable;
267  }
268 
274  void DisableHighPassRescaling( bool disable = true )
275  {
276  EnableHighPassRescaling( !disable );
277  }
278 
289  bool IsRawHighPassEnabled() const
290  {
291  return m_rawHighPass;
292  }
293 
298  void EnableRawHighPass( bool enable = true )
299  {
300  m_rawHighPass = enable;
301  }
302 
307  void DisableRawHighPass( bool disable = true )
308  {
309  EnableRawHighPass( !disable );
310  }
311 
316  {
317  return m_convolveRows;
318  }
319 
323  void EnableRowConvolution( bool enable = true )
324  {
325  m_convolveRows = enable;
326  }
327 
334  void DisableRowConvolution( bool disable = true )
335  {
336  EnableRowConvolution( !disable );
337  }
338 
343  {
344  return m_convolveCols;
345  }
346 
350  void EnableColumnConvolution( bool enable = true )
351  {
352  m_convolveCols = enable;
353  }
354 
361  void DisableColumnConvolution( bool disable = true )
362  {
363  EnableColumnConvolution( !disable );
364  }
365 
372  {
373  PCL_PRECONDITION( !m_filter.IsNull() )
374  return m_filter->Size() + (m_filter->Size() - 1)*(InterlacingDistance() - 1);
375  }
376 
377 protected:
378 
379  /*
380  * The response function for convolution is a separable filter.
381  */
383 
384  /*
385  * Cached filter properties.
386  */
387  double m_weight = 0; // filter weight for low-pass normalization
388  bool m_highPass = false; // true iff this is a high-pass filter
389 
390  /*
391  * User-selectable options.
392  */
393  bool m_rawHighPass = false; // neither truncate nor normalize out-of-range values
394  bool m_rescaleHighPass = false; // truncate out-of-range values instead of normalize
395  bool m_convolveRows = true; // perform one-dimensional convolution of pixel rows
396  bool m_convolveCols = true; // perform one-dimensional convolution of pixel columns
397 
398  /*
399  * In-place 2-D separable convolution algorithm.
400  */
401  void Apply( pcl::Image& ) const override;
402  void Apply( pcl::DImage& ) const override;
403  void Apply( pcl::UInt8Image& ) const override;
404  void Apply( pcl::UInt16Image& ) const override;
405  void Apply( pcl::UInt32Image& ) const override;
406 
407 private:
408 
409  void CacheFilterProperties()
410  {
411  PCL_PRECONDITION( !m_filter.IsNull() )
412  PCL_PRECONDITION( !m_filter->IsEmpty() )
413  ValidateFilter();
414  m_highPass = m_filter->IsHighPassFilter();
415  m_weight = m_filter->Weight();
416  if ( pcl::Abs( m_weight ) < __PCL_SEPARABLE_CONVOLUTION_TINY_WEIGHT )
417  m_weight = 1;
418  }
419 
420  void ValidateFilter() const;
421 };
422 
423 // ----------------------------------------------------------------------------
424 
425 } // pcl
426 
427 #endif // __PCL_SeparableConvolution_h
428 
429 // ----------------------------------------------------------------------------
430 // EOF pcl/SeparableConvolution.h - Released 2019-11-07T10:59:34Z
bool IsNull() const
Definition: AutoPointer.h:454
SeparableFilter::coefficient_vector coefficient_vector
Interlaced image transformation in the spatial domain.
virtual SeparableFilter * Clone() const
void DisableRowConvolution(bool disable=true)
PCL root namespace.
Definition: AbstractImage.h:76
Discrete two-dimensional separable convolution.
void EnableRawHighPass(bool enable=true)
A smart pointer with sole object ownership and optional automatic object destruction.
Definition: AutoPointer.h:241
Separable filter in two dimensions.
SeparableFilter::coefficient coefficient
16-bit unsigned integer image.
void EnableHighPassRescaling(bool enable=true)
T Abs(const Complex< T > &c)
Definition: Complex.h:420
void Apply(FI i, FI j, F f)
Definition: Utility.h:249
void EnableRowConvolution(bool enable=true)
SeparableConvolution(const SeparableConvolution &x)
void DisableColumnConvolution(bool disable=true)
64-bit floating point real image.
32-bit unsigned integer image.
SeparableConvolution(const SeparableFilter &filter)
8-bit unsigned integer image.
void EnableColumnConvolution(bool enable=true)
void DisableHighPassRescaling(bool disable=true)
const SeparableFilter & Filter() const
void SetFilter(const SeparableFilter &filter)
32-bit floating point real image.
coefficient_vector Filter(int phase) const
void DisableRawHighPass(bool disable=true)
A process using multiple concurrent execution threads.