Page 1 of 1

Possible bug -draw polygon IM 6.9.2.8 Q16 Mac OSX Snow Leopard

Posted: 2015-12-07T16:20:42-07:00
by fmw42
Input:
Image

I am trying to make the bottom of the image transparent along a sine curve from one side to the other. I compute a sine curve with -function sinusoid and write to txt. Then I get the y coordinates and recompute to floating point accuracy so that it will be anti-aliased along the sine curve. I then get the two bottom corners and add those to the list of coordinates and then draw a mask image for the alpha channel as black at the bottom on a white background. Afterwards there is one non-transparent pixel on the left side in the transparent region at 0,149 which should have been transparent. Note: you need to expand the mask to see the one white dot on the left side in the black region.

Code: Select all

infile="lena.jpg"
amplitude=10
row=128
ww=`convert -ping "$infile" -format "%w" info:`
hh=`convert -ping "$infile" -format "%h" info:`
wm1=$((ww-1))
hm1=$((hh-1))
qrange=`convert xc: -format "%[fx:quantumrange]" info:`
amp=`convert xc: -format "%[fx:$amplitude/$qrange]" info:`
off=`convert xc: -format "%[fx:$row/$qrange]" info:`
coords=`convert -size 1x256 gradient: -rotate 90 -function sinusoid "1,180,0.5,0.5" txt:- |\
sed -n 's/^\([^,]*\),.*: [(]\([^,]*\).*$/\1,\2/p'`
xArr=(`echo "$coords" | cut -d, -f1`)
yArr=(`echo "$coords" | cut -d, -f2`)
len=${#xArr[*]}
#echo "len=$len;"
#echo "${xArr[*]}
#echo "${yArr[*]}
for ((i=0; i<len; i++)); do
yy=`echo "scale=6; $amplitude*${yArr[$i]}*2/$qrange+$row" | bc`
coordArr[$i]="${xArr[$i]},$yy"
done
coords="${coordArr[*]} $wm1,$hm1 0,$hm1"
convert "$infile" \
\( +clone -fill white -colorize 100 -fill black -draw "polygon $coords" -alpha off -write tmp2.png \) \
-compose copy_opacity -composite lena_sine_crop2.png
Image
Image

I even tried closing the polygon by adding the first sine wave point (rounded to 0,138) and added -stroke black -strokewidth 2, but neither of these changes made a difference and did not get rid of the bad point at 0,149.



However, if I draw the mask the opposite polarity (white at the top on black background), it works fine.

Code: Select all

infile="lena.jpg"
amplitude=10
row=128
ww=`convert -ping "$infile" -format "%w" info:`
hh=`convert -ping "$infile" -format "%h" info:`
wm1=$((ww-1))
hm1=$((hh-1))
qrange=`convert xc: -format "%[fx:quantumrange]" info:`
amp=`convert xc: -format "%[fx:$amplitude/$qrange]" info:`
off=`convert xc: -format "%[fx:$row/$qrange]" info:`
coords=`convert -size 1x256 gradient: -rotate 90 -function sinusoid "1,180,0.5,0.5" txt:- |\
sed -n 's/^\([^,]*\),.*: [(]\([^,]*\).*$/\1,\2/p'`
xArr=(`echo "$coords" | cut -d, -f1`)
yArr=(`echo "$coords" | cut -d, -f2`)
len=${#xArr[*]}
#echo "len=$len;"
#echo "${xArr[*]}
#echo "${yArr[*]}
for ((i=0; i<len; i++)); do
yy=`echo "scale=6; $amplitude*${yArr[$i]}*2/$qrange+$row" | bc`
coordArr[$i]="${xArr[$i]},$yy"
done
coords="$wm1,0 0,0 ${coordArr[*]}"
convert "$infile" \
\( +clone -fill black -colorize 100 -fill white -draw "polygon $coords" -alpha off -write tmp3.png \) \
-compose copy_opacity -composite lena_sine_crop3.png

Image
Image

Re: Possible bug -draw polygon IM 6.9.2.8 Q16 Mac OSX Snow Leopard

Posted: 2015-12-15T04:53:18-07:00
by magick
Modify your coords variable as follows:

coords="$wm1,$hm1 0,$hm1 ${coordArr[*]}"

We did not investigate why this works or why the other form fails.