Help - Search - Members - Calendar
Full Version: dynamic range compression
Hydrogenaudio Forums > Digital Audio/Video > General A/V
eyesonly
Hi,

I hope this is the right forum for this question.

I have a very bad camera shot from a very small theatre. I would like to do something similar to dynamic compression in audio since there are some very bright areas on the screen, while some are too dark. Can I do such a thing in video? If yes, plz tell me how to do it smile.gif

best regards
smok3
that would be possible if your input source had a bigger dynamic range than your output, for example film2video transfer, but in your case it is about clipping on both sides, but you could raise middle range a bit (probably any editing or composing software can do that one way or another...).

edit: actually what you are looking for is the opposite of dynamic compression.
edit2: upload a frame or two somewhere and you might get some additional info.
StoneRoses
Try lower the contrast, or adjust picture level. It will bring back some mid-tone details, but won't help the shadow and highlight area that were already clipped.

AVISynth will do the job.
eyesonly
Hi,
you can see a picture here: http://gemini1325.w.interia.pl/pic1.jpg .

I wuould like to have the darker objects more bright, and the brighter ones more dark. and yeah, I know there is probably some heavy clipping here (in the brighter parts), but I would like to make the picture more pleasant.


best regards
ErikS
Very common problem for me as well. When I looked around for tools to solve this I found two different methods being used. One is highpass filtering, and the other one is localised equalisation. The drawback of both were that they are very sensitive to noise.

I'll try to give some links for you when I get back home tonight...
ErikS
Ok. I had a look at your picture, and it looks like a hopeless case already. Too much noise in the dark areas to do anything useful. Thsi is what it looks like after some simple local histogram equalizing...
http://www.comp.nus.edu.sg/~s0300325/files/out.png

Here's an example from my pictures which I tried to correct in a similar fashion. Also has problems with noise, and here I have even done quite some manual noise removal...

http://www.comp.nus.edu.sg/~s0300325/img/L...d/ElCapitan.jpg
http://www.comp.nus.edu.sg/~s0300325/img/L...ard/Captain.jpg

Is this what you look for, or did you expect better results?
eyesonly
QUOTE
Ok. I had a look at your picture, and it looks like a hopeless case already. Too much noise in the dark areas to do anything useful. Thsi is what it looks like after some simple local histogram equalizing...
http://www.comp.nus.edu.sg/~s0300325/files/out.png


I know, this is pretty bad.
I managed to get something like this: http://gemini1325.w.interia.pl/pic3.jpg . Well it's not great, but much more pleasant. Can I count on something better?

I used VirtualDub and these filters:
1.coring (removes pixels that are closest to black - removes a lot of noise)
2. Denoise
3. windowed histogram equalize
4. I changed the saturation of the reds to 0.73 (There were some artifacts after using the equalizer, this compensated them a bit)
5. overall saturation changed to 1.30
6. blurred a bit

Could you recomend me some alternative/better method? I would be very grateful.

QUOTE
Here's an example from my pictures which I tried to correct in a similar fashion. Also has problems with noise, and here I have even done quite some manual noise removal...

http://www.comp.nus.edu.sg/~s0300325/img/L...d/ElCapitan.jpg
http://www.comp.nus.edu.sg/~s0300325/img/L...ard/Captain.jpg

Is this what you look for, or did you expect better results?


Wow!! :jawdrop cool.gif

This is really great. Could you share your secret smile.gif ? plz ;] Even If I could apply this to still images I would really like to use it.


Thanks
ErikS
QUOTE(eyesonly @ Feb 18 2004, 01:02 AM)
This is really great. Could you share your secret smile.gif ?  plz ;] Even If I could apply this to still images I would really like to use it.

Of course! smile.gif This is done with a matlab program I made for an image processing assignment I had last year. I can give you the code for it. Think this should be the one... Well, it's just a windowed histogram equalisation. Very simple, so it should be possible to find plugins that do the same thing.

I wanted to make a photoshop plugin based on this code, but I was discouraged by Adobe's new price for the SDK (300 USD iirc). If you have an old SDK lying around somewhere (which is not subject to this fee), could you share it me?
MugFunky
VCRs use dynamic compression. that's why macrovision protection b0rks tape copying (unless you're got a vintage national toploader still working that uses a different AGC circuit).

one of these days i'll write a function for avisynth that works like an AGC circuit. shouldn't be toooo difficult. just a matter of storing average luma in a bunch of variables and doing some other stu.....

*wanders off muttering*
i4004
[duplicated post erased]
i4004
QUOTE
I used VirtualDub and these filters:
1.coring (removes pixels that are closest to black - removes a lot of noise)

coring?
coring clamps pixels close to black->black...
so that's dynamics compression...(and you are aiming for dynamics expansion,as smok3 said)
so if you have an image with already too narrow dynamic range,you're making even more problems if you clamp it some more....

we have discussed such things here:
http://virtualdub.everwicked.com/index.php...=6&t=5896&st=75

if your stuff is "out of range" there's nothing in this world that'll bring it back!
as there's nothing to be saved!
and i think bootleg camera shot qualifies as excellent candidate for "out of range"....
(above mentioned thread discusses issues on video capturing,but it's the same thing....exactly the same thing...)
you can play with "levels" (or whatever) as much as you like,but if it's too clamped you won't fix it...

mug;
QUOTE
VCRs use dynamic compression. that's why macrovision protection b0rks tape copying (unless you're got a vintage national toploader still working that uses a different AGC circuit).

huh?
VCR's use bandwidth limiting(with "fancy" analog ways to limit it) and
the thing you called dynamic compression..well,i just call it video levels regulation...usually this affects the impression of contrast of an image...i have a old vcr that "compresses the dynamics"(lowers the contrast) and newer vcr's that "expand "it(increase the contrast)...no,i wouldn't use that terminology on vcr's at all...they just regulate levels of video so that it fits their video rec. preamp...


actually whole this naming reminds me a bit of dolby b/c,which (in my mind) never actually worked..it just clamped hi-freq. response...it accentuated hifreq. on recording ok,but had issues on playback(always doing too strong deacctentuation....)...didn't really worked....
but back to vcrs;macrovision indeed works because of AGC,but what does AGC has to do with dynamics compression?
VCR's must have AGC because tape/heads need a signal of particular levels.....
ie tape/heads equalization curves are adjusted for particular video signal levels....

QUOTE
one of these days i'll write a function for avisynth that works like an AGC circuit.


you can,but you won't be solving too dark or too bright images...that's for sure...


but.."dynamic range compression"...yes,i use ut every day;cap your stuff with a bit lowered contrast/brightness(will save bitrate on mpeg4 encoding),and then increase these 2 on playback....there.....range compression to save some bitrate(hehe)
decrease cont/bright lil bit more(on capping) and you won't see anything anyhow...

also;
CODE
#  Recovers visibility on very bad recordings.
colorYUV(autogain=true, autowhite=true)


but this doesn't really work for those out-of-range files(in fact it'll tend to mess those even more...)

a bit pesimistic post,but that's how it is..some things can be fixed,others can't....

ps.just saw your images...this qualifies as "out fo range" in my mind...and it must;consumer grade video camera shooting a bright scenes inside a theatre....

offtopic/hmm..mug,your pal kassandro is twisting the truth it seems(align fields) if morsa shots(is that morsa on images? smile.gif ) are truthfull(and i think they are)
and if this is truth
QUOTE
similar to TomsMoComp with search effort higher than 10.

it's a disaster!

but i see it's speedy,so i'll test it;if it's tmc style deinterlacing,i'll suggest skipping it alltogether...how on earth can that guy say that KD is cheating???
when HE's the one deinterlacing still portions of image....
we'll see.....some images (from me) will follow,i'm sure...i hate the doubt and uncertainty...more about it in some other thread....
MugFunky
CODE

global gl_lum=1

function AGC (clip c, int "type",float "multiplier", float "gamma", int "radius",int "scenechange")
{
global gl_radius = default(radius,4)
global gl_scenechange = default(scenechange,20)
global gl_multiplier = default(multiplier,.96)
global gl_c = c
global gl_gamma = default(gamma,1)
type = default(type, 2)

global gl_multiplier = (type==2)? float(gl_multiplier*2) :
\ float(gl_multiplier)

global gl_method = (type==1)? "averageluma()" :
\ (type==2)? "YplaneMax()" : "YplaneMedian()"

gl_c=gl_c.frameevaluate("global gl_lum = gl_multiplier*128/
\ (gl_c.deleteframe(0).reduceby2().reduceby2().
\ temporalsoften(gl_radius,255,255,gl_scenechange,2).
\ levels(0,gl_gamma,255,0,255,coring=false)." + string(gl_method + ")")
\ ,after_frame=false)

gl_c.scriptclip("converttorgb32().RGBadjust(gl_lum,gl_lum,gl_lum,0).converttoyv12()")

}



BAM!

already put this on doom9, and works like an AGC circuit, but has scenechange detection (well, the scenechange detection inherent in temporalsoften, which this is based on). scenechange detection is good because you don't get obvious pumping except in difficult situations (fan slowly rotating in front of a backlit window), and these can be somewhat mitigated by changing the "type" behaviour.

