enc_detect_dots.h (2342B)
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 // We attempt to remove dots, or speckle from images using Gaussian blur. 7 #ifndef LIB_JXL_ENC_DETECT_DOTS_H_ 8 #define LIB_JXL_ENC_DETECT_DOTS_H_ 9 10 #include <array> 11 #include <cstddef> 12 #include <cstdint> 13 #include <vector> 14 15 #include "lib/jxl/base/data_parallel.h" 16 #include "lib/jxl/base/rect.h" 17 #include "lib/jxl/base/status.h" 18 #include "lib/jxl/enc_patch_dictionary.h" 19 #include "lib/jxl/image.h" 20 21 namespace jxl { 22 23 struct GaussianDetectParams { 24 double t_high = 0; // at least one pixel must have larger energy than t_high 25 double t_low = 0; // all pixels must have a larger energy than tLow 26 uint32_t maxWinSize = 0; // discard dots larger than this containing window 27 double maxL2Loss = 0; 28 double maxCustomLoss = 0; 29 double minIntensity = 0; // If the intensity is too low, discard it 30 double maxDistMeanMode = 0; // The mean and the mode must be close 31 size_t maxNegPixels = 0; // Maximum number of negative pixel 32 size_t minScore = 0; 33 size_t maxCC = 50; // Maximum number of CC to keep 34 size_t percCC = 15; // Percentage in [0,100] of CC to keep 35 }; 36 37 // Ellipse Quantization Params 38 struct EllipseQuantParams { 39 size_t xsize; // Image size in x 40 size_t ysize; // Image size in y 41 size_t qPosition; // Position quantization delta 42 // Quantization for the Gaussian sigma parameters 43 double minSigma; 44 double maxSigma; 45 size_t qSigma; // number of quantization levels 46 // Quantization for the rotation angle (between -pi and pi) 47 size_t qAngle; 48 // Quantization for the intensity 49 std::array<double, 3> minIntensity; 50 std::array<double, 3> maxIntensity; 51 std::array<size_t, 3> qIntensity; // number of quantization levels 52 // Extra parameters for the encoding 53 bool subtractQuantized; // Should we subtract quantized or detected dots? 54 float ytox; 55 float ytob; 56 57 void QuantPositionSize(size_t* xsize, size_t* ysize) const; 58 }; 59 60 // Detects dots in XYB image. 61 StatusOr<std::vector<PatchInfo>> DetectGaussianEllipses( 62 const Image3F& opsin, const Rect& rect, const GaussianDetectParams& params, 63 const EllipseQuantParams& qParams, ThreadPool* pool); 64 65 } // namespace jxl 66 67 #endif // LIB_JXL_ENC_DETECT_DOTS_H_