imgproc.h
Go to the documentation of this file.
1 /*
2 * ECVL - European Computer Vision Library
3 * Version: 0.3.4
4 * copyright (c) 2021, Università degli Studi di Modena e Reggio Emilia (UNIMORE), AImageLab
5 * Authors:
6 * Costantino Grana (costantino.grana@unimore.it)
7 * Federico Bolelli (federico.bolelli@unimore.it)
8 * Michele Cancilla (michele.cancilla@unimore.it)
9 * Laura Canalini (laura.canalini@unimore.it)
10 * Stefano Allegretti (stefano.allegretti@unimore.it)
11 * All rights reserved.
12 */
13 
14 #ifndef ECVL_IMGPROC_H_
15 #define ECVL_IMGPROC_H_
16 
17 #include <random>
18 #include "image.h"
19 #include "saturate_cast.h"
20 
21 namespace ecvl
22 {
27 enum class ThresholdingType
28 {
29  BINARY,
30  BINARY_INV,
31 };
32 
38 {
39  nearest,
40  linear,
41  area,
45  cubic,
46  lanczos4
47 };
48 
56 
68 void ResizeDim(const ecvl::Image& src, ecvl::Image& dst, const std::vector<int>& newdims, InterpolationType interp = InterpolationType::linear);
69 
81 void ResizeScale(const ecvl::Image& src, ecvl::Image& dst, const std::vector<double>& scales, InterpolationType interp = InterpolationType::linear);
82 
91 void Flip2D(const ecvl::Image& src, ecvl::Image& dst);
92 
101 void Mirror2D(const ecvl::Image& src, ecvl::Image& dst);
102 
119 void Rotate2D(const ecvl::Image& src, ecvl::Image& dst, double angle, const std::vector<double>& center = {}, double scale = 1.0, InterpolationType interp = InterpolationType::linear);
120 
135 void RotateFullImage2D(const ecvl::Image& src, ecvl::Image& dst, double angle, double scale = 1.0, InterpolationType interp = InterpolationType::linear);
136 
148 void ChangeColorSpace(const Image& src, Image& dst, ColorType new_type);
149 
165 void Threshold(const Image& src, Image& dst, double thresh, double maxval, ThresholdingType thresh_type = ThresholdingType::BINARY);
166 
178 void MultiThreshold(const Image& src, Image& dst, const std::vector<int>& thresholds, int minval = 0, int maxval = 255);
179 
189 int OtsuThreshold(const Image& src);
190 
203 std::vector<int> OtsuMultiThreshold(const Image& src, int n_thresholds = 2);
204 
213 void Filter2D(const Image& src, Image& dst, const Image& ker, DataType type = DataType::none /* type of border */);
214 
224 void SeparableFilter2D(const Image& src, Image& dst, const std::vector<double>& kerX, const std::vector<double>& kerY, DataType type = DataType::none);
225 
236 void GaussianBlur(const Image& src, Image& dst, int sizeX, int sizeY, double sigmaX, double sigmaY = 0);
237 void GaussianBlur(const Image& src, Image& dst, double sigma);
238 
246 void AdditiveLaplaceNoise(const Image& src, Image& dst, double std_dev);
247 
255 void AdditivePoissonNoise(const Image& src, Image& dst, double lambda);
256 
263 void GammaContrast(const Image& src, Image& dst, double gamma);
264 
274 void CoarseDropout(const Image& src, Image& dst, double p, double drop_size, bool per_channel);
275 
282 void IntegralImage(const Image& src, Image& dst, DataType dst_type = DataType::float64);
283 
289 void NonMaximaSuppression(const Image& src, Image& dst);
290 
297 std::vector<ecvl::Point2i> GetMaxN(const Image& src, size_t n);
298 
307 void ConnectedComponentsLabeling(const Image& src, Image& dst);
308 
314 void FindContours(const Image& src, std::vector<std::vector<Point2i>>& contours);
315 
321 void Stack(const std::vector<Image>& src, Image& dst);
322 
328 void HConcat(const std::vector<Image>& src, Image& dst);
329 
335 void VConcat(const std::vector<Image>& src, Image& dst);
336 
341 enum class MorphType
342 {
343  MORPH_ERODE ,
344  MORPH_DILATE ,
345  MORPH_OPEN ,
346  MORPH_CLOSE ,
350  MORPH_TOPHAT ,
356 };
357 
362 enum class BorderType
363 {
367  BORDER_WRAP,
370 };
371 
383 void Morphology(const Image& src, Image& dst, MorphType op, Image& kernel,
384  Point2i anchor = { -1, -1 },
385  int iterations = 1,
387  const int& border_value = 0 /*morphologyDefaultBorderValue()*/
388 );
389 
394 enum class InpaintType
395 {
396  INPAINT_NS,
398 };
399 
408 void Inpaint(const Image& src, Image& dst, const Image& inpaintMask, double inpaintRadius, InpaintType flag = InpaintType::INPAINT_TELEA);
409 
416 void MeanStdDev(const Image& src, std::vector<double>& mean, std::vector<double>& stddev);
417 
423 void Transpose(const Image& src, Image& dst);
424 
437 void GridDistortion(const Image& src, Image& dst,
438  int num_steps = 5,
439  const std::array<float, 2>& distort_limit = { -0.3f, 0.3f },
442  const int& border_value = 0,
443  const unsigned seed = std::default_random_engine::default_seed
444 );
445 
458 void ElasticTransform(const Image& src, Image& dst,
459  double alpha = 34.,
460  double sigma = 4.,
463  const int& border_value = 0,
464  const unsigned seed = std::default_random_engine::default_seed
465 );
466 
479 void OpticalDistortion(const Image& src, Image& dst,
480  const std::array<float, 2>& distort_limit = { -0.3f, 0.3f },
481  const std::array<float, 2>& shift_limit = { -0.1f, 0.1f },
484  const int& border_value = 0,
485  const unsigned seed = std::default_random_engine::default_seed
486 );
487 
496 void Salt(const Image& src, Image& dst, double p, bool per_channel = false, const unsigned seed = std::default_random_engine::default_seed);
497 
506 void Pepper(const Image& src, Image& dst, double p, bool per_channel = false, const unsigned seed = std::default_random_engine::default_seed);
507 
516 void SaltAndPepper(const Image& src, Image& dst, double p, bool per_channel = false, const unsigned seed = std::default_random_engine::default_seed);
517 
527 void SliceTimingCorrection(const Image& src, Image& dst, bool odd = false, bool down = false);
528 
549 void Moments(const Image& src, Image& moments, int order = 3, DataType type = DataType::float64);
550 
615 void CentralMoments(const Image& src, Image& moments, std::vector<double> center, int order = 3, DataType type = DataType::float64);
616 
617 
628 void DrawEllipse(Image& src, ecvl::Point2i center, ecvl::Size2i axes, double angle, const ecvl::Scalar& color, int thickness = 1);
629 
637 void DropColorChannel(Image& src);
638 
649 void Normalize(const Image& src, Image& dst, const double& mean, const double& std);
650 
661 void Normalize(const Image& src, Image& dst, const std::vector<double>& mean, const std::vector<double>& std);
662 
671 void CenterCrop(const ecvl::Image& src, ecvl::Image& dst, const std::vector<int>& size);
672 
682 void ScaleTo(const Image& src, Image& dst, const double& new_min, const double& new_max);
683 
695 } // namespace ecvl
696 
697 #endif // ECVL_IMGPROC_H_
void ResizeDim(const ecvl::Image &src, ecvl::Image &dst, const std::vector< int > &newdims, InterpolationType interp=InterpolationType::linear)
Resizes an Image to the specified dimensions.
Image class.
Definition: image.h:72
void CoarseDropout(const Image &src, Image &dst, double p, double drop_size, bool per_channel)
Sets rectangular areas within an Image to zero.
void GridDistortion(const Image &src, Image &dst, int num_steps=5, const std::array< float, 2 > &distort_limit={ -0.3f, 0.3f }, InterpolationType interp=InterpolationType::linear, BorderType border_type=BorderType::BORDER_REFLECT_101, const int &border_value=0, const unsigned seed=std::default_random_engine::default_seed)
Randomly stretch or reduce each cell of the grid in which the input Image is divided into....
void ScaleTo(const Image &src, Image &dst, const double &new_min, const double &new_max)
Linearly scale an Image into a new range.
InpaintType
Enum class representing the ECVL inpaint types.
Definition: imgproc.h:394
void ChangeColorSpace(const Image &src, Image &dst, ColorType new_type)
Copies the source Image into destination Image changing the color space.
void Morphology(const Image &src, Image &dst, MorphType op, Image &kernel, Point2i anchor={ -1, -1 }, int iterations=1, BorderType border_type=BorderType::BORDER_CONSTANT, const int &border_value=0)
Performs advanced morphological transformations using an erosion and dilation as basic operations.
Use Navier-Stokes based method.
aaaaaa|abcdefgh|hhhhhhh
void Inpaint(const Image &src, Image &dst, const Image &inpaintMask, double inpaintRadius, InpaintType flag=InpaintType::INPAINT_TELEA)
Restores the selected region in an image using the region neighborhood.
void CentralMoments(const Image &src, Image &moments, std::vector< double > center, int order=3, DataType type=DataType::float64)
Calculate all central image moments of the source Image up to the specified order.
void ConnectedComponentsLabeling(const Image &src, Image &dst)
Labels connected components in a binary Image.
void VConcat(const std::vector< Image > &src, Image &dst)
Vertical concatenation of images (with the same number of columns)
void CenterCrop(const ecvl::Image &src, ecvl::Image &dst, const std::vector< int > &size)
Crops the given image at the center.
void FindContours(const Image &src, std::vector< std::vector< Point2i >> &contours)
Finds contours in a binary image.
DataType
DataType is an enum class which defines data types allowed for images.
Definition: datatype.h:43
ColorType
Enum class representing the ECVL supported color spaces.
Definition: image.h:50
InterpolationType
Enum class representing the ECVL interpolation types.
Definition: imgproc.h:37
void AdditiveLaplaceNoise(const Image &src, Image &dst, double std_dev)
Adds Laplace distributed noise to an Image.
void SliceTimingCorrection(const Image &src, Image &dst, bool odd=false, bool down=false)
Corrects each voxel's time-series. Slice timing correction works by using (Hanning-windowed) sinc int...
void Threshold(const Image &src, Image &dst, double thresh, double maxval, ThresholdingType thresh_type=ThresholdingType::BINARY)
Applies a fixed threshold to an input Image.
void DrawEllipse(Image &src, ecvl::Point2i center, ecvl::Size2i axes, double angle, const ecvl::Scalar &color, int thickness=1)
Draw an ellipse over the specified Image.
void HConcat(const std::vector< Image > &src, Image &dst)
Horizontal concatenation of images (with the same number of rows)
void Transpose(const Image &src, Image &dst)
Swap rows and columns of an Image.
std::vector< int > OtsuMultiThreshold(const Image &src, int n_thresholds=2)
Calculates the Otsu thresholding values.
iiiiii|abcdefgh|iiiiiii with some specified i
int OtsuThreshold(const Image &src)
Calculates the Otsu thresholding value.
void Salt(const Image &src, Image &dst, double p, bool per_channel=false, const unsigned seed=std::default_random_engine::default_seed)
Adds salt noise (white pixels) to an Image.
void ResizeScale(const ecvl::Image &src, ecvl::Image &dst, const std::vector< double > &scales, InterpolationType interp=InterpolationType::linear)
Resizes an Image by scaling the dimensions to a given scale factor.
cdefgh|abcdefgh|abcdefg
int GetOpenCVInterpolation(InterpolationType interp)
Given an InterpolationType, the GetOpenCVInterpolation function returns the associated OpenCV enum va...
void GaussianBlur(const Image &src, Image &dst, int sizeX, int sizeY, double sigmaX, double sigmaY=0)
Blurs an Image using a Gaussian kernel.
void Normalize(const Image &src, Image &dst, const double &mean, const double &std)
Normalize Image image with mean and standard deviation.
fedcba|abcdefgh|hgfedcb
ThresholdingType
Enum class representing the ECVL thresholding types.
Definition: imgproc.h:27
void RotateFullImage2D(const ecvl::Image &src, ecvl::Image &dst, double angle, double scale=1.0, InterpolationType interp=InterpolationType::linear)
Rotates an Image resizing the output accordingly.
BorderType
Enum class representing the ECVL border types.
Definition: imgproc.h:362
void SeparableFilter2D(const Image &src, Image &dst, const std::vector< double > &kerX, const std::vector< double > &kerY, DataType type=DataType::none)
Convolves an Image with a couple of 1-dimensional kernels.
void MultiThreshold(const Image &src, Image &dst, const std::vector< int > &thresholds, int minval=0, int maxval=255)
Applies multiple thresholds to the input Image.
void SaltAndPepper(const Image &src, Image &dst, double p, bool per_channel=false, const unsigned seed=std::default_random_engine::default_seed)
Adds salt and pepper noise (white and black pixels) to an Image. White and black pixels are equally l...
void Moments(const Image &src, Image &moments, int order=3, DataType type=DataType::float64)
Calculate all raw image moments of the source Image up to the specified order.
void AdditivePoissonNoise(const Image &src, Image &dst, double lambda)
Adds Poisson distributed noise to an Image.
void Rotate2D(const ecvl::Image &src, ecvl::Image &dst, double angle, const std::vector< double > &center={}, double scale=1.0, InterpolationType interp=InterpolationType::linear)
Rotates an Image.
void DropColorChannel(Image &src)
Remove color channel from the input Image.
std::array< int, 2 > Point2i
Definition: datatype.h:25
void Filter2D(const Image &src, Image &dst, const Image &ker, DataType type=DataType::none)
Convolves an Image with a kernel.
void Stack(const std::vector< Image > &src, Image &dst)
Stack a sequence of Images along the depth dimension (images width and height must match)
void OpticalDistortion(const Image &src, Image &dst, const std::array< float, 2 > &distort_limit={ -0.3f, 0.3f }, const std::array< float, 2 > &shift_limit={ -0.1f, 0.1f }, InterpolationType interp=InterpolationType::linear, BorderType border_type=BorderType::BORDER_REFLECT_101, const int &border_value=0, const unsigned seed=std::default_random_engine::default_seed)
Barrel / pincushion distortion. Based on https://github.com/albumentations-team/albumentations/blob/m...
std::vector< double > Scalar
Definition: datatype.h:29
void NonMaximaSuppression(const Image &src, Image &dst)
Calculate the Non-Maxima suppression of the source Image.
Use the algorithm proposed by Alexandru Telea.
MorphType
Enum class representing the ECVL morphology types.
Definition: imgproc.h:341
void GammaContrast(const Image &src, Image &dst, double gamma)
Adjust contrast by scaling each pixel value X to 255 * ((X/255) ** gamma).
void IntegralImage(const Image &src, Image &dst, DataType dst_type=DataType::float64)
Calculate the integral image of the source Image.
void MeanStdDev(const Image &src, std::vector< double > &mean, std::vector< double > &stddev)
Calculates the mean and the standard deviation of an Image.
void Flip2D(const ecvl::Image &src, ecvl::Image &dst)
Flips an Image.
std::vector< ecvl::Point2i > GetMaxN(const Image &src, size_t n)
Get the n maximum values that are in the source Image.
void Pepper(const Image &src, Image &dst, double p, bool per_channel=false, const unsigned seed=std::default_random_engine::default_seed)
Adds pepper noise (black pixels) to an Image.
void ElasticTransform(const Image &src, Image &dst, double alpha=34., double sigma=4., InterpolationType interp=InterpolationType::linear, BorderType border_type=BorderType::BORDER_REFLECT_101, const int &border_value=0, const unsigned seed=std::default_random_engine::default_seed)
Elastic deformation of input Image. Based on https://github.com/albumentations-team/albumentations/bl...
void Mirror2D(const ecvl::Image &src, ecvl::Image &dst)
Mirrors an Image.
std::array< int, 2 > Size2i
Definition: datatype.h:27