ENH: consider colors with de < 5 as the same

1. Use cie de2000 as color distance
2.Consider colors with de < 5 as the same color  when calculating
flush

jira:NONE

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: I4b451910a21c9db3471c63c270f1f120e3c5d160
(cherry picked from commit 72bc6f44cfab9145aecdb843ac4a03a9338a8cc6)
This commit is contained in:
xun.zhang
2025-08-24 23:18:23 +08:00
committed by Noisyfox
parent 179eab1355
commit b71d14b526
4 changed files with 277 additions and 41 deletions
+38 -2
View File
@@ -3,20 +3,56 @@
#include<unordered_map>
namespace FlushPredict
{
struct RGBColor
{
unsigned char r{ 0 };
unsigned char g{ 0 };
unsigned char b{ 0 };
RGBColor(unsigned char r_,unsigned char g_,unsigned char b_) :r(r_),g(g_),b(b_){}
RGBColor() = default;
};
struct LABColor
{
double l{ 0 };
double a{ 0 };
double b{ 0 };
LABColor() = default;
LABColor(double l_,double a_,double b_):l(l_),a(a_),b(b_){}
};
// transfer colour in RGB space to LAB space
LABColor RGB2LAB(const RGBColor& color);
// calculate DeltaE2000
float calc_color_distance(const LABColor& lab1, const LABColor& lab2);
float calc_color_distance(const RGBColor& rgb1, const RGBColor& rgb2);
// check if DeltaE is within the threshold. We consider colors within the threshold to be the same
bool is_similar_color(const RGBColor& from, const RGBColor& to, float distance_threshold = 5.0);
}
// Singleton pattern
class FlushVolPredictor
{
using RGB = FlushPredict::RGBColor;
public:
bool predict(const unsigned char src_r, const unsigned char src_g, const unsigned char src_b,
const unsigned char dst_r, const unsigned char dst_g, const unsigned char dst_b, float& flush);
bool predict(const RGB& from,const RGB& to , float& flush);
static FlushVolPredictor& get_instance();
private:
FlushVolPredictor(const std::string& data_file);
FlushVolPredictor(const FlushVolPredictor&) = delete;
FlushVolPredictor& operator=(const FlushVolPredictor&) = delete;
~FlushVolPredictor() = default;
uint64_t generate_hash_key(const RGB& from, const RGB& to);
private:
std::unordered_map<uint64_t, float> m_flush_map;
std::vector<RGB> m_colors;
bool m_valid;
};
#endif