See above 2 posts. Sorry to belabor this.
With this last image example, I am getting different results from -remap than with my script.
With -remap:
convert \( 1cropped.jpeg +dither -colors 24 \) \
+dither +colors +dither -remap 1paintapic_palette.png 1cropped_im_remap_test2b.gif
convert 1cropped_im_remap_test2b.gif -format "%k" info:
19
or
convert \( 1cropped.jpeg +dither -colors 24 -depth 8 -write 1cropped_im_remap_test1b.gif \) \
-depth 8 +dither -remap 1paintapic_palette.png 1cropped_im_remap_test2b.gif
convert 1cropped_im_remap_test2b.gif -format "%k" info:
19
convert 1cropped_im_remap_test2b.gif -format "%c" histogram:info: | sort -r -k 1
60449: ( 82, 45, 36) #522D24 rgb(82,45,36)
52538: (173,165,157) #ADA59D rgb(173,165,157)
45662: ( 0, 0, 0) #000000 black
43666: (156, 48, 36) #9C3024 rgb(156,48,36)
34498: (230,224,232) #E6E0E8 rgb(230,224,232)
29293: (150,103, 73) #966749 rgb(150,103,73)
24955: (156,116,100) #9C7464 rgb(156,116,100)
15078: (101, 83, 59) #65533B rgb(101,83,59)
15062: (205,215,210) #CDD7D2 rgb(205,215,210)
14318: (186,186,186) #BABABA grey73
12939: (203,193,193) #CBC1C1 rgb(203,193,193)
11378: (175,138,123) #AF8A7B rgb(175,138,123)
9823: ( 41, 42, 39) #292A27 rgb(41,42,39)
9660: (151,152,154) #97989A rgb(151,152,154)
7939: (193,151,121) #C19779 rgb(193,151,121)
6321: (109, 98, 94) #6D625E rgb(109,98,94)
6135: (147, 80, 58) #93503A rgb(147,80,58)
3586: (121, 91,167) #795BA7 rgb(121,91,167)
2972: ( 80, 64,107) #50406B rgb(80,64,107)
With my script:
infile="1cropped.jpeg"
mapfile="1paintapic_palette.png"
Output:
convert 1cropped_remap4.gif -format "%k" info:
19
So the same number of colors, but the mapping is different!
Here is the list of colors that are remapped (from:to) and the minimum color distance found
dist=sqrt( ( (r1-r2)*(r1-r2)+(g1-g2)*(g1-g2)+(b1-b2)*(b1-b2) )/3 )
index=0; rgb(8,10,9):rgb(0,0,0); 9.03696
index=19; rgb(46,25,24):rgb(41,42,39); 13.404
index=26; rgb(69,58,87):rgb(80,64,107); 13.626
index=28; rgb(88,30,28):rgb(82,45,36); 10.4083
index=28; rgb(112,16,17):rgb(82,45,36); 26.4701
index=41; rgb(112,88,87):rgb(109,98,94); 7.25718
index=38; rgb(117,70,57):rgb(101,83,59); 11.9583
index=47; rgb(119,119,161):rgb(121,91,167); 16.5731
index=55; rgb(135,74,62):rgb(147,80,58); 8.0829
index=61; rgb(142,18,21):rgb(156,48,36); 20.9841
index=54; rgb(142,84,73):rgb(142,86,59); 8.16497
index=62; rgb(162,111,99):rgb(156,116,100); 4.54606
index=57; rgb(162,155,165):rgb(151,152,154); 9.14695
index=73; rgb(162,175,211):rgb(186,186,186); 20.9921
index=61; rgb(164,23,28):rgb(156,48,36); 15.843
index=70; rgb(177,135,120):rgb(175,138,123); 2.70801
index=70; rgb(180,148,141):rgb(175,138,123); 12.2338
index=79; rgb(183,203,228):rgb(205,215,210); 17.8139
index=75; rgb(197,139,121):rgb(193,151,121); 7.30297
index=75; rgb(198,150,138):rgb(193,151,121); 10.247
index=69; rgb(198,165,161):rgb(173,165,157); 14.6173
index=77; rgb(200,188,198):rgb(203,193,193); 4.43471
index=87; rgb(204,215,239):rgb(230,224,232); 16.3911
index=87; rgb(211,216,230):rgb(230,224,232); 11.9583
convert 1cropped_remap4.gif -format "%c" histogram:info: | sort -r -k 1
60449: ( 82, 45, 36) #522D24 rgb(82,45,36)
45662: ( 0, 0, 0) #000000 black
43666: (156, 48, 36) #9C3024 rgb(156,48,36)
42585: (175,138,123) #AF8A7B rgb(175,138,123)
34498: (230,224,232) #E6E0E8 rgb(230,224,232)
29293: (142, 86, 59) #8E563B rgb(142,86,59)
24955: (156,116,100) #9C7464 rgb(156,116,100)
21978: (193,151,121) #C19779 rgb(193,151,121)
15078: (101, 83, 59) #65533B rgb(101,83,59)
15062: (205,215,210) #CDD7D2 rgb(205,215,210)
14318: (186,186,186) #BABABA grey73
12939: (203,193,193) #CBC1C1 rgb(203,193,193)
9823: ( 41, 42, 39) #292A27 rgb(41,42,39)
9660: (151,152,154) #97989A rgb(151,152,154)
7292: (173,165,157) #ADA59D rgb(173,165,157)
6321: (109, 98, 94) #6D625E rgb(109,98,94)
6135: (147, 80, 58) #93503A rgb(147,80,58)
3586: (121, 91,167) #795BA7 rgb(121,91,167)
2972: ( 80, 64,107) #50406B rgb(80,64,107)