Howto set gradient map on image/photo

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
waza123

Howto set gradient map on image/photo

Post by waza123 »

How to set Gradient Map (effect) on photo/image ?

Here what i need

Original:
Image

Gradient map (Photoshop):
Image


Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Howto set gradient map on image/photo

Post by fmw42 »

Convert image to grayscale. Then create a gradient as shown in viewtopic.php?f=1&t=13147 and apply the gradient using -clut.

convert image.jpg -colorspace gray grayimage.jpg

convert \( -size 1x1 xc:navy xc:yellow xc:navy +append \) \
-filter cubic -resize 256x1! -scale 256x20! gradient_lut.png

specify the colors that make your gradient look the way you want. see http://imagemagick.org/script/color.php

convert grayimage.jpg gradient_lut.png -clut coloredimage.jpg
waza123

Re: Howto set gradient map on image/photo

Post by waza123 »

Big thanks !!! works perfectly !

One more question:

How to use rgb(255, 0, 0) instead of defined words: navy yellow navy ?

In this command
convert \( -size 1x1 xc:navy xc:yellow xc:navy +append \) \
-filter cubic -resize 256x1! -scale 256x20! gradient_lut.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Howto set gradient map on image/photo

Post by fmw42 »

waza123 wrote:Big thanks !!! works perfectly !

One more question:

How to use rgb(255, 0, 0) instead of defined words: navy yellow navy ?

In this command
convert \( -size 1x1 xc:navy xc:yellow xc:navy +append \) \
-filter cubic -resize 256x1! -scale 256x20! gradient_lut.png
replace

xc:colorname

with

xc:"rgb(XX,YY,ZZ)"

for example for

xc:blue

you would have

xc:"rgb(0,0,255)"

you can also use hex color values

xc:"#0000ff"

see color definitions at http://imagemagick.org/script/color.php
waza123

Re: Howto set gradient map on image/photo

Post by waza123 »

Again Thanks !

And maybe one more question:

i know that the first pixel of image x:1 y:1 is background white

Orig:
Image

Step 1
Is there a way to replace white background of image with transperent background ?
Image

Step 2
I do gradient
Image

Step 3
Replace transperent with black background
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Howto set gradient map on image/photo

Post by fmw42 »

waza123 wrote:Again Thanks !

And maybe one more question:

i know that the first pixel of image x:1 y:1 is background white

Orig:
Image

Step 1
Is there a way to replace white background of image with transperent background ?
Image

Step 2
I do gradient
Image

Step 3
Replace transperent with black background
Image



Actually the first pixel is 0,0 in IM.

convert image -transparent white transparentimage.gif (or.png)

do your gradient operation (but not sure how the formerly white area may get changed anyway)

convert gradientimagewithtrasparent -alpha on -channel rgba -fill black -opaque none blackbackgroundimage
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Howto set gradient map on image/photo

Post by fmw42 »

I have created a new script, tricolorize, to achieve the original colorization effect.

See http://www.fmwconcepts.com/imagemagick/index.html
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Howto set gradient map on image/photo

Post by anthony »

I just recently fixed a bug in the -clut operator that prevented you re-coloring grayscale images using a gradient containing transparent and semi-transparent colors. To use this with -clut you needed to turn of the matte/alpha channel of the gray-scale image (so there was not alpha values for -clut to use, so it resorts to using the grayscale component) and set -channel RGBA.

See IM Examples, CLUT, recoloring with transparency
http://www.imagemagick.org/Usage/color/#clut_rgba

This bug fix is in the latest point release v6.4.9-8
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply