View Full Version : conditional convolution filter
mathmax
16th September 2012, 20:24
Hello
I would need a convolution function in which each pixel of the matrix is only taken into account under a certain condition.
The condition would be written in reverse polish notation. Ideally, it could depend on other pixels' values targeted by the matrix.
I guess such function doesn't exist.. so the solution would be to write it in c++. However, I have no experience in such task..
Would someone here be so kind to code it? Even a draft code would be welcome.. and I will do my best to finish it.
Thank you in advance :)
mathmax
30th October 2012, 22:05
bump.. :)
Guest
30th October 2012, 22:08
Your specifications are ridiculously vague and the purpose of the function is not described at all. It should not surprise you that no-one responds.
jmac698
31st October 2012, 00:27
Your question makes perfect sense to me. For a given matrix size, say 3x3, you want to apply a conditional expression to the pixels. For those pixels that remain, you want to perform a convolution. I've tried doing pixel level calculations before, and avisynth script is just not suited to it. The sample created by StainlessS helped me to start writing filters. However, now you have a new option, with VapourSynth. If you can learn some Python, you can do some pixel level scripting.
It's also possible to work out your expression mathematically; if it's separable, you can use some column expressions, or combine multiple convolutions in a conditional way. This could be done in masktools.
There's one other way, in avisynth 2.6 you have separate columns, what you can do is express the pixels of a frame of video as n frames of video, but each is a small square, then it's easier to work on individual pixels. I did this with the splitrows function to be able to apply per-line effects in a filter.
Guest
31st October 2012, 00:37
Your question makes perfect sense to me. Then you should provide the "draft code" that the OP asked for. :devil:
mathmax
31st October 2012, 02:02
Your specifications are ridiculously vague and the purpose of the function is not described at all.
I would rather say it's a generic function.. so its purpose is wide :)
It's has the same purpose as a normal convolution filter but it takes the pixel of the matrix into account only if they match a mathematical condition..
Your question makes perfect sense to me. For a given matrix size, say 3x3, you want to apply a conditional expression to the pixels. For those pixels that remain, you want to perform a convolution.
Thank you. You exactly got my point. And it's reassuring to see that my explanation can be understood :)
I've tried doing pixel level calculations before, and avisynth script is just not suited to it. The sample created by StainlessS helped me to start writing filters. However, now you have a new option, with VapourSynth. If you can learn some Python, you can do some pixel level scripting.
I don't know Python unfortunately. That would investment to learn it only for this plugin.. :s
But thanks anyway for the hint.
It's also possible to work out your expression mathematically; if it's separable, you can use some column expressions, or combine multiple convolutions in a conditional way. This could be done in masktools.
What is a 'column expression'?
The solution with masktools interests me a lot.. but I don't see how you would achieve this..
There's one other way, in avisynth 2.6 you have separate columns, what you can do is express the pixels of a frame of video as n frames of video, but each is a small square, then it's easier to work on individual pixels. I did this with the splitrows function to be able to apply per-line effects in a filter.
Now I'm the one who don't understand this part.. I read several times, but I may miss some knowledge to understand it. :(
jmac698
31st October 2012, 05:34
What I mean is, in order to work on one row of pixels at a time (in my case, to apply a horizontal shift), I had to write a function to split hte video into lines. The difference is, now there's 480 videos, each 720x1 in size. You could separate a video into thousands of squares, then each square is small enough to write explicit pixel operations on.
Another way, is to use gscript. You can write a for-next loop in script, and by using crops, access individual pixels. It could be slow though.
Do you have any specific conditions in mind? A separable filter means, one that can be applied in several steps of smaller filters, such as one column at a time, then one row at a time. In that case, you can make conditions on the sub-steps.
But I'd have to say, ultimately for speed, a plugin would be a good solution.
Search of avisynth for c progrrammers... stainlessS wrote it.
mathmax
1st November 2012, 01:06
Thank you for the explanations.
A specific condition in mind? Well yes.. I would like to use this kind of conditional convolution filter in order to remove the halos caused by over sharpening in old VHS.
So basically a halo is a black strip between bright area and a darker area. To remove it, I have to blur over this strip.. but a normal convolution will blur in any direction and the bright edge will smear on the black strip. So a simple condition would be to exclude the pixel which have a luma value upper than a threshold. A more accurate condition would be to exclude the pixels upper to the average values of the matrix (or any other custom formula).
Does it make sense?
jmac698
1st November 2012, 19:50
You can make a one directional kernal for that. Take any blur kernel, and zero out the top and bottom rows. You can even make it left or right acting only, by zeroing out the left and right terms. Use masktools with the custom kernel string.
mathmax
1st November 2012, 20:16
You can make a one directional kernal for that. Take any blur kernel, and zero out the top and bottom rows. You can even make it left or right acting only, by zeroing out the left and right terms. Use masktools with the custom kernel string.
It's not only about blurring to the left or to the right.. the direction may also be oblique and I find it nice to have full control over the pixel with a mathematical expression. Thus, I can give more importance on some of them.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.