[magick-users] RE: Advanced 'Unsharp Mask' technique (Claus Cyrny)

Fred Weinhaus fmw at alink.net
Sun Sep 16 13:37:47 PDT 2007


Sending again as my email font got messed up in the prevous message.

Fred




Claus,

I can see two problems right away. I will have to look into your 
script in more detail regarding the unsharp masking and the use of 
-mask, -edge and -usharp. However there are the several errors that I 
see right away.

1) You need to define your tmp files and setup to have them 
auto-deleted after completion (you can use .png or .miff or whatever 
format you want. For example, as Anthony showed me...

# set directory for temporary files
dir="."    # suggestions are dir="." or dir="/tmp"
tmp0="$dir/unsharp_0_$$.png"
tmp1="$dir/unsharp_1_$$.png"
tmp2="$dir/unsharp_2_$$.png"
tmp1p="$dir/unsharp_1_$$.png"
tmp2p="$dir/unsharp_2_$$.png"
trap "rm -f  $tmp0 $tmp1 $tmp2 $tmp3 $tmp1p $tmp2p; exit 0" 0
trap "rm -f $tmp0 $tmp1 $tmp2 $tmp3 $tmp1p $tmp2p; exit 1" 1 2 3 15

2) Your conversion to HSL should be

convert $1 -colorspace HSL -channel R -separate $tmp0
convert $1 -colorspace HSL -channel G -separate $tmp1
convert $1 -colorspace HSL -channel B -separate $tmp2

as you have it all three $tmp file are the HUE channel. In mine 
above, tmp0 is the hue, tmp1 is the saturation and tmp2 is the 
lightness.

3) In your steps

convert -mask $tmp2
convert $tmp2 -edge 2.5
convert $tmp2 -unsharp 2.0


The first has no input and the second and third have no output


4) Your output $1.tiff will take the input, for example image.jpg and 
make the output image.jpg.tiff. I am not sure that you want that. You 
may want to strip off the suffix on the input and then add the new 
suffix to create the output. For example.


inname=`echo "$1" | sed -n 's/^\([^.]*\)[.][^.]*$/\1/ p'`
outfile=$inname.tiff

use $outfile where you have $1.tiff


Hope this helps.

Fred
__________________________



>Hi all,
>
>here's the first draft of a shell script I wrote, which is supposed
>to be an advanced 'Unsharp Mask' technique (thanks to Anthony
>for his suggestions).
>
>The only problem is that the script, as it is now, results in error
>messages right at the beginning ('No command convert' or to
>the effect). This is most likely a syntax error on my part.
>
>What this script is supposed to do, is:
>
>1. Convert an RGB image into 'HSL'.
>2. Copy the 'L' Channel into a mask.
>3. Apply an edge detection to it.
>4. Apply a  Gaussian Blur to it .
>5. Make a selection out of the mask (don't know
>if this is necessary in IM; I would proceed like this
>in a bitmap editor).
>6. Select all the channels ('H','S', and 'L', and apply
>the final  'Unsharp Mask' filter to them.
>7. Convert the image back to RGB.
>
>My script:
>
>--- begin ---
>
>#!/bin/sh
>
>PATH=/home/ccyrny/Grafik/scripts; export PATH
>
>convert $1 -colorspace HSL -channel R -separate $tmp0
>convert $1 -colorspace HSL -channel R -separate $tmp1
>convert $1 -colorspace HSL -channel R -separate $tmp2
>
>convert -mask $tmp2
>convert $tmp2 -edge 2.5
>convert $tmp2 -unsharp 2.0
>
>convert $tmp0 - colorspace $colormodel $tmp0 -compose CopyRed -composite \
>     $tmp1p -compose CopyGreen -composite \
>     $tmp2p -compose CopyGreen -composite \
>     -colorspace RGB $1.tiff
>
>convert +mask
>
>--- end ---
>
>Can anyone see what mistakes I made here?
>
>TIA,
>
>Claus
>
>P.S.: After taking a look at the script again, I see that
>at least the two steps right after 'convert -mask $tmp2'
>are not correct, because I don't want to work with the
>'L' channel ($tmp2) as it is, but with the mask I (hopefully)
>created out of $tmp2.
>
>Fred: This is the script you wanted to know about!
>
>--
>Home Page        - http://home.arcor.de/ccyrny/            [in English]
>graf-o-matic 2.0 - http://grafomatic01.twoday.net/         [in German]


More information about the Magick-users mailing list