Page 1 of 1

brightness curve

Posted: 2009-09-18T09:35:01-07:00
by cedricb
Hi,

I'm just wondering how can I apply a brightness curve to an image? ...something like that:

Image

I'm bit lost after this step:

Code: Select all

im_fx_curves -c 0,0 0.125,0.375 0.25,0.625 0.5,0.875 1,1

Regards,
Ced.

Re: brightness curve

Posted: 2009-09-18T09:45:52-07:00
by fmw42
If you have the data as x,y points, you can draw a filled curve in an image with -draw such that it is white below and black above. Then average the rows down to one row. That becomes a look up table that can be applied to any image using -clut.

see my tidbits example at: http://www.fmwconcepts.com/imagemagick/ ... raph2image

see my plm script at: http://www.fmwconcepts.com/imagemagick/plm/index.php

see my curves script at: http://www.fmwconcepts.com/imagemagick/curves/index.php

see -clut at http://www.imagemagick.org/script/comma ... s.php#clut and
http://www.imagemagick.org/Usage/color/#clut

Re: brightness curve

Posted: 2009-11-11T06:47:57-07:00
by cedricb
I'm resurrecting this post... ;-)

I can apply my brightness curve using your "curves" script like this:

Code: Select all

./curves "0,0 12.5,37.5 25,62.5 50,87.5 100,100" image.tiff image_b.tiff
If I want to produce a layer mask for this brightness curve (like in Photoshop). How can I do that?

Then, I'll overlay the mask to the original image to get the final brightened image. I would like to create a mask so I can apply further manipulation (like a gaussian blur) before overlaying to the original image.

Re: brightness curve

Posted: 2009-11-11T06:57:34-07:00
by cedricb
a bit of brainy illumination...

Code: Select all

composite -compose CopyOpacity \( image.tiff -negate \) image_b.tiff mask.tiff

Re: brightness curve

Posted: 2009-11-11T07:14:47-07:00
by cedricb
I would like to achieve the same effect than this http://translate.google.com/translate?u ... N&ie=UTF-8; BRIGHTNESS ADJUSTMENT LAYER (4 additional steps)

At the moment I've done step 1... ;-)

Re: brightness curve

Posted: 2009-11-11T11:01:59-07:00
by fmw42
I don't follow that all, but this may be of interest in using the same curve for many images. See -hald-clut at
http://www.imagemagick.org/script/comma ... #hald-clut
http://www.imagemagick.org/Usage/color/#hald-clut

Re: brightness curve

Posted: 2009-11-11T12:24:01-07:00
by cedricb
I don't understand how the hald-cut will perform my different Photoshop like layering masks? ;-)

Re: brightness curve

Posted: 2009-11-11T12:42:26-07:00
by fmw42
As far as I know, IM does not have any special types of photoshop-like layers, other than just masking and merging of images. The hald-cut simply allows you to create a special lut that can be used for many images to process them the same way, i.e. with the same curve. But you could in principle also just save the normal lut from the curves and reuse it.

Re: brightness curve

Posted: 2009-11-11T16:52:40-07:00
by anthony
cedricb wrote:I'm bit lost after this step:

Code: Select all

im_fx_curves -c 0,0 0.125,0.375 0.25,0.625 0.5,0.875 1,1
This outputs a set of numbers, which are the coefficients of a polynomial equation that was fitted to the control points you specified. The output of the above program was

Code: Select all

  -0.762,3.333,-5.167,3.595,-0.000
Meaning

Code: Select all

    -0.762 * x^4   + 3.333 * x^3   +  -5.167 * x^2  + 3.595 * x  + 0
It is applied to an image using the -function polynomial

Code: Select all

  convert image  -function polynomial '-0.762,3.333,-5.167,3.595,-0.000' result
A very bright image.
IM curves...
http://www.imagemagick.org/Usage/
Polynomial Math Function
http://www.imagemagick.org/Usage/transf ... polynomial



Fred developed his own scripts for handling control-point curve functions. Rather than fitting a polynomial to the control points he uses either linear or cubic interpolation. This can produce a better curve. Also he applys the fitted curve as a Color Lookup Table rather than as a mathematical function.

Basically they are just different method of applying a freeform curve to an image.

Re: brightness curve

Posted: 2009-11-12T01:32:43-07:00
by cedricb
Thanks for the details, I'm fine with the maths. I was wondering how can I re-produce the different layering masks from that tone mapping tutorial.
I'm not looking to add different layers to an image like Photoshop. I just want to reproduce the same final effect by producing masks which I can overlay to the original image.

Re: brightness curve

Posted: 2009-11-12T16:26:43-07:00
by anthony
You generate the different layers and then use -composite (for two images) or -flatten (for multiple images. Of course the -compose setting is important to set how the images should be combined.

Composiion Methods
http://www.imagemagick.org/Usage/compose/

Layering
http://www.imagemagick.org/Usage/layers/#flatten

Re: brightness curve

Posted: 2009-11-13T06:52:50-07:00
by cedricb
I'm fine to perform a mask, the only thing I have is the difficulty to replicate the actual mask from this tutorial... :?

I think I've been able to replicate step 1 and step 2.

Code: Select all

./curves "0,0 12.5,37.5 25,62.5 50,87.5 100,100" img_orig.tiff img_bright.tiff
composite -compose CopyOpacity img_bright.tiff img_orig.tiff mask.tiff
To resolve step 3/4, I'm just wondering if I can do the following:
1 - convert the mask.tiff to HSL and extract the luminance channel (I'm fine with this)
2 - apply a threshold value to the luminance image, so for example I'll keep the 20% of the most illuminated pixels and make the rest transparent
3 - replace the pixels from the mask to the transparent pixels from the luminance image (which I've applied the threshold ratio)
4 - apply a Gaussian-blur to that mask (I'm fine with this I think)
5 - merge the mask with img_bright.tiff (I'm fine with this)

So how I do number 2 and 3 with IM ?

Re: brightness curve

Posted: 2009-11-13T11:05:18-07:00
by fmw42
1 - convert the mask.tiff to HSL and extract the luminance channel (I'm fine with this)
2 - apply a threshold value to the luminance image, so for example I'll keep the 20% of the most illuminated pixels and make the rest transparent
3 - replace the pixels from the mask to the transparent pixels from the luminance image (which I've applied the threshold ratio)
1) you can get the luminance directly (note the L in HSL in lightness and not luminance)

convert image -colorspace Rec601Luma result

(or Rec709Luma)

see http://www.imagemagick.org/script/comma ... colorspace

2) you can threshold the image (luminance) using -threshold. If you want the brightest 20% white and the rest black

convert image -threshold 80% result

see http://www.imagemagick.org/script/comma ... #threshold
see also -black-threshold and -white-threshold


3) Not sure what you want here. If you want to put the thresholded luminance into the alpha channel of the image

convert image luminanceimage -alpha off -compose copy_opacity -composite result

see http://www.imagemagick.org/Usage/compose/#copyopacity


General reading:

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

Re: brightness curve

Posted: 2009-11-15T12:24:49-07:00
by cedricb
the colorspace Rec601Luma and the threshold value produce the correct black and white mask... ;-)

I'm getting the correct result with the Copy Opacity operator, but ultimately I would like to replace the transparent pixel to opaque white? ...how can I do that after the last convert?

Re: brightness curve

Posted: 2009-11-15T15:20:14-07:00
by fmw42
add

-fill white -opaque none

or

-background white -flatten