things to note - it does it's amping in RGB, which you probably don't want (it'll give a little smearing compared to luma-only gain, but gives way more accurate results).

also it's extremely unstable and temperamental - if VDM crashes it'll be this.

[edit]
oh... and on the dynamic compression thing... well i'm thinking more in signals then images, and it looks like windowed histogram equalise will work better than the above script.

ivo:
not to split hairs (huh... that's exactly what i'm doing smile.gif), VCRs have an AGC circuit. it has a very fast attack time (a few lines) and a very slow release time (a few frames). it is EXACTLY the same as an analog compressor used in recording studios and radio stations worldwide, only it operates in the video signal. Macrovision works by putting in "transients" (audio speak) or rather very bright lines in the overscan areas at the top of all affected frames. these lines are typically about 3x standard white level. the AGC circuit (a typically designed one, anyway) will react in about 30 lines to this spike and turn the level down to unwatchable darkness. in order to prevent people just adding gain to this signal in order to make dubs, these lines aren't present all the time, rather they switch on and off intermittently. this is why certain rental tapes will pulse between light and dark. depending on how good/new your VCR is you will see this effect or you wont (most current ones will simply blank the screen if they detect macrovision in their line-in).

hehe. my old (dead crying.gif ) top-loading VCR predated the macrovision technique, and has a non-standard AGC circuit. i used to be able to make copies of macrovision tapes without special equipment (hmm... that quite possibly doesn't violate the DMCA if i didn't intentionally circumvent anything)
i4004
i'll be sure to report this to mpaa! biggrin.gif

QUOTE
it is EXACTLY the same as an analog compressor used in recording studios and radio stations worldwide,

just a matter of speaking,i guess....
bringing the contrast up is expanding the video signal amplitude,so why call it "compression"
bringing the contrast down can be called compression,offcourse....

QUOTE
the AGC circuit (a typically designed one, anyway) will react in about 30 lines to this spike and turn the level down to unwatchable darkness.

nice explanation....
we discussed it recently here
http://episteme.arstechnica.com/eve/ubb.x?...31#271007572631

QUOTE
hehe. my old (dead  )

my ol' vcr's never die...as i'm fixing them... smile.gif

QUOTE
i used to be able to make copies of macrovision tapes without special equipment

i was a bit more aggressive while stealing the crappy quality pre-rec tapes...
(all prerecorded tapes are of crappy quality...all of them!)
offcourse,making a vhs copy and then putting original tape-reel to my cassette and copied reel to original cassette won't work if original was macrovision protected....(ie i was actually swapping the tapes from 2 cassettes) biggrin.gif

ahh..the good ol' days......

your script?how is it different to tweak,levels or rgbadjust....?
hehe..just kidding....
will try it next time i need dynimics espansion( smile.gif )
MugFunky
QUOTE
offcourse,making a vhs copy and then putting original tape-reel to my cassette and copied reel to original cassette won't work if original was macrovision protected....(ie i was actually swapping the tapes from 2 cassettes)


IVO! i bow my head humbly to you! that's the funniest thing i've heard on this forum for a long time biggrin.gif that's ingenious. no matter how l33t i was in highskoo, i never thought of actually stealing the rental tape. (i'm not sure if we can continue this discussion under the TOS though dry.gif )

yeah... it took me a while to get the compression thing... although the contrast is higher , the dynamic range is less. just like a squished album. a low contrast picture has more headroom for bright bits (interesting aside - http://www.debevec.org has some very cool ideas about images and dynamic range - using bracketed exposures, cleverly adding them together and storing the result as a 32 bit float image. VERY good for 3d renders), therefore more dynamic range (although if all that's being done is amplification, you don't lose anything or gain anything. my script above will work like that on type=2 (i should change that to "mode", as "type" is an awkward term).
i4004
ohh...that's nothing (i assure you... biggrin.gif )

some other stories are MUCH funnier....(for example ones where we actually socialized with our "targets"..or rather "the owners of our prey"...... smile.gif ...
and sometimes they caught you(that probably being the funniest part to the innocent bystander...) OUCH i said in the occasion...)

but you said it;i stole that tape...didn't stole the cassette though....LOL!

TOS?
ohh yeah,the mencoder..( biggrin.gif )....i told you it works here..
check it out
http://neuron2.net/ipw-web/bulletin/bb/vie...php?p=3177#3177

dynamics..
http://www.prorec.com/prorec/articles.nsf/...625661000745390
http://www-valo.uta.fi/cap/htmls/dynamics.html
http://www.record-producer.com/learn/techn...essor-noise.cfm

it all says exactly what i previously though dynamics are;amplitude between loud(white) and quite(black)....
more contrast=more dynamics....

QUOTE
although if all that's being done is amplification, you don't lose anything or gain anything.

amplification is about all you CAN do,isn't it?

it seems i'll be trying your script sooner rather than later smile.gif
[you better run for cover... biggrin.gif ]
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.