convert's equivalent to (gimp-brightness-contrast)

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
shlomif

convert's equivalent to (gimp-brightness-contrast)

Post by shlomif »

Hi all!

How can I emulate GIMP's (gimp-brightness-contrast) using ImageMagick's convert?

I have the following GIMP script, which I've wrapped in a gimp-console:

Code: Select all

(let*
 ((in-fn "Input.bmp")
  (out-fn "Input_out.bmp")
  (brightness -90)
  (contrast 116)
  (img (car (gimp-file-load 1 in-fn in-fn)))
  (drawable (car (gimp-image-get-active-drawable img))))
 (gimp-brightness-contrast drawable brightness contrast)
 (if (not (car (gimp-drawable-is-gray drawable)))
     (gimp-image-convert-grayscale img))
 (gimp-file-save 1 img drawable out-fn out-fn))
The values of brightness and contrast should be settable. Reading from
the GIMP documentation:

<<<
This procedures allows the brightness and contrast of the specified
drawable to be modified. Both 'brightness' and 'contrast' parameters
are defined between -127 and 127."
>>>

And you can find the source for it here:

http://www.koders.com/c/fid5EF9F42E3382 ... ontrast#L1

Regards and thanks in advance,

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

Re: convert's equivalent to (gimp-brightness-contrast)

Post by fmw42 »

I don't think IM can use gimp's fooscript or whatever they call it. IM is coded in C.

However...
This is not exactly the same as GIMP, but you might try my unix bash script, bcimage, at http://www.fmwconcepts.com/imagemagick/index.html

In IM, you can control the brightness using the -modulate function (as well as saturation and hue) and IM also has a -contrast function. (My script however, does not use either, but goes at it a more direct way by building a lookup table to adjust brightness and contrast)

see http://www.imagemagick.org/script/comma ... ptions.php

Fred

PS. You can also build your own piece-wise linear lookup table transpformation using my script, plm or a spline interpolated look-up table transformation using my script, curves.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert's equivalent to (gimp-brightness-contrast)

Post by fmw42 »

Here is a short set of IM commands to do the equivalent to my script, bcimage, without all the argument prompting and trapping and documentation. This is the guts of the script except here I use -function polynomial rather than computing a lookup table as in my script.

You can do the computations for the slope and intcp arguments that lead up to the convert $infile -function polynomial "$slope,$intcp" $outfile any way you can within your Window Batch script. I used some unix variables created by using IM -fx calculations. But in my original script I used unix bc to do the calcs. Presumably you have some way to do those computations to set up slope and intcp arguments.

You can get help from other Window users, such as Bonzo or el_supremo on the Discourse forum if you need help. They are two Windows users that I know about. Unfortunately I don't use or know much about Windows scripting as I use a Mac.


infile="zelda3.png"
bri=20
con=20
inname=`convert $infile -format "%t" info:`
outfile1=${inname}_b${bri}_c${con}_A.png
diffc=`convert xc: -format "%[fx:100-$con]" info:`
con=`convert xc: -format "%[fx:$diffc<=0.1?99.0:$con]" info:`
arg=`convert xc: -format "%[fx:pi*((($con*$con)/20000) + (3*$con/200))/4]" info:`
slope=`convert xc: -format "%[fx:1+atan($arg)]" info:`
slope=`convert xc: -format "%[fx:$slope<0?0:$slope]" info:`
echo "diffc=$diffc; con=$con; arg=$arg; slope=$slope;"
pivot=`convert xc: -format "%[fx:(100-$bri)/200]" info:`
intcpbri=`convert xc: -format "%[fx:$bri/100]" info:`
intcpcon=`convert xc: -format "%[fx:$pivot*(1-$slope)]" info:`
intcp=`convert xc: -format "%[fx:$intcpbri+$intcpcon]" info:`
echo "pivot=$pivot; intcpbri=$intcpbri; intcpcon=$intcpcon; intcp=$intcp;"
convert $infile -function polynomial "$slope,$intcp" $outfile1


See the notes in my script for a discussion of the formulae that I used for these calculations and the graphs on my web page at http://www.fmwconcepts.com/imagemagick/ ... /index.php


Regards,

Fred

P.S. Windows users should look at the recently revised page at http://www.imagemagick.org/Usage/windows/ thanks to Wolfgang Hugemann
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert's equivalent to (gimp-brightness-contrast)

Post by fmw42 »

another tool similar to -function polynomial is -cdl (color decision list) that allows for each channel to be adjusted using slope, offset and gamma. see http://www.imagemagick.org/script/comma ... ns.php#cdl see also http://en.wikipedia.org/wiki/ASC_CDL
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert's equivalent to (gimp-brightness-contrast)

Post by fmw42 »

the IM team is working to convert my bcimage script into an IM function called -brightness-contrast. it is hoped to be available in IM 6.5.9.0
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert's equivalent to (gimp-brightness-contrast)

Post by fmw42 »

a new function, -brightness-contrast, is now available in IM 6.5.9-0. see http://www.imagemagick.org/script/comma ... s-contrast
Post Reply