Sirius  0.0.0
filter.h
Go to the documentation of this file.
1 
22 #ifndef SIRIUS_FILTER_H_
23 #define SIRIUS_FILTER_H_
24 
25 #include <map>
26 #include <memory>
27 #include <string>
28 
29 #include "sirius/image.h"
30 #include "sirius/types.h"
31 
32 #include "sirius/fftw/types.h"
33 
34 #include "sirius/utils/lru_cache.h"
35 
36 namespace sirius {
37 
45 };
46 
47 constexpr Point filter_default_hot_point{-1, -1};
48 
52 class Filter {
53  private:
54  static constexpr int kCacheSize = 10;
56  using FilterFFTCacheUPtr = std::unique_ptr<FilterFFTCache>;
57 
58  public:
68  static Filter Create(Image filter_image, const ZoomRatio& zoom_ratio,
71  bool normalize = false);
72 
73  Filter() = default;
74 
75  ~Filter() = default;
76 
77  // non copyable
78  Filter(const Filter&) = delete;
79  Filter& operator=(const Filter&) = delete;
80  // moveable
81  Filter(Filter&&) = default;
82  Filter& operator=(Filter&&) = default;
83 
88  bool IsLoaded() const { return filter_.IsLoaded(); }
89 
94  Size size() const { return filter_.size; }
95 
100  Size padding_size() const { return padding_size_; }
101 
106  PaddingType padding_type() const { return padding_type_; }
107 
109  return {filter_.size, padding_size_, padding_type_};
110  }
111 
116  Padding padding() const {
117  return {padding_size_.row, padding_size_.row, padding_size_.col,
118  padding_size_.col, padding_type_};
119  }
120 
121  const Point& hot_point() const { return hot_point_; }
122 
128  bool CanBeApplied(const ZoomRatio& zoom_ratio) const {
129  return (zoom_ratio_.input_resolution() ==
130  zoom_ratio.input_resolution());
131  }
132 
144  fftw::ComplexUPtr Process(const Size& image_size,
145  fftw::ComplexUPtr image_fft) const;
146 
147  private:
148  static Filter CreateZoomInFilter(Image filter_image,
149  const ZoomRatio& zoom_ratio,
151  const Point& hot_point);
152  static Filter CreateZoomOutFilter(Image filter_image,
153  const ZoomRatio& zoom_ratio,
155  const Point& hot_point);
156  static Filter CreateRealZoomFilter(Image filter_image,
157  const ZoomRatio& zoom_ratio,
159  const Point& hot_point);
160 
161  Filter(Image&& filter_image, const Size& padding_size,
162  const ZoomRatio& zoom_ratio, PaddingType padding_type,
163  const Point& hot_point);
164 
165  fftw::ComplexUPtr CreateFilterFFT(const Size& image_size) const;
166 
167  private:
168  Image filter_{};
169  Size padding_size_{0, 0};
170  ZoomRatio zoom_ratio_{};
172  Point hot_point_{filter_default_hot_point};
173 
174  FilterFFTCacheUPtr filter_fft_cache_{nullptr};
175 };
176 
177 } // namespace sirius
178 
179 #endif // SIRIUS_FILTER_H_
PaddingType
Definition: image.h:31
Definition: exception.h:27
Frequency filter.
Definition: filter.h:52
Size margin_size
Definition: filter.h:43
Size size
Definition: filter.h:42
~Filter()=default
Data class that represents the 2D coordinates of a point.
Definition: types.h:86
PaddingType padding_type() const
Get padding type.
Definition: filter.h:106
int input_resolution() const
Definition: types.h:141
LRU cache.
Definition: lru_cache.h:38
std::unique_ptr<::fftw_complex[], detail::ComplexDeleter > ComplexUPtr
Definition: types.h:57
Data class that represents zoom ratio as input_resolution/output_resolution.
Definition: types.h:105
FilterMetadata Metadata() const
Definition: filter.h:108
Size size() const
Filter image size.
Definition: filter.h:94
Size padding_size() const
Padding size needed for the filter.
Definition: filter.h:100
constexpr Point filter_default_hot_point
Definition: filter.h:47
bool IsLoaded() const
Filter is loaded and ready to be applied on an image FFT.
Definition: filter.h:88
Data class that represents the padding of an image.
Definition: image.h:39
Data class that represents the size of an image.
Definition: types.h:38
fftw::ComplexUPtr Process(const Size &image_size, fftw::ComplexUPtr image_fft) const
Apply the filter on the image_fft.
Filter & operator=(const Filter &)=delete
int row
Definition: types.h:79
Filter()=default
int col
Definition: types.h:80
Padding padding() const
Zero padding needed for the filter.
Definition: filter.h:116
PaddingType padding_type
Definition: filter.h:44
static Filter Create(Image filter_image, const ZoomRatio &zoom_ratio, const Point &hot_point=filter_default_hot_point, PaddingType padding_type=PaddingType::kMirrorPadding, bool normalize=false)
Filter which is adapted specifically for a particular zoom ratio.
Data class that represents an image (Size + Buffer)
Definition: image.h:65
Data class that contains Filter metadata.
Definition: filter.h:41
const Point & hot_point() const
Definition: filter.h:121
bool IsLoaded() const
Check that the image is loaded Row, col and data are set.
Definition: image.h:122
Size size
Definition: image.h:157
bool CanBeApplied(const ZoomRatio &zoom_ratio) const
Check that the filter can be applied on the given zoom ratio.
Definition: filter.h:128