Level - Input with output

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
brubru
Posts: 18
Joined: 2013-05-10T04:22:01-07:00
Authentication code: 6789

Level - Input with output

Post by brubru »

Hi.
How i can to do this effect? Image
I mean output 82 with input 56.
-level and +level do 82,0 or 0,56. But i need 82,56. Help me please to resolve it.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Level - Input with output

Post by snibgo »

You want a transformation with two lines. "+level" or "-level" gives a transformation with only one line. We can do the second line with "-compose Lighten". Windows script:

Code: Select all

convert ^
  in.png ^
  +level 13.07%%,100%% ^
  ( +clone -fill rgb(32.16%%,32.16%%,32.16%%) -colorize 100 ) ^
  -compose Lighten -composite ^
  out.jpg
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Level - Input with output

Post by fmw42 »

If on Linux,Mac, see my script, plm, (piece-wise linear mapping) at the link below. The following will do what you want. Thought the values will be scaled to fit the range 0 to 100 for the graph and the listed breakpoints. However, the -s 255,255 allows values to be input in 8-bit range.

# create gradient image for testing
convert -size 100x100 gradient: grad100.png

# process
plm -s 255,255 -g "0,82 56,82 255,255" grad100.png 1tmp0.png
Break Points = 0,32.1 21.9,32.1 100.0,100.0

Note, your example is similar to one I list in the Clip Low examples
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Level - Input with output

Post by anthony »

Another method is to use two level operations. one to clip the bounds, and the other to raise it again.

A bit like what was done to explain non-HDRI clipping
http://www.imagemagick.org/Usage/basics ... um_effects
see also Level Operator
http://www.imagemagick.org/Usage/color_mods/#level

However two operations like this will add on extra set of 'rounding' errors.

The level with a compose lighten is another way to do it, as Fred gain in at previous topic.
Or perhaps we can add some type of -evaluate method? (clamp, and burn?)


I did think initially that maybe threshold-black would do the task, but that just pushes the values to 0 and not to the threshold level given.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Level - Input with output

Post by fmw42 »

It can be done with +level to adjust the Y intercept of the straight line appropriately, followed by -black-threshold, followed by -fill ... +opaque black to raise the black area to the desired level.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Level - Input with output

Post by anthony »

fmw42 wrote:It can be done with +level to adjust the Y intercept of the straight line appropriately, followed by -black-threshold, followed by -fill ... +opaque black to raise the black area to the desired level.
That will fail for images with color! but if it is grayscale, no problem.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Level - Input with output

Post by fmw42 »

anthony wrote:
fmw42 wrote:It can be done with +level to adjust the Y intercept of the straight line appropriately, followed by -black-threshold, followed by -fill ... +opaque black to raise the black area to the desired level.
That will fail for images with color! but if it is grayscale, no problem.
Why?

You can use it with a gradient LUT and then apply with -clut if that makes a difference?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Level - Input with output

Post by snibgo »

I had forgotten about "-evaluate max", as mentioned on another thread. So my method simplifies to (Windows script):

Code: Select all

convert test.png ^
  +level 13.07%%,100%% ^
  -evaluate max 32.16%% ^
  out2.jpg
snibgo's IM pages: im.snibgo.com
brubru
Posts: 18
Joined: 2013-05-10T04:22:01-07:00
Authentication code: 6789

Re: Level - Input with output

Post by brubru »

Thank you very much.
I chose this method - "-level 20% +level 20%".
I don't know why, but here "http://www.imagemagick.org/Usage/color_mods/#level_plus" this command "convert test.png +level 20% -level 20% test_level_undo.png" just switch output point back to 0%. So, for real he do 20%,20%.
Post Reply