It still can not be your help, but it seems there is one way to exclude specific color, according to the document.
libjpeg9 has new -wipe option for jpegtran.
Code: Select all
A complementary lossless-wipe option is provided to discard (gray out)
data inside a given image region while losslessly preserving what is
outside:
-wipe WxH+X+Y
Wipe (gray out) a rectangular subarea of width W, height H
starting at point X,Y.
Yes, it does not change to the arbitrary color. It seems to replace it to #808080. (That's why I said it is no useful for you.)
Anyway I start from this image.
In my enviromnemt
Code: Select all
$ convert logo.jpg -format "%c" histogram:info: | sort -nr | head
226556: (255,255,255) #FFFFFF white
4471: ( 34, 62,146) #223E92 srgb(34,62,146)
2732: (255,254,255) #FFFEFF srgb(255,254,255)
1593: (254,255,255) #FEFFFF srgb(254,255,255)
1577: (255,255,253) #FFFFFD srgb(255,255,253)
1456: (255,253,255) #FFFDFF srgb(255,253,255)
893: (252,255,255) #FCFFFF srgb(252,255,255)
822: (255,255,251) #FFFFFB srgb(255,255,251)
754: (254,254,254) #FEFEFE srgb(254,254,254)
712: (255,252,255) #FFFCFF srgb(255,252,255)
So try to exclude #223E92.
Code: Select all
$ cp logo.jpg tmp.jpg
$ for i in `convert logo.jpg -depth 8 txt: | awk -F: '/#223E92/ {print $1}'`
> do
> X=`echo $i | awk -F, '{print $1}'`
> Y=`echo $i | awk -F, '{print $2}'`
> G="1x1+$X+$Y"
> echo $G
> jpegtran -wipe "$G" -outfile tmp2.jpg tmp.jpg
> mv tmp2.jpg tmp.jpg
> done | wc -l
4471
$ mv tmp.jpg result.jpg
check the result.
Code: Select all
$ convert result.jpg -format "%c" histogram:info: | grep -i 223E92
$ convert result.jpg -format "%c" histogram:info: | sort -nr | head
226543: (255,255,255) #FFFFFF white
11521: (128,128,128) #808080 fractal
2695: (255,254,255) #FFFEFF srgb(255,254,255)
1574: (254,255,255) #FEFFFF srgb(254,255,255)
1562: (255,255,253) #FFFFFD srgb(255,255,253)
1426: (255,253,255) #FFFDFF srgb(255,253,255)
881: (252,255,255) #FCFFFF srgb(252,255,255)
810: (255,255,251) #FFFFFB srgb(255,255,251)
754: (254,254,254) #FEFEFE srgb(254,254,254)
701: (255,252,255) #FFFCFF srgb(255,252,255)
Originally logo.jpg has 1 #808080
Code: Select all
$ convert logo.jpg -format "%c" histogram:info: | grep 808080
1: (128,128,128) #808080 fractal
So I expected to get 4472 #808080 pixels but it did not.
I don't understand what I missed, or the bug of jpegtran (comes from MacPort).
Code: Select all
$ jpegtran -v
Independent JPEG Group's JPEGTRAN, version 9a 19-Jan-2014
Copyright (C) 2014, Thomas G. Lane, Guido Vollbeding
As far as I tried, it wipes at least 16x16 area for one time for logo.jpg above.
And if I start with jpg created with
Code: Select all
convert logo: -quality 100 logo100.jpg
it wipes 8x8 area.
Probably it is related with this sampling factor.
Code: Select all
$ identify -format "%[jpeg:sampling-factor]\n" logo100.jpg
1x1,1x1,1x1
$ identify -format "%[jpeg:sampling-factor]\n" logo.jpg
2x2,1x1,1x1
but I don't know the detail of these values.