Page 1 of 1

Colorspaces and porting from IM 6.6.x

Posted: 2015-08-27T10:39:30-07:00
by coloring
I have an old script that is used to do clean up some images before OCR. The script has grown organically but it is "well oiled" and it has done its job perfectly in the past years. Now we moved to a new Ubuntu version that ships version 6.7.7-10 and the script is producing horrible results. We traced it down to a change in the way default colorspaces are handled, as suggested by http://www.imagemagick.org/script/color-management.php and viewtopic.php?t=20501.

I tried sprinkling some -set colorspace RGB -colorspace RGB around but it did not work.

The core of my script is

Code: Select all

cat "$workdir/src.png" |
	# remove shades of gray1
	convert png:fd:0 -fuzz 10% -fill black -opaque 'rgb(159,153,153)' png:fd:1 |
	tee /tmp/step1.png |

	# remove shades of gray2
	convert png:fd:0 -fuzz 10% -fill black -opaque 'rgb(109,97,109)' png:fd:1 |
	tee /tmp/step2.png |

	# remove shades of gray3
	convert png:fd:0 -fuzz 10% -fill black -opaque 'rgb(178,185,193)' png:fd:1 |
	tee /tmp/step3.png |

	# convert to grayscale with an emphasis on reds
	convert png:fd:0 \
		\( -clone 0 -channel GR -separate +channel -evaluate-sequence mean \) \
		\( -clone 0 -channel RB -separate +channel -evaluate-sequence mean \) \
		-delete 0 -evaluate-sequence mean \
		png:fd:1 |
	tee /tmp/step4.png |

	# black text on white background
	convert png:fd:0 -threshold 50% -negate png:fd:1 |
	cat > "$workdir/bw.png"
This script works perfectly with IM 6.6.9 but produces completely wrong results with IM 6.7.7-10.

How can I change this script to work in the same way it both version or, at least, only in version 6.7.7 but in the correct way?

Re: Colorspaces and porting from IM 6.6.x

Posted: 2015-08-27T10:47:20-07:00
by snibgo
My advice: don't "upgrade" to 6.7.7. That's like "upgrading" an old but reliable car to another old and different (and very weird) car.

6.7.7 and similar version were confused about RGB/sRGB colourspaces, and especially when the image was grayscale. Upgrade to the current version.

Re: Colorspaces and porting from IM 6.6.x

Posted: 2015-08-27T10:57:13-07:00
by coloring
For what is worth I'd stay with 6.6.9, but we would like to use what comes with the current Ubuntu LTS, and that is 6.7.7. :(

Re: Colorspaces and porting from IM 6.6.x

Posted: 2015-08-27T11:04:13-07:00
by fmw42
Unfortunately, 6.7.7 was during a major change in colorspace and may not be fully correct. See viewtopic.php?f=4&t=21269. So Ubuntu picked a very unstable release.

Re: Colorspaces and porting from IM 6.6.x

Posted: 2015-08-27T11:28:15-07:00
by coloring
Just as a workaround, isn't there a way out of RGB/sRGB? The intermediate files do not need to be in PNG format so anything will do.

WRT Ubuntu, the LTS will be stuck on 6.7.7 until 16.04 LTS: https://bugs.launchpad.net/ubuntu/+sour ... ug/1179054 (15.04 is not an LTS).

Re: Colorspaces and porting from IM 6.6.x

Posted: 2015-08-27T11:45:28-07:00
by fmw42
try adding either

-set colorspace RGB
or
-set colorspace sRGB

before -channel in your commands. I am not sure which is needed, because the releases at that time were undergoing a swap of RGB and sRGB and grayscale (separate channels) were considered non-linear (sRGB) at one time, then linear (RGB) at another time, then back to non-linear again.

Re: Colorspaces and porting from IM 6.6.x

Posted: 2015-08-27T12:08:13-07:00
by coloring
Using -set colorspace RGB also before -channel worked. I had already put that command everywhere, but not inside the expression.

Thank you very much fmw42!

Re: Colorspaces and porting from IM 6.6.x

Posted: 2015-08-27T12:14:30-07:00
by fmw42
Glad to hear that was all that was needed.