Greyscale half of image diagonally solution tips? Using rmagick

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
gilbert
Posts: 2
Joined: 2016-01-07T17:23:42-07:00
Authentication code: 1151

Greyscale half of image diagonally solution tips? Using rmagick

Post by gilbert »

https://i.imgur.com/FRqephU.jpg

Any tips on achieving this output?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Greyscale half of image diagonally solution tips? Using rmagick

Post by fmw42 »

I do not know RMagick, but perhaps you can convert from the following command lines. I had to crop out your input image. It would be best in the future if you provide two separate images. Also always provide your IM version and platform. See viewtopic.php?f=1&t=9620

Code: Select all

size=`convert FRqephU.png -format "%wx%h" info:`
ww=`echo $size | cut -dx -f1`
hh=`echo $size | cut -dx -f2`
p1=0,0
p2="$((ww-1)),0"
p3="0,$((hh-1))"
echo "p1=$p1; p2=$p2; p3=$p3;"
convert FRqephU.png \
\( -clone 0 -colorspace gray \) \
\( -clone 0 -fill black -colorize 100 \
-fill white -draw "polygon $p1 $p2 $p3" \) \
-alpha off -compose over -composite result.png
gilbert
Posts: 2
Joined: 2016-01-07T17:23:42-07:00
Authentication code: 1151

Re: Greyscale half of image diagonally solution tips? Using rmagick

Post by gilbert »

Thanks so much. That's pretty close to what I need; it's just coming out a bit dark. How would I go about making the result lighter?

https://imgur.com/a/n4LgP - here's an album (original, expected, actual).

I really appreciate the help. Are you Fred?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Greyscale half of image diagonally solution tips? Using rmagick

Post by fmw42 »

Yes, Fred here.

What version of Imagemagick and what platform are you using? Please always provide that information since syntax and IM may work differently. see viewtopic.php?f=1&t=9620

Your problem may be due to older versions of IM using linear grayscale rather than sRGB or when RGB and sRGB were reversed.

Since I do not know what version of IM you are using try one of the following:

Code: Select all

size=`convert FRqephU.png -format "%wx%h" info:`
ww=`echo $size | cut -dx -f1`
hh=`echo $size | cut -dx -f2`
p1=0,0
p2="$((ww-1)),0"
p3="0,$((hh-1))"
echo "p1=$p1; p2=$p2; p3=$p3;"
convert FRqephU.png \
\( -clone 0 -set colorspace RGB -colorspace gray \) \
\( -clone 0 -fill black -colorize 100 \
-fill white -draw "polygon $p1 $p2 $p3" \) \
-alpha off -compose over -composite result.png

Code: Select all

size=`convert FRqephU.png -format "%wx%h" info:`
ww=`echo $size | cut -dx -f1`
hh=`echo $size | cut -dx -f2`
p1=0,0
p2="$((ww-1)),0"
p3="0,$((hh-1))"
echo "p1=$p1; p2=$p2; p3=$p3;"
convert FRqephU.png \
\( -clone 0 -set colorspace sRGB -colorspace gray \) \
\( -clone 0 -fill black -colorize 100 \
-fill white -draw "polygon $p1 $p2 $p3" \) \
-alpha off -compose over -composite result.png

Code: Select all

size=`convert FRqephU.png -format "%wx%h" info:`
ww=`echo $size | cut -dx -f1`
hh=`echo $size | cut -dx -f2`
p1=0,0
p2="$((ww-1)),0"
p3="0,$((hh-1))"
echo "p1=$p1; p2=$p2; p3=$p3;"
convert FRqephU.png \
\( -clone 0 -grayscale Rec709Luminance \) \
\( -clone 0 -fill black -colorize 100 \
-fill white -draw "polygon $p1 $p2 $p3" \) \
-alpha off -compose over -composite result.png

Code: Select all

size=`convert FRqephU.png -format "%wx%h" info:`
ww=`echo $size | cut -dx -f1`
hh=`echo $size | cut -dx -f2`
p1=0,0
p2="$((ww-1)),0"
p3="0,$((hh-1))"
echo "p1=$p1; p2=$p2; p3=$p3;"
convert FRqephU.png \
\( -clone 0 -grayscale Rec601Luminance \) \
\( -clone 0 -fill black -colorize 100 \
-fill white -draw "polygon $p1 $p2 $p3" \) \
-alpha off -compose over -composite result.png

see viewtopic.php?f=4&t=21269 and http://www.imagemagick.org/script/comma ... #grayscale and http://www.imagemagick.org/script/comma ... #intensity

If none of the above work, then it could be a profile issue. But I won't look into that until I hear back from you.
Post Reply