Log in

View Full Version : Idea: Implement Retinex Algorithm


mikeytown2
18th February 2009, 08:57
Was browsing around and found this
http://www.fmwconcepts.com/imagemagick/retinex/index.php
Looks like it requires Gaussian blur and log operations on the image data.

Use this for blur
http://forum.doom9.org/showthread.php?t=88645
What about log operations?

Sagekilla
18th February 2009, 15:51
mask tools perhaps? I know it has a log operator. So you could do mt_lut("x log")

Edit:


src = last

G1 = src.Blur(0.3)
M1 = mt_lutxy(src, G1, "x y / 1 + log")
G2 = src.Blur(0.7)
M2 = mt_lutxy(src, G2, "x y / 1 + log")
G3 = src.Blur(1.5)
M3 = mt_lutxy(src, G3, "x y / 1 + log")

Avg = Merge(Merge(M1,M2,weight=.50),M3,weight=.33)

G0 = src.Grayscale()
CB = mt_lutxy(src, G0, "x y / 1 + log")

MI = Overlay(Avg, CB, mode="multiply")
Merge(Avg, MI)


That would work. If it worked with RGB top to bottom. Unfortunately we can't :( Will post update in a few minutes.

Update: You have to do this through a plugin because through scripts, it would be -extremely- unwieldly. I can try fudging together something as my first attempt at a plugin but no guarantees there.

tin3tin
18th February 2009, 23:48
Was browsing around and found this
http://www.fmwconcepts.com/imagemagi...inex/index.php
Nice find. It would really be great if usage of IM scripts was possible in the (old) ImageMagick Avisynth (http://forum.doom9.org/showthread.php?p=612335#post612335) plugin. :)

Mug Funky
19th February 2009, 06:55
it seems to do the same as HDRAGC? or am i missing something?

btw, in most of those examples the original looked most natural, and would have probably only needed a vanilla lift/gain/gamma adjustment to achieve the same goal in a more aesthetically pleasing way...

i'm not a huge fan of performing contrast and colour balance adjustments in YCbCr space though - it always looks wrong

Sagekilla
19th February 2009, 08:04
I don't think you can do this in YV12 anyway.

Unless you jump through a lot of hoops (ShowRed() etc), you can't do this filter in the current state of things.

The only function I know of that provides a log function is mask tools. Unless you find a way to make it support RGB, it's just going to be painfully annoying trying to get it done.

Merge, Overlay, GaussianBlur, they all exist. Only problem is the "log" portion :(

Didée
19th February 2009, 11:55
Sagekilla - there is still MaskTools v1.5.8, which hands RGBLUT() at your disposal. :)

However, "insufficiency of YV12" is no excuse for your script being faulty. It produces a black output. Hang on - don't you see the mistake(s)? ;)


BTW, I didn't know of that "Retinex" algorithm, but no surprise, 've been there before. It was around late 2005 / early 2006 when I was first playing with that idea. A small hint was given here (http://forum.doom9.org/showthread.php?p=760935#post760935): "Todo: replace [additive] sharpening with [multiplication] sharpening".
That was when I was at a somewhat serious attempt to do LimitedSharpenEX(), which should implement combined multiscale nonlinear sharpening. It used sqrt(), however, not log(). What I found was that, while results on selected scenes with selected parameters can be great, the method is rather hard to control so that it gives a consistent result on content with varying characteristics. Showing some great result on selected still images is one thing. Achieving a convincing result on moving pictures, aka "video", is another story. Characteristics change each scene, and even the slightest compression artifacts get blown up into nasty prominence.

mikeytown2
19th February 2009, 13:48
NASA appears to be using this on video
http://dragon.larc.nasa.gov/retinex/servo/
And seeing how its designed for a live feed, they didn't take into consideration compression artifacts.

This is strangely similar to HDRAGC now that you mention it.
http://forum.doom9.org/showthread.php?p=917911#post917911

Did some more searching... looks like a dud. It's in gimp, play around with it. It's SLOW
Colors -> Retinex (at the bottom of the menu)
http://www.sfr-fresh.com/unix/misc/gimp-2.6.5.tar.gz:a/gimp-2.6.5/plug-ins/common/contrast-retinex.c

Sagekilla
19th February 2009, 15:55
@Didee: Oh I know, I went back and I realized I screwed up quite a bunch of things in that original script, namely the mt_lut calls. Didn't know there was a RGBLUT() though ;) Thanks for pointing that out.

Fizick
19th February 2009, 21:42
GaussianBlur from tsp plugin should be faster (it uses fftw)