Page 1 of 1
Is it possible to reproduce Ylevels filter with ImageMagick?
Posted: 2014-09-15T23:21:00-07:00
by konstantin
Is it possible to reproduce avisynth's Ylevels filter with ImageMagick?
http://avisynth.nl/index.php/Ylevels
http://forum.doom9.org/showthread.php?t=79898
To make dark video screenshots brighter and visible.
Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-09-16T09:18:53-07:00
by snibgo
I can't easily figure out what the Ylevels filter does.
For lightening dark pixels, without also lightening light pixels, "+sigmoidal-contrast" with a midpoint above 50% is useful.
For example, "+sigmoidal-contrast 8,70%" gives this transfer curve:

You could use this:
Code: Select all
convert rose: -colorspace YIQ -channel R +sigmoidal-contrast 8,70% +channel -colorspace sRGB s.png
Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-09-16T13:54:06-07:00
by konstantin
I don't understand exactly as well how it works, but the visual appearance of the videos are very nice with this Ylevels filter applied.
Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-09-16T14:15:49-07:00
by fmw42
It appears to be an IM -gamma function per comments at
https://ffmpeg.org/pipermail/ffmpeg-use ... 20584.html. Though I suspect it is like IM -levels, that allows blackpoint, whitepoint and gamma adjustment, but on the Y channel of YCbCr).
Just use it in place of sigmoidal-contrast in snibgo's command which operates on the intensity channel (or use the L channel from LAB, or I from HSI). However, there are a number of similar non-linear operators, such as -evaluate log, -gamma, or a one sided -sigmoidal-contrast Vx0%.
I use the sigmoidal-contrast in my script sigmoidal, which tries to emulate Photoshops non-linear brightness-contrast.
Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-09-16T16:35:52-07:00
by konstantin
Here you can see Ylevels filter in action:
Full resolution image:
http://i.imgur.com/etjLWz7.jpg

Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-09-16T16:42:07-07:00
by fmw42
Do you have access to the control for it? If so, please provide a screen snap. From you images, it appears to be equivalent to IM -levels or just -gamma operating on the Y channel from YCbCr (or YIQ or YUV). But you can also try L from LAB (see my script enhancelab) or I from HSI. Just change snibgo's command to
Code: Select all
convert rose: -colorspace YCbCr -channel R -gamma gammaval +channel -colorspace sRGB s.png
or
Code: Select all
convert rose: -colorspace YCbCr -channel R -level bpt,wpt,gammaval +channel -colorspace sRGB s.png
see
http://www.imagemagick.org/script/comma ... .php#gamma
http://www.imagemagick.org/script/comma ... .php#level
http://www.imagemagick.org/Usage/color_mods/#level
Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-09-16T20:21:37-07:00
by konstantin
Sorry, what does exactly mean: "control for it" and "screen snap"? Could you be more specific and verbose? (I am not a native english speaker), My avisynth file (yl.avs) looked like this when I generated the above image (one have to install MaskTools.dll and ylevels.avsi to the avisynth plugin directory, or load them manually with loadplugin("masktools.dll") and import("ylevels.avsi") ):
Code: Select all
ImageSource("000.jpg").trim(0,16)
w=last.width
h=last.height
cr=(4 - (w % 4) % 4)
cb=(2 - (h % 2) % 2)
AddBorders(0, 0, cr, cb, $000000)
converttoyv12()
Animate(last, 0,16, "ylevels", 0,1.0,255, 0, 255,0,2.5,255, 0, 255)
scriptClip( """ subtitle("Gamma applied:" + LeftStr(string(current_frame/10.0+1.0),3) )""")
#Ylevels(0,1.8,255, 0, 255)
converttorgb24()
crop(0,0,-cr,-cb)
ImageWriter("ylevels",0,16,"jpg")
AddBorders(0, 0, cr, cb, $000000)
converttoyv12()
The last two lines are needed only when somebody is on Linux, and use avs2yuv.exe to run the script and render the images like this:
Code: Select all
wine avs2yuv.exe yl.avs - > /dev/null
Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-09-16T20:40:41-07:00
by fmw42
What I was asking was if you have the Avisynth program and when you run it, there is a graphical window for you to interact. When the window is open, can you capture the view of the window so we can see what the graphical controls look like.
Nevertheless, the line from your file has this
This is the standard arguments for a level-like operation such as in Photoshop and GIMP.
It is likely
0 for input black point
1.8 for gamma
255 for input white point
0 for output white point
255 for output black point
In this sequence, the only argument that causes a change of the image is 1.8 for gamma (where gamma=1 would be no change).
So in IM, all you need do is some thing like
Code: Select all
convert inputimage -colorspace YCbCr -channel R -gamma 1.8 +channel -colorspace sRGB outputimage
If you want more control, then use
Code: Select all
convert inputimage -colorspace YCbCr -channel R -level X,1.8,Y +channel -colorspace sRGB outputimage
where X=0 by default but could be made larger and Y=255 by default but could be made smaller. The 1.8 can be varied to get different results as in your examples. X=input black point and Y=input white point.
Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-09-16T22:06:45-07:00
by konstantin
Oh, I see. There is no graphical control window for this filter called Ylevels. It can be used only with function arguments.
I have tried the first command you mentioned, this is the result:
Top image was generated with avisynth, bottom with ImageMagick. They reasonably differ, the bottom is a bit darker.
Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-09-20T19:43:07-07:00
by konstantin
Btw, is there any way to automatically guess the right gamma value for an image?
Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-09-20T19:52:40-07:00
by fmw42
konstantin wrote:Btw, is there any way to automatically guess the right gamma value for an image?
Not that I know. IM has an auto-gamma function that tries. I have a script, auto-gamma that is similar but allows you to set the mid gray level (IM used 0.5 i.e. 50%).
You can try the IM -auto-gamma where you have -gamma in your code. You can also try using other colorspaces, such as LAB.
If you are on Linux or Mac OS or Windows with Cygwin, you can try my script. I also have one that does white balance and brightness contrast along with auto-gamma. see my autotone.
Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-09-20T20:18:33-07:00
by snibgo
konstantin wrote:Btw, is there any way to automatically guess the right gamma value for an image?
I have discovered that when gamma is the only control, I
always prefer the gamma that maximises the standard deviation of the image.
In my experience, this is always true for photographs (including video). It may not be true for more graphical images.
This is now part of my standard default processing of photographs. Video is more complex as we need a consistent gamma for all the frames in one shot, and the shots in a sequence need to have the same "look".
IM's in-built auto-gamma chooses the gamma that makes the mean value 50%. This generally doesn't maximise the SD, and doesn't give the "best" image.
Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-10-25T15:27:16-07:00
by konstantin
Do you mean that standard deviation which is listed by the command "identify -verbose"?
Code: Select all
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 390x527+0+0
Resolution: 96x96
Print size: 4.0625x5.48958
Units: PixelsPerInch
Type: TrueColor
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
Pixels: 205530
Red:
min: 0 (0)
max: 255 (1)
mean: 195.229 (0.765604)
standard deviation: 78.3089 (0.307094)
kurtosis: 0.368077
skewness: -1.36697
Green:
min: 0 (0)
max: 255 (1)
mean: 135.378 (0.530892)
standard deviation: 68.3243 (0.267938)
kurtosis: -0.739838
skewness: -0.537471
Blue:
min: 0 (0)
max: 255 (1)
mean: 131.736 (0.516611)
standard deviation: 66.8117 (0.262007)
kurtosis: -0.720457
skewness: -0.525522
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 154.114 (0.604369)
----------------------------------------------------------------------
+ standard deviation: 71.3309 (0.279729) +
----------------------------------------------------------------------
kurtosis: -0.0524484
skewness: -0.678321
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: white
Border color: srgb(223,223,223)
Matte color: grey74
Transparent color: black
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 390x527+0+0
Dispose: Undefined
Iterations: 0
Compression: JPEG
Quality: 94
Orientation: Undefined
Properties:
date:create: 2014-10-21T01:25:02+02:00
date:modify: 2014-10-21T01:25:02+02:00
jpeg:colorspace: 2
jpeg:sampling-factor: 2x2,1x1,1x1
Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-10-25T15:57:18-07:00
by fmw42
I am pretty sure snibgo's SD is standard deviation
Re: Is it possible to reproduce Ylevels filter with ImageMag
Posted: 2014-10-25T17:12:28-07:00
by snibgo
Yes. In particular, a script finds the value of XX that maximises:
Code: Select all
convert in.miff -gamma XX -format "%%[fx:standard_deviation]\n" info:
My rule of thumb ("
always choose the gamma that maximises the SD") is true for my photos, but not other people's. For example, applying this to a portrait where the face was low-contrast but the image also contained bright sky gave a horrible result. Cropping out the face, finding the gamma that maximised the SD of the face, then applying that gamma to the entire photo, was a big improvement.