Skip to content
This repository was archived by the owner on Nov 26, 2022. It is now read-only.

Wrong calculation of a Threshold distance #20

Closed
MetLob opened this issue Sep 29, 2015 · 2 comments
Closed

Wrong calculation of a Threshold distance #20

MetLob opened this issue Sep 29, 2015 · 2 comments
Labels
Milestone

Comments

@MetLob
Copy link
Contributor

MetLob commented Sep 29, 2015

public static int FindNextColor(Color c, Color[] palette, decimal threshold = 0)
in Ekona.Images.Actions.cs

If a color represented as vector with coordinates R G B
Distance between two vector equals to |x - y|
Then the threshold value is a radius of a toleranced sphere.

But in the FindNextColor method distance calculated as | |x| - |y| |...

Error or I'm not understanding of a color spectre stucture...

@MetLob
Copy link
Contributor Author

MetLob commented Oct 7, 2015

I think, next changes fix this:

Old code:

            double modulec = Math.Sqrt(palette[i].R * palette[i].R + palette[i].G * palette[i].G + palette[i].B * palette[i].B);
            decimal distance = (decimal)Math.Abs(module - modulec);

New code:

            double x = palette[i].R - c.R;
            double y = palette[i].G - c.G;
            double z = palette[i].B - c.B;
            decimal distance = (decimal)Math.Sqrt(x * x + y * y + z * z);

@pleonex pleonex added the bug label Feb 28, 2016
@pleonex pleonex added this to the Version 0.9.1 milestone Feb 28, 2016
@pleonex
Copy link
Owner

pleonex commented Feb 28, 2016

You are absolutely right! I will fix it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants