View Full Version : Subtracting one pixel with the neighboring pixel on the left
real.finder
11th August 2018, 01:35
as the title said, how can do subtracting one pixel with the neighboring pixel on the left in avs?
wonkey_monkey
11th August 2018, 01:51
Using rgba_rpn/y8_rpn (https://forum.doom9.org/showthread.php?t=172601) you could do this:
clip.rgba_rpn("[c0] [c0(-1,0)] -") # or y8_rpn for yuv clips - you can extractu and extractv to do the same processing on the chroma planes with separate calls to y8_rpn
This should work, but I'm in the middle of a big rewrite on that plugin so I may have got it wrong.
For a non-plugin method, you can crop/addborders or do a shifted resize to make a second clip, then use overlay with mode="subtract".
What's best depends on what you're really trying to achieve.
johnmeyer
11th August 2018, 05:17
Your request is somewhat similar to how a convolution kernel works:
http://avisynth.nl/index.php/GeneralConvolution
wonkey_monkey
11th August 2018, 12:24
Oh, yes, there you go - johnmeyer's solution is ths simplest.
real.finder
11th August 2018, 14:50
thank you both :)
GeneralConvolution only for rgba (I need YUV/Y since I am plan to make mask for Analog video artifacts), and rgba_rpn/y8_rpn not work with Y8 and since it's Closed source I do not tend to use it in scripts for many reasons (I have had enough suffering from deen() and others Marc FD/prunedtree filters not being update and get x64 builds)
so I think "crop/addborders or do a shifted resize to make a second clip, then use overlay with mode="subtract"" is the best option for now even if it not look nice as others
pinterf
11th August 2018, 18:40
Or use Expr in avs+, see pixel addressing
http://avisynth.nl/index.php/Expr
wonkey_monkey
11th August 2018, 20:13
rgba_rpn/y8_rpn not work with Y8
It does, that's what y8_rpn is for!
real.finder
11th August 2018, 22:24
It does, that's what y8_rpn is for!
it show unhandled clip type: -536870912 unless I use yv12
real.finder
11th August 2018, 22:25
Or use Expr in avs+, see pixel addressing
http://avisynth.nl/index.php/Expr
will check it
real.finder
13th August 2018, 00:51
ok, here simple function
Function spixsub(clip c, int "left", int "top")
{
left=Default(left, 1) #set the "left" to 2 will make it 2 pass since the subtract mode in overlay ignore the negative result of subtracting
top=Default(top, 0) #same as left parameter
c
left > 0 ? PointResize(Width(), Height(), src_left=-1) : last
leftsub = left > 0 ? overlay(c,last,mode="Subtract") : last
left > 1 ? overlay(leftsub,overlay(last,c,mode="Subtract"),mode="add") : leftsub
h=last
top > 0 ? c : last
top > 0 ? PointResize(Width(), Height(), src_top=-1) : last
topsub = top > 0 ? overlay(c,last,mode="Subtract") : last
top > 1 ? overlay(topsub,overlay(last,c,mode="Subtract"),mode="add") : topsub
top > 0 && left > 0 ? overlay(h,last,mode="add") : last
}
and mt_convolution seems can be used too, but it not give same output as above with mt_convolution("-1 1 0")
will see if avs+ Expr can do it better and cleaner, didn't test it yet, maybe I will add it in spixsub() since I don't want to drop normal avs support yet
edit: more advanced version https://pastebin.com/WkVUQDu5
edit2: final one with expr in avs+ added in Advanced Denoising.avsi (http://forum.doom9.org/showthread.php?p=1750019#post1750019)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.