@@ -102,7 +102,7 @@ function rgb2lab(rgb) {
102
102
103
103
class ImageColorUtils {
104
104
constructor ( params ) {
105
- const { origin, mockMovePx = 30 , boundaryValue = 10 , ParticleSize = 4 , width, height, onload, } = params || { } ;
105
+ const { origin, mockMovePx = 30 , boundaryValue = 10 , ParticleSize = 8 , width, height, onload, } = params || { } ;
106
106
if ( ! origin ) {
107
107
throw new Error ( 'Origin is necessary' ) ;
108
108
}
@@ -406,6 +406,7 @@ class ImageColorUtils {
406
406
const similarColorsMap = { } ;
407
407
const res = [ ] ;
408
408
const boundaryValue = 25 ;
409
+ const type = 'lab' ;
409
410
let lastColor ;
410
411
for ( let x = 1 ; x < this . canvas . width ; x += ImageColorUtils . ParticleSize ) {
411
412
for ( let y = 1 ; y < this . canvas . height ; y += ImageColorUtils . ParticleSize ) {
@@ -420,11 +421,11 @@ class ImageColorUtils {
420
421
}
421
422
else if ( similarValues . length &&
422
423
lastColor &&
423
- ImageColorUtils . compare ( rgba , lastColor , ImageColorUtils . boundaryValue ) ) {
424
+ ImageColorUtils . compare ( rgba , lastColor , ImageColorUtils . boundaryValue , type ) ) {
424
425
let insert = false ;
425
426
for ( const similarValue of similarValues ) {
426
- if ( ImageColorUtils . compare ( rgba , similarValue [ 0 ] , boundaryValue , 'lab' ) ||
427
- ImageColorUtils . compare ( rgba , similarValue [ similarValue . length - 1 ] , boundaryValue , 'lab' ) ) {
427
+ if ( ImageColorUtils . compare ( rgba , similarValue [ similarValue . length - 1 ] , boundaryValue , type ) &&
428
+ ImageColorUtils . compare ( rgba , similarValue [ Math . floor ( similarValue . length / 2 ) ] , boundaryValue , type ) ) {
428
429
similarValue . push ( rgba ) ;
429
430
insert = true ;
430
431
}
@@ -438,9 +439,10 @@ class ImageColorUtils {
438
439
const values = Object . values ( similarColorsMap ) ;
439
440
values
440
441
. sort ( ( x , y ) => ( x . length < y . length ? 1 : - 1 ) )
442
+ . filter ( ( item ) => item . length > 5 )
441
443
. forEach ( ( item ) => {
442
- if ( ! res . some ( ( value ) => ImageColorUtils . compare ( value , ImageColorUtils . getMost ( item ) , boundaryValue , 'lab' ) ) ) {
443
- res . push ( ImageColorUtils . getMost ( item ) ) ;
444
+ if ( ! res . some ( ( value ) => ImageColorUtils . compare ( value , ImageColorUtils . getMedian ( item ) , boundaryValue , type ) ) ) {
445
+ res . push ( ImageColorUtils . getMedian ( item ) ) ;
444
446
}
445
447
} ) ;
446
448
return {
0 commit comments