Convert image to monochrome using MSL

Discuss the conjure program and the Magick Scripting Language (MSL) here. MSL is an XML-based wrapper to the ImageMagick image-processing functions.
Post Reply
twardega

Convert image to monochrome using MSL

Post by twardega »

I am new to IM and need some help with MSL. I would like to use MSL to convert photographs to monochrome MONO format.
I need to do the following:
- resize the image to 160x120 pixels
- rotate 180 degrees
- everything black or dark gray needs to be black
- everything else (all other colors dark or light) need to be white

Here is the first version of MSL that does not do exactly what I like because it converts colors to grayscale before creating a monochrome image:
<image>
<read filename="input.jpg" />
<resize width="160" height="120" />
<rotate degrees="180" />
<quantize dither="true" colors="2" colorspace="gray" />
<normalize />
<write filename="output.mono" />
</image>

Any ideas for accomplishing what I need or doing things better will be greatly appreciated!
twardega

Re: Convert image to monochrome using MSL

Post by twardega »

OK. Maybe a different question. I would like to do the following in MSL using 1 conjure call. This series of calls converts an image input.jpg to BW out.gif using several intermediate steps - this is a local thresholding method shown on Fred's ImageMagick scripts site (http://www.fmwconcepts.com/imagemagick/ ... /index.php) This works great for what I need, but I would like to use MSL to do this and avoid creating intermediate files. I will greatly appreciate your advice on how to use MSL in this case.

convert -quiet -regard-warnings input.jpg -colorspace Gray -alpha off +repage 1_A.mpc
convert 1_A.mpc -negate 1_A.mpc
convert 1_A.mpc -blur "0x8" 1_M.mpc
convert 1_A.mpc 1_M.mpc -compose difference -composite -gamma 2 1_S.mpc
convert 1_A.mpc 1_M.mpc +swap -compose minus -composite ( 1_S.mpc -evaluate multiply 0.2 ) \
+swap -compose minus -composite -threshold 1 1_T.mpc
convert 1_T.mpc -negate out.gif
Post Reply