Log in

View Full Version : histogram matching/curve computing question


Pages : [1] 2

zee944
5th March 2010, 23:52
http://i179.photobucket.com/albums/w286/zee944/calculatecurvetatraexample.jpg

Dear Everyone,

I have a problem with histogram matching.
I have the original picture on the left (above). I want to make it look like the picture on the right through applying a luma curve to it. How can I figure out the curve I need by comparing the histograms? As you can see, in the above example the desired curve is known, but obviously normally I only have the pictures.

I've written a little program which creates the histograms. I thought it'll be very simple to calculate out the needed luma curve, but I've just realized it's not. I tried comparing "column" to "column" but I ended up with very irrealistic curves. They didn't look like the above. There must be a working mathematical way to work it out. Any ideas? :confused:


Full size pictures:
http://i179.photobucket.com/albums/w286/zee944/UJ_VC_eredetikep.jpg
http://i179.photobucket.com/albums/w286/zee944/UJ_VC_elkurtkep.jpg

Dogway
6th March 2010, 04:14
Do you mean you want to reverse what is shown in the picture?

Curves work like an histogram but in a diagonal axis. Just a question, do you know any curves filter for avisynth? im very interested.

In this particular case the best you can do is by eye. As you have de curve, you can try to do just de opposite. Reference on the grid and reverse the points. Much better, reference the curve graph, and copy the points position, then reverse the value numbers based on the diagonal axis.

Didée
6th March 2010, 14:14
You can't reverse such an operation in the general case. Reversal is only possible when the adjusted curve is continuously rising (or continuously falling). If the adjusted curve doesn't meet this criterium, e.g. if there is a sinus-style rise-fall-rise part in the curve, like in the given example, then the projection is not anymore bijective, and cannot be reversed. (Independent input values become the same output value. If you have only the output value, there is no way to transform that value back into some, some other, or yet another value.)

That's basic maths, you can't square a circle.

zee944
6th March 2010, 14:44
You can't reverse such an operation in the general case. Reversal is only possible when the adjusted curve is continuously rising (or continuously falling). If the adjusted curve doesn't meet this criterium, e.g. if there is a sinus-style rise-fall-rise part in the curve, like in the given example, then the projection is not anymore bijective, and cannot be reversed. (Independent input values become the same output value. If you have only the output value, there is no way to transform that value back into some, some other, or yet another value.)

That's basic maths, you can't square a circle.

Perhaps my post was misleading. :(
I don't want to actually reverse anything. I don't want to tweak the right picture back to the left.

Normally I only have the two images, the left and the right and no curve at all. The curve is what I want to find out: a curve which makes the left image look (nearly) like the right one.

In the example above, the desired curve is already there but that's because it's just an artificial example I created for further examination. So what I need is to calculate out the curve you see in the middle on the pic by comparing the two images.

Is this impossible too?

Gavino
6th March 2010, 14:55
If you have both images, then for each input luma value (at least for those values present in the input), you can see what output value it maps to, giving you your curve.

Didée
6th March 2010, 15:04
Perhaps my post was misleading. :(
I don't want to actually reverse anything. I don't want to tweak the right picture back to the first.
...
Is this impossible too?
It depends on the actual difference. See: you have two such pictures, and want to make one look like the other. Now, if the theoretical curve to make the other look like the one (i.e. the reverse direction of what you want to do) would imply such a not-bijective projection, then it is imposible.


Apart from that, there is a "match histogram" filter for Avisynth. I never tried it (don't even have it). Training for your search skills! ;)

zee944
7th March 2010, 09:41
It depends on the actual difference. See: you have two such pictures, and want to make one look like the other. Now, if the theoretical curve to make the other look like the one (i.e. the reverse direction of what you want to do) would imply such a not-bijective projection, then it is imposible.

Apart from that, there is a "match histogram" filter for Avisynth. I never tried it (don't even have it). Training for your search skills! ;)

Oh, I see now. You're saying if the difference between the two histograms is consistent (basically: their shape look similar) then it is possible. Otherwise not.

I couldn't find histogram matching filter. If you're thinking of ColourLike, that's not a very useful filter and doesn't give me a luma curve anyway. :(

If you have both images, then for each input luma value (at least for those values present in the input), you can see what output value it maps to, giving you your curve.

That's what I thought... but it didn't work for me. My logic was that if, say, the value of luma 127 is '50' units in one histogram, and '56' in the other histogram, then I should add 56/50 = 1.12 gain in the curve at the same point. So 127*1.12 = '142' at luma 127. But I ended up with an exaggarated, unreal curve.

Before I did that I realized that this step won't make the 50 units the desired 56. It'll make all the luma 127 pixels 142. But I thought these steps will compensate each other and the result will be fine. Now that I've written it down I can see even more clearly why this is not working. The right logic must be more complex. Any ideas?

(Perhaps I have to find out the average luma and act the opposite way below and above that gradually?)

Gavino
7th March 2010, 14:04
That's what I thought... but it didn't work for me. My logic was that if, say, the value of luma 127 is '50' units in one histogram, and '56' in the other histogram, then I should add 56/50 = 1.12 gain in the curve at the same point. So 127*1.12 = '142' at luma 127. But I ended up with an exaggarated, unreal curve.
What I meant was to look at the individual pixels, not the histograms. For each pixel, examine input luma and output luma, and construct a table which gives you a mapping from input values to output values. This assumes that a given input luma value always produces the same (or very close to the same) output value, regardless of position - if you find this is not the case, then no possible 'curve' can be found that corresponds to the transformation.

If you want to work solely from the histograms, then it can be done if (as Didée hinted) you assume a monotonic curve. Then you can pair off values from the two histograms in ascending or descending order of luma.

LaTo
7th March 2010, 21:59
Just a quick try, without testing (only on your sample (http://latoninf.free.fr/d9/others/test.jpg)).

MatchHistogram(img1,img2,debug=false)
img1 is the original image (the left one in your example).
img2 is the target image (the right one in your example).
The output is img1 with the calculated curve.

Use debug=true if you want to see the calculated curve (http://latoninf.free.fr/d9/others/curve.jpg).

Here is the plugin: MatchHistogram.dll (http://latoninf.free.fr/d9/others/MatchHistogram.dll)

It doesn't work anytime (cf. Didée), for example inverse img1 & img2 and... oups! :rolleyes:

zee944
8th March 2010, 21:22
Just a quick try, without testing (only on your sample (http://latoninf.free.fr/d9/others/test.jpg)).

LaTo, judging from the images this is genius. :o Does it work only by using the histograms? No pixel-pixel comparing at all?

Isn't the plugin broken? It's 15,360 bytes and AviSynth [2.5.8] tells me "unable to load MatchHistogram.dll". I couldn't find out why yet.

LaTo
9th March 2010, 07:43
LaTo, judging from the images this is genius. :o Does it work only by using the histograms? No pixel-pixel comparing at all?

Really it isn't genius, here is the code:
int temp[2][256] = {{0}};
unsigned char curve[256] = {0};

for (int h = 0 ; h < height ; h++) {
for (int w = 0 ; w < width ; w++) {
temp[0][src1[(h*pitch)+w]] += src2[(h*pitch)+w];
temp[1][src1[(h*pitch)+w]] += 1;
}
}

for(int i = 0 ; i < 256 ; i++) {
if( temp[1][i] != 0 )
curve[i] = temp[0][i] / temp[1][i];
else
curve[i] = i;
}
Now you have your curve, curve[input] = output.

Isn't the plugin broken? It's 15,360 bytes and AviSynth [2.5.8] tells me "unable to load MatchHistogram.dll". I couldn't find out why yet.
It works on my PC... Try to re-download it!

AVIL
9th March 2010, 22:00
Hi,

It also works in my PC (loaded explicitilly) and works OK. ¿BTW a YUY2 version could be possible?. Anyway thanks for the new plugin.

vcmohan
10th March 2010, 04:13
I could not follow completely the discussion. Histogram matching can not exactly match, it only tries to produce a best approximation as it can not fill holes. My HistogramAdjust (http://avisynth.org/vcmohan/HistogramAdjust/HistogramAdjust.html) plug in. Can be tried.

zee944
13th March 2010, 12:10
Really it isn't genius, here is the code:
It's simple indeed. Pixel to pixel. Using the histograms would be genius... and probably impossible to achieve a curve that good. ;)

My problem with pixel-with-pixel comparing you and Gavino suggested that the image geometry has to be exactly the same. But I often want to capture the luma levels of an image and apply that to another image with different content. Imagine a frame of a video which shows a house. And another frame from another video footage (recorded by a different cam) which shows the same house from another angle. Pretty similar in subject, but quite different in geometry. I have to match the luma levels, but pixel-to-pixel mapping doesn't work at all. That's why I want to work from histograms.

I could not follow completely the discussion. Histogram matching can not exactly match, it only tries to produce a best approximation as it can not fill holes. My HistogramAdjust (http://avisynth.org/vcmohan/HistogramAdjust/HistogramAdjust.html) plug in. Can be tried.

Your plugin is interesting. I've met with it years ago already. But it doesn't show the curve it applies on the target video. Could you perhaps modify it to create a curve?

LaTo
13th March 2010, 17:53
Your plugin is interesting. I've met with it years ago already. But it doesn't show the curve it applies on the target video. Could you perhaps modify it to create a curve?

Try:

src=last
clip=src.HistogramAdjust(xxx)
MatchHistogram(src,clip,debug=true)
And maybe it will output the correct curve (it depends on how HistogramAdjust works...)

vcmohan
14th March 2010, 04:06
HistogramAdjust uses the Histogram curve of the video used for matching. So the curve is that of the clip used for matching. It can be a single frame or frame by frame as opted.

zee944
14th March 2010, 04:33
And maybe it will output the correct curve (it depends on how HistogramAdjust works...)

MatchHistogram still doesn't work for me. I've no idea yet, will try to find out why.

HistogramAdjust uses the Histogram curve of the video used for matching. So the curve is that of the clip used for matching. It can be a single frame or frame by frame as opted.

I understand that, it is in the documentation and I've also tried it out. It's not the histograms I'm thinking of. You use some mathematical operation to tweak one histogram to look like the other, and this operation can be described with a curve.

fvisagie
7th July 2015, 15:54
Isn't the plugin broken? It's 15,360 bytes and AviSynth [2.5.8] tells me "unable to load MatchHistogram.dll". I couldn't find out why yet.

Here I have it as 13,253 bytes, and trying to load it into Avisynth 2.6.0 Alpha 4 fails with
LoadPlugin: unable to load "C:\Users\fvisagie\Documents\Working\Video evaluation\MatchHistogram.dll", error=0xc1


Obviously auto-loading also fails.

I was looking forward to working with this. Are any updated or fixed versions available?

StainlessS
7th July 2015, 16:57
Take a look here at post by a well respected member of the forum [error=0xc1]:)
http://forum.doom9.org/showthread.php?p=1696498#post1696498

Reel.Deel
7th July 2015, 17:41
Wanted to try to see if I can get it to load but the link to MatchHistogram.dll is dead.

foxyshadis
7th July 2015, 19:59
Probably just needs to be rebuilt statically, since common AviSynth plugins barely even use the CRT. Aside from that, install the 2008 or 2010 VC runtime to get this working (not sure which).

raffriff42
7th July 2015, 20:12
See also, VCMohan's HistogramAdjust
http://www.avisynth.nl/users/vcmohan/HistogramAdjust/HistogramAdjust.html

StainlessS
8th July 2015, 01:48
I also tried to find the dll, where'd you get it fvisagie ?

fvisagie
8th July 2015, 08:52
Take a look here at post by a well respected member of the forum [error=0xc1]:)
http://forum.doom9.org/showthread.php?p=1696498#post1696498

I expected your post to leave a little egg on my face,

Wanted to try to see if I can get it to load but the link to MatchHistogram.dll is dead.

but this one really plastered me. For me the link had "worked" - right-click, save as, filename automatically populated with MatchHistogram.dll, done. Only now did I realise I'd downloaded an Error 404 page, hehe!

So the DLL is gone. I'll enquire from LaTo via PM.

fvisagie
8th July 2015, 10:22
See also, VCMohan's HistogramAdjust
http://www.avisynth.nl/users/vcmohan/HistogramAdjust/HistogramAdjust.html

Thanks, but I'm looking for the ability to display the calculated curve, which MatchHistogram() seems to have.

vcmohan
8th July 2015, 14:13
You may try my HistogramAdjust plugin

fvisagie
9th July 2015, 08:24
You may try my HistogramAdjust plugin

I must misunderstand something, because I cannot get HistogramAdjust() to display the derived curve?

StainlessS
9th July 2015, 12:43
fvisagie, is Avisynth v2.6 dll OK for you (MatchHistogram) ?

EDIT:
If so I'll try add support for eg YV24 etc.

fvisagie
9th July 2015, 12:49
fvisagie, is Avisynth v2.6 dll OK for you (MatchHistogram) ?

EDIT:
If so I'll try add support for eg YV24 etc.

Yes, thanks. At this point additional colourspace support isn't a concern for me.

StainlessS
9th July 2015, 14:34
Here tis, MatchHistogram dll for Avisynth v2.5+ (temp link till attachment cleared):-
LINK REMOVED

Code REMOVED

ATTACHMENT REMOVED

See post #46:- http://forum.doom9.org/showthread.php?p=1729796#post1729796

fvisagie
9th July 2015, 15:30
Here tis, MatchHistogram dll for Avisynth v2.5+
...
EDIT: fvisagie, no curve displayed


Thanks a stack for your trouble.

So it seems the
MatchHistogram(img1,img2,debug=false)
...
Use debug=true if you want to see the calculated curve (http://latoninf.free.fr/d9/others/curve.jpg).

parameter has unfortunately vanished? (curve link above now dead)

Many thanks also to LaTo for kindly digging up the source.

StainlessS
9th July 2015, 15:42
The debug curve mentioned is posted before source here:- http://forum.doom9.org/showthread.php?p=1381389#post1381389
and that source is different to later source provided by Lato, so looks like debug was only present early on and then removed.

Do you know what the original 'curve' looked like ? that link is also not working.

fvisagie
9th July 2015, 15:53
Unfortunately I don't know what it looked like. I guess it would have been the obvious 0 - 255 input luma vs. output luma plot.

StainlessS
9th July 2015, 15:59
OK, did not know if you were expecting something exotic.

I'll try to synthesize 256x256 frame BW plot when debug == true.
Not gonna spend a lot of time on it.

fvisagie
9th July 2015, 16:10
Not gonna spend a lot of time on it.

Please don't. I wasn't expecting you to add back lost functionality, and you have already done more than your unfair share ;).

LaTo
9th July 2015, 18:30
Please don't. I wasn't expecting you to add back lost functionality, and you have already done more than your unfair share ;).
Check your PM ;)

edit: uploaded latest (http://latoninf.free.fr/d9/MatchHistogram.cpp) version!

StainlessS
9th July 2015, 20:04
Thanx LaTo :thanks:

and also to fvisagie for being pushy :)

Here update not including LaTo PM source.
I'll post what I've done so far: LINK REMOVED

CODE REMOVED: See post #46 :- http://forum.doom9.org/showthread.php?p=1729796#post1729796

LaTo
9th July 2015, 21:03
I've uploaded the latest source in my previous post.
Keep in mind that this plugin should be used for analysis only...
It's too simple to be used in production. Or use it as a base to enhance it :)

Reel.Deel
10th July 2015, 03:18
Thanks LaTo & StainlessS!


@LaTo
Haven't seen you around in some time, hope everything's going well for you.
I have a quick question on your updated source you posted, I see the syntax is "cc[plane]i[raw]b[show]b", what's the purpose of plane and raw? I'm guessing the old debug parameter is now show?

Edit: I'm thinking the plane parameter dictates which plane to process?


@StainlessS
I hate to be the one who nitpicks but there's a small typo in the source in post #37. "Error: Clips dissimiilar dimensions" should be dissimilar. Please don't hate me, I wasn't looking for errors I just happened to see it. :p

Edit: you don't have to do all that, doesn't bother me one bit, I'm just happy than there's a working version of the plugin :). Currently I've been doing color experimenting, starting with a YUV source I take the Y channel and save to a Y8 PNG then I load it in an external HDR program, do some subtle enhancements, save it, load it back to into AviSynth and merge it with the original chroma. This technique works surprisingly well on certain things. I want to see how well MatchHistogram performs, I'm also gonna try VCMohan's HistogramAdjust.

StainlessS
10th July 2015, 03:44
Sum peeple iz neva appy :rolleyes:

I'll compile latest when I get around to it.

EDIT:

And many thanx to Reel.Deel for his attention to detail. :)

StainlessS
10th July 2015, 04:34
A better test, return one of the Stack results

CODE REMOVED, see post #46:- http://forum.doom9.org/showthread.php?p=1729796#post1729796

fvisagie
10th July 2015, 11:33
Here update not including LaTo PM source.
I'll post what I've done so far: http://www.mediafire.com/download/s2s5n0x51r3gceb/MatchHistogram-TAKE_2.zip


I especially like how you demonstrate in the *.avs how to sample values. Great work so far and many thanks to you and LaTo.

I've uploaded the latest source in my previous post.
Keep in mind that this plugin should be used for analysis only...


Rest assured on my account, that's exactly what I have been looking for :).

EDIT: Most notably, on some HD scenes I notice banding in the output, probably due to no high-bitdepth processing and no dithering. But, for analysis as stated, this is perfect!:thanks:

vcmohan
10th July 2015, 13:09
I must misunderstand something, because I cannot get HistogramAdjust() to display the derived curve?

To have a display of actual histogram you can use Histogram, one of the avisynth included filters. You can input the input image, desired image(to match) and output of HistogramAdjust to Histogram and view input curve, matching curve and resulting curve after matching.

fvisagie
11th July 2015, 09:59
To have a display of actual histogram you can use Histogram, one of the avisynth included filters. You can input the input image, desired image(to match) and output of HistogramAdjust to Histogram and view input curve, matching curve and resulting curve after matching.

Although useful, I find manually comparing input and output histograms and waveforms somewhat limiting in this case of adjusting one filter to match the luma response of another. Analysing this way is further complicated when the filters are adaptive. A luma tonality curve (https://en.wikipedia.org/wiki/Curve_%28tonality%29) (i.e. plotting output luma vs. input luma) would directly display for each filter the luma transfer function derived from programmatically compared histograms. Although artificial luma curves can be constructed from evenly monotonically graded grey-scale input images and Histogram("classic"), I still find it difficult to translate such results to real-world footage.

vcmohan
11th July 2015, 13:55
A luma tonality curve (i.e. plotting output luma vs. input luma) would directly display for each filter the luma transfer function derived from programmatically compared histograms. Although artificial luma curves can be constructed from evenly monotonically graded grey-scale input images and Histogram("classic"), I still find it difficult to translate such results to real-world footage.
If I understood correctly you are looking for a plot of output vs input luma. Ths can be done easily by a little coding. As real world footage runs into thosands of frames, visually examining tonal curve of each frame would be enormously slow and tedious.

StainlessS
11th July 2015, 21:06
LaTo's update (v2.6 and v2.5 dll's, + source + vs 2008 project files + original source)
(with added MatchHistogramDebug as I think the ability to measure the values could be handy).

MatchHistogram(clip c,clip c2,int "Plane"=0,bool "Raw"=False,Bool "Show"=False) : by LaTo.

Planar only. v2.6 and v2.5 plugins.

Modifies clip c histogram to match that of c2.
Plane, default 0. 0=Luma : 1=U : 2=V : 3=U+V : 4=Y+U+V
Raw default false. False Smoothed histogram, True Raw histogram.
Show, Default false. True show histogram on frame.

Will produce weird results if frame contents are dissimilar.

###

MatchHistogramDebug(clip c,clip c2,int "Plane"=0,bool "Raw"=False) : by StainlessS, histogram smoothing by LaTo.
As for MatchHistogram but returns Debug clip grayscale YV12 256x256 @ clip c Framerate and FrameCount.
Plane, default 0. 0=Luma : 1=U : 2=V
Raw default false. False Smoothed histogram, True Raw histogram.

Debug mode, returns PC Range YV12 clip @ 256x256 original framerate without audio showing curve used.
Can sample luma @ x,255 for value in curve LUT[x] (look up table) ie bottom of histogram at x position.



avisource("D:\avs\starwars.avi")
#colorbars

(VersionNumber>=2.6) ? ConvertToYV24() : ConvertToYV12

A=Last
TEST=2 # 0=Invert Luma : 1=Photo -ve invert : 2=Gamma test
#GAMMA=1.0/2.2 # A little excessive
GAMMA=0.66
BLUR=0.0
###################################
# MatchHistogram mode only #
RAW=True # False = Smooth histogram : True=No Smooth
PLANE=4 # Plane to fix (0=Y : 1=U : 2=V : 3=U+V : 4=Y+U+V)
#MatchHistogram Debug mode only #
DEBUG_RAW=True # False = Smooth histogram : True=No Smooth
DEBUG_PLANE=0 # Plane to show in debug mode (0=Y : 1=U : 2=V)
###################################

# Pick a test below
Assert(A.IsPlanar(),"Planar Only")
Assert(TEST!=0 || VersionNumber<2.6 || !A.IsY8(),"TEST=0 : Y8 Has No Chroma")
B=(TEST==0) ? A.Invert.MergeChroma(A) : (TEST==1) ? A.Invert : A.Levels(0,GAMMA,255,0,255)
###
B = (BLUR!=0.0) ? B.Blur(BLUR) : B
###
#return StackVertical(A.Subtitle("ORIG"),B.Subtitle("BAD")).ConvertToYV12

C = MatchHistogram(b,a,plane=PLANE) # Match B to A
#return C.ConvertToYV12
CS=MatchHistogram(b,a,plane=PLANE,Show=true)
#return CS.ConvertToYV12
###DBUG = MatchHistogramDebug(b,a,Plane=DEBUG_PLANE,RAW=DEBUG_RAW) # DBUG, Returns YV12
DBUG = MatchHistogram(b,a,Plane=DEBUG_PLANE,RAW=DEBUG_RAW,DEBUG=True) # DBUG, Returns YV12
#return DBUG
D=ClipDelta(A,C)
#return D.ConvertToYV12
X_COORD = 255
Script="""
V = Int(DBUG.RT_AverageLuma(x=X_COORD,y=255,w=1,h=1)) # Bottom pixel @ X_COORD (Cartesian Coords ie bottom rel for graph)
RT_Subtitle("Curve Value @ %d=%d",X_COORD,V,Align=8)
Return Last
"""

D=D.ScriptClip(Script).OverLay(DBUG,y=D.Height-DBUG.Height,Output="YV12") # BEWARE, Overlay(YV16,YV12) can return YV24
#return D

TOP = StackHorizontal(A.ConvertToYV12.Subtitle("ORIG",align=1),CS.ConvertToYV12.Subtitle("FIXED (Blur not fixed)",align=1))
BOT = StackHorizontal(B.ConvertToYV12.Subtitle("BAD"),D.Subtitle("DIFF"))
Return StackVertical(TOP,BOT)
###################################
# Return Clip Difference of input clips (amp==true = Amplified, show==true = show background)
Function ClipDelta(clip clip1,clip clip2,bool "amp",bool "show") {
amp=Default(amp,false)
show=Default(show,false)
c2=clip1.levels(128-32,1.0,128+32,128-32,128+32).greyscale()
c1=clip1.subtract(clip2)
c1=(amp)?c1.levels(127,1.0,129,0,255):c1
return (show)?c1.Merge(c2):c1
}


LaTo, bugfix as gets stuck in a loop sometimes (dont know if best fix)

for (int i = 0 ; i < first ; i++) {
int z = min(first*2-i,255); // ssS
// if( div[first*2-i] != 0 ) {
if( div[z] != 0 ) {
// curve[i] = min(max(curve[first]*2-curve[first*2-i],0),255); // ssS
curve[i] = min(max(curve[first]*2-curve[z],0),255);
sum[i] = curve[i];
div[i] = 1;
}
}
}

if( div[255] == 0 ) {
// tween missing last to 255
int last = -1;
for (int l = 255 ; l >= 0 ; l--) {
if( div[l] != 0 ) {
last = l;
break;
}
}

for (int i = 255 ; i > last ; i--) {
int z = min(last*2-i,255); // ssS
// if( div[last*2-i] != 0 ) {
if( div[z] != 0 ) { // ssS
curve[i] = min(max(curve[last]*2-curve[z],0),255);
sum[i] = curve[i];
div[i] = 1;
}
}
}
}


LINKS REMOVED

LaTo
12th July 2015, 10:57
I have compiled a new version of MatchHistogram, it contains a fix for the bug reported by StainlessS and the debug 256px ouput.
Available here (http://latoninf.free.fr/d9/MatchHistogram.7z) with source code.

StainlessS> I will say something in a perspective to help, not criticize... I think you over complicated code for nothing! Watch my latest sources, they produce the same result as you but yours are much less readable (a lot of noise), are way larger in size (10ko vs 17ko) and are more difficult to maintain (code duplication).
When I spend some time to read the forum I see many scripts or other works from you that seem very interesting, but when I read the code your logic is often hard to follow and I give up because I am lazy. It is unfortunate, I think a little code cleaning could really help.
Again I say that without the desire to be rude, I just propose suggestions so that people are more interested in your work!
Thanks for all, continue your work, best regards!

StainlessS
12th July 2015, 13:18
Thanks for your suggestions LaTo.
I deliberately kept the code separate and as separate function call to make it easy to rip out for other uses,
as for coding style, that is how I've always done it and it is quite clear to me.
I notice that you multiply the Y coords by pitch and add X offset rather than using a raster pointer incremented by pitch at every line,
that is a lot of multiplications that could be replaced by a simple addition every now and then, not something I would not do myself.
I did however like your overall style, but is not mine, I'm a C programmer not CPP, each to their own I guess.

And just to clarify, the TAKE_3 post also contains the bug fix.

Thanks for your work LaTo, much appreciated. :)

EDIT:
Can use LaTo's MatchHistogram with script in post #46 changing

DBUG = MatchHistogramDebug(b,a,Plane=DEBUG_PLANE,RAW=DEBUG_RAW)

to

DBUG = MatchHistogram(b,a,Plane=DEBUG_PLANE,RAW=DEBUG_RAW,DEBUG=True)


However, debug pixel sampling functionality is broken as histogram plots Luma 255 where histogram is zero (ie white outline),
original MatchHistogramDebug() plots histogram value only @ Y= 255(bottom line), outline only rendered where histogram value is greater than 0.

fvisagie
12th July 2015, 14:17
Thanks for your work, guys, sincerely appreciated and gainfully used.

Forgive me a small nit-pick:



MatchHistogram(clip c,clip c2,int "Plane"=0,bool "Raw"=False,Bool "Show"=False) : by LaTo.

Planar only. v2.6 and v2.5 plugins.

Modifies clip c histogram to match that of c2.
Plane, default 0. 0=Luma : 1=U : 2=V : 3=U+V : 4=Y+U+V
Raw default false. False raw histogram, true smoothed histogram.
Show, Default false. True show histogram on frame.

Will produce weird results if frame contents are dissimilar.

###

MatchHistogramDebug(clip c,clip c2,int "Plane"=0,bool "Raw"=False) : by StainlessS, histogram smoothing by LaTo.
As for MatchHistogram but returns Debug clip grayscale YV12 256x256 @ clip c Framerate and FrameCount.
Plane, default 0. 0=Luma : 1=U : 2=V
Raw default false. False raw histogram, true smoothed histogram.

Debug mode, returns PC Range YV12 clip @ 256x256 original framerate without audio showing curve used.
Can sample luma @ x,255 for value in curve LUT[x] (look up table) ie bottom of histogram at x position.



The description logic is reversed, also in the sample script.

visually examining tonal curve of each frame would be enormously slow and tedious.

I remain undaunted ;), although I do not intend to sample every single frame :).

StainlessS
12th July 2015, 14:30
Thank you small nit-picker, post #46 fixed.