Answer the question
In order to leave comments, you need to log in
How to speed up the site (algorithm for calculating the nearest color from a known color palette)?
Hello,
I have a php script. Main tasks:
1. Analysis of the dominant colors of the image
2. Matching the dominant color to one of the colors in a known palette
The whole thing works on php gd.
Namely:
1. Color selection by palette - imagecolorclosest
2. Formula - nearest color -
$diff = ( sqrt(pow($r1,2) + pow($g1,2)) + sqrt(pow($g1,2) + pow($b1,2)) + sqrt(pow($b1,2) + pow($r1,2))) / 3;
$diff = $r1 + $g1 + $b1;
Answer the question
In order to leave comments, you need to log in
They threw off a link not to the main one, as it should be? Error at the bottom of the main "Article".
The function you provided in the comments clearly lacks two things:
1. Caching, so as not to repeat the calculation for the color that has already been calculated. I foresee an increase in speed by a couple of orders of magnitude.
2. Understanding that in order to find ONE optimal value for hell, you don’t need to collect an entire array and sort it. Have you ever seen an algorithm for finding the smallest value in an array?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question