Levels

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
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Levels

Post by myspacee »

Hello,
i've a task to solve. At job ask me be able to adjust the color levels for some images.

I started by setting input and output of black and white for this image:
Image
backround Image result too white for final destination (newspaper).
With white so white image appears to float on printed paper.

So, using photosh0p i level INPUT and OUTPUT :
Image

How replicate, by setting parameters, the same effect using IM ?

thank you for any help,
m.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Levels

Post by snibgo »

Code: Select all

convert in.png -evaluate Min 95% out.png
Set the percentage to whatever you want.
snibgo's IM pages: im.snibgo.com
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Levels

Post by myspacee »

Thank you for reply Snibgo,
can you explain how [Min 95%] is able to represent two values ?
(input & output)


--------- EDIT ---------
My boss give me this to rapresent request about grayscale images:

Image

m.
Last edited by myspacee on 2015-05-28T12:33:05-07:00, edited 2 times in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Levels

Post by snibgo »

It only represents one value. All inputs at 95% or above are capped at 95%. If you want something different, please explain.
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: Levels

Post by fmw42 »

There are two points on the Photoshop Curves diagram in piecewise linear mode (not the Levels diagram). You are showing us only one of them at the top right corner. Note there is another point at the lower left, which we do not know from your picture. You need to show both.

If you are on Linux/Mac OSX or Windows with Cygwin, see my script PLM.

Also your boss's diagram is not very clear what he wants. You need two values for each point -- input vs output (as per the Photoshop diagram)

Does he want 7% input to go to 0 and 90% input to go to 255? If so then

Code: Select all

convert image -level 7x90% output
should do that. But that is different from what you seem to be doing in the PS Curves window.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Levels

Post by snibgo »

The Photoshop straight-line effect can be done in two stages. "-level" (no "s") to increase the contrast and blacken shadows beneath 7%. Then -evaluate Min to cap highlight values at 90%.

Code: Select all

convert in.png -level 7%,100% -evaluate Min 90% out.png
snibgo's IM pages: im.snibgo.com
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Levels

Post by myspacee »

Hello,
reading some documentation.

Snibo while waiting write this:

Code: Select all

convert TOO_white.jpg -level 2x97%% TOO_white3.jpg
convert TOO_white3.jpg -evaluate Min 96%% TOO_white4.jpg
it's same ?

Code: Select all

convert in.png -level 2%,97% -evaluate Min 96% out.png
Need to study, come back for colors curves.. Thank you for now :)

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

Re: Levels

Post by fmw42 »

If in place of 7% input going to 0 and 90% input going to 255, you want 0 to go to 7% and 255 to go to 90%, then do

Code: Select all

convert in.png -evaluate max 7% -evaluate min 90% out.png

Neither this nor my earlier code is the same as what is done in the PS Curves diagram.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Levels

Post by fmw42 »

If you want to reproduce the PS Curves two point line, then you can solve the equation Y=aX+b using the two end points.

For example given the two endpoints in=X=7%, out=Y=5% and in=X=90%, out=Y=80%, then you have two equations, where I have converted percent values to a fraction:

5/100=a*7/100 + b
80/100=a*90/100 +b

or

5=a*7 + b*100
80=a*90 + b*100

then subtract the first from the second, gives

75=a*83 which yields a=75/83=0.904

now substitute a=0.904 into the second gives

80=0.904*90+b*100
or
80=81.33+b*100
or
b=-0.00133

Then one can use -function polynomial to make a straight line of the given slope and intercept and then -evaluate min/max to clip the output to the values 5% and 90%

Code: Select all

convert in.png -function polynomial 0.904,-0.00133 -evaluate max 5% -evaluate min 90% out.png
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Levels

Post by myspacee »

Hello,
reading a lot i these days, and It has become a challenge between us colleagues :D

For grayscaleimages, the best result so far we obtained is this :
INPUT IMAGE
Image
OUTPUT IMAGE
Image

The yield in printed paper, favors this conversion than other. Post command :

Code: Select all

convert INPUT.jpg -colorspace Gray -normalize -level 0%,100%,1.3 -evaluate Min 93% OUTPUT.jpg
Can you explain step by step what exactly does ?
(the colleague who proposed this solution used throughout the 'magic' that IM can offer... [Lucky b*st*rd] :) )

for example, I can not interpret 'level' use:

Code: Select all

-level 0%,100%,1.3
thank you for you time,
m.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Levels

Post by fmw42 »

The -normalize is the same as -contrast-stretch 2%x1%, which expands the histogram endpoints by 2% on the black end and 1% on the high end. This increases the contrast.

-level 0%,100%,1.3 does not adjust the endpoints due to 0%x100% being a null operation. It simply applies a gamma of 1.3. So this command could be simplified to just -gamma 1.3.

The evaluate min 93% ensures no value is larger (whiter) than 93%.

So this should do the same

Code: Select all

convert INPUT.jpg -colorspace Gray -normalize -gamma 1.3 -evaluate Min 93% OUTPUT.jpg
myspacee
Posts: 153
Joined: 2007-06-14T02:09:35-07:00

Re: Levels

Post by myspacee »

Thank you for the info,
m.
Post Reply