Log in

View Full Version : PaintBucket/fill script


Hadien
19th December 2007, 00:48
I did a search and found an old thread that mentioned using a color key Mask. However, I was looking for a script capable of filling a "contiguous" area from a certain point on a frame. I mean more specifically that it fills only the pixels confined by the other colors from a point... For example, its a lot like the paintbucket effect in Aftereffects or the color fill tool in Microsoft Paint(but with a tolerance option)

I'm thinking of making this a component of a larger function I'm trying to develop... though I'm still a bit new to the AVISynth language itself...

I first wanted to see if such a function existed, and If one didn't, how I would go about to creating one...

Sagekilla
19th December 2007, 03:53
You could try doing something like a mask where you selectively choose colors that fall within a tolerance range, and then set those pixels to a color and replace the old pixels with the color you want it to be.

How you would go about this though, I have absolutely no idea, but I can at least give you an idea of how it (in my eyes) might be done.

foxyshadis
19th December 2007, 07:58
Flood fill algorithms are easy to find, for instance (http://en.wikipedia.org/wiki/Flood_fill). Heck, the simplest method might even be to pull the relevant code out of GIMP or Inkscape and plop it into SimpleSample or your favorite open-source filter.

It'd be possible but probably impractical to build one with existing filters, unless you used CelForeground somehow.

Wilbert
19th December 2007, 18:59
Try MaskHS in AviSynth 2.6.

Hadien
19th December 2007, 23:11
2.6 eh...
heh, Looks like I'll have to update... thanks for the heads up.

@Foxshadis
Finding the algorithm for a paint fill isn't the real problem. Its how you would implement it through AVISynth... I mean how to work on a frame pixel by pixel... The closest thing I found to evaluating a frame by pixel were the "colorspace"LUT filters. but even those filters I can't quite understand. I tried following their examples but I can't seem to get any results. I guess I'm just misinterpreting what the filters are used for. Not even sure I need them...

Thanks for the link, that scanline fill sounds more promising (though I'm still in the same boat on how to construct it)

And I'll try the MaskHS and see how it would help.
Update:Oh 2.6 is a pre-Alpha... Guess I should be careful...

Wilbert
20th December 2007, 22:36
And I'll try the MaskHS and see how it would help.
Update:Oh 2.6 is a pre-Alpha... Guess I should be careful...
Yes, you should be :) I can always make a separate plugin (for v2.5) from it when it's worthwhile.

Hadien
21st December 2007, 10:39
I'm looking at the documentation for MaskHS... And though I do see many uses I can get out of it, I don't see how it can offer me a contiguous area for a selected color from a given point.

Is there any way you can call up the value of a certain pixel location and change it,per frame? like pixel[x][y] for Frame z (or all frames) or something? (and yes, I'm sure it wouldn't be an array since arrays are not native to AVISynth, but bear with me)
for example:

...
#assuming the colorspace is RGB and the clip is 720X480
#this will change the center pixel to the color red
pixel[360][240] =$FF0000
...

If thats not possible then is there any way to make a function to handle this? and upon further thinking if the current version can't support it do you think its possible for it to show up in a later version? Being able to do this would surely help in me writing out a fill script. Or am I just underestimating MaskHS?

Edit: As for that CelForeground... All I can find on that is a dll... I don't even know what arguments or functions it has or how it exactly works. the closest documentation I came to it was where Foxyshadis was recommending it to someone else in another thread...and looking from the pics posted using CelForground, it doesn't look like what I'm looking for...

squid_80
21st December 2007, 11:15
Yes, you should be :) I can always make a separate plugin (for v2.5) from it when it's worthwhile.I already did that a while ago since I needed it. Returns a YV12 clip with blank chroma planes instead of a Y8 clip. Also requires VS2005 SP1 runtime libraries.

Edit: Link removed. See below for new link.

Leak
21st December 2007, 12:47
My 0.02 EYPO:

Implementing a fill algorithm in an AviSynth script would be dog slow, and moreover AviSynth scripts lack a useful loop construct and aren't meant to be run on a per-frame basis.

So your best bet would be to write a filling plugin in C/C++ (like suggested earlier) and call that from your script.

np: Yello - How How (Papa-Who-Ma-Mix) (Eccentrix Remixes)

Wilbert
21st December 2007, 23:07
@Hadien

However, I was looking for a script capable of filling a "contiguous" area from a certain point on a frame.
Could you explain what you mean by a "contiguous" area?

This zip-file contains documentation of CelForeground:

http://www.geocities.com/wilbertdijkhof/CelForeground_08Sep05.zip

and also this thread:

http://forum.doom9.org/showthread.php?t=99778

but i never used it, so i don't know its possibilities.

@squid_80,

Thanks! Could you also include the source?

Hadien
22nd December 2007, 03:00
@Leak
your best bet would be to write a filling plugin in C/C++ (like suggested earlier) and call that from your script.

I guess so... I'm not exactly sure how to make it interact...Do I simply make the function into some dll then simply import (LoadPackage) it into my script and call it? or is there something more to that... guess it wouldn't hurt for me to just play around a bit...

@Wilbert

imagine you're using Paint and you just have a blank screen. you then make a simple box shape in the center. the color inside the box and the color outside the box are both the same color (white) while the box line is black. If you only want to turn the color inside the box to another color (lets say red) you would use the paintbucket tool paint has. you would select the color you want to change to in the palette then fill in the box with a red color.
notice it only fills in the white pixels inside the box, not all the white pixels on the canvas. Thats what I mean by contiguous... it doesn't change all the pixels that have the color on the frame. just the white pixels that are adjacent to other white pixels to which down the line is adjacent to the pixel location you define... (it sounds to me that I'm over complicating the definition)... if you were to select a position outside the box instead, then the white outside the box would be red while the inside would remain white.



of course if there were some way to use MaskHS (or ColorKeyMask, or something similar) to find all the colors you plan to change then subtract all the areas that wouldn't have the target location. It would end up with the similar (if not, exact) result I'm looking for...

vcmohan
22nd December 2007, 04:20
In my Colorit plugin the mask creation functions and color fill functions are available. May be tried.

squid_80
22nd December 2007, 07:00
Thanks! Could you also include the source?

www.digitalfoundry.org/andrew/MaskHS_src.zip
Includes both source and a compiled dll. (It's called avisynthplugin because that's what my skeleton filter project is called and I never changed it.)

edit mod: link: http://www.geocities.com/wilbertdijkhof/MaskHS_src.zip (dll included; docs: see v2.60 documentation).

Hadien
22nd December 2007, 08:00
In my Colorit plugin the mask creation functions and color fill functions are available. May be tried.

THANKS!!! your Colordrops function did the trick for me and with it I was able to use it to finish my other function (a simple auto-rotoscoping function). theres is also a number of other functions in your colorit.dll I could use as components.

the reason I needed such a fill function was because I was challenged in making a vid just using AVISynth and so using applications like Premiere Pro and Aftereffects (or your favorite editing and compositing program)were prohibited. the point of the challenge was to show off what AVISynth could do... and while using something like a fill script (or a simple rotoscoping script) isn't what AVISynth is meant to do, I just wanted to show that AVISynth is capable of being abused and do these things.

and although my Rotoscoping function is extremely slow by AVISynth terms, it'll definitely be much faster than doing it manually through AE. so much that it'll likely be integrated into my workflo from now on.

Thanks to everyone for the help!!

BlueCup
23rd December 2007, 21:56
Have any samples of your work that you can post here?

Hadien
24th December 2007, 06:42
here:
http://i253.photobucket.com/albums/hh77/Koensayrbtls3/AutoRotoexample.jpg?t=1198472675

Running from top left to right to bottom right:

1. The first one is the original source.
2.The second is the area I want the function to rotoscope.
3.Third is the original after going through my DefineLine function (clip orig, int "power", float "thickness", bool "denoise", int "radius", int "Luma_t", int "Chroma_t")
using spatial softening, convolution Kernel, then Binarize
4.Fourth is having the second mask the output of the third
5.Fifth is the result of a number of functions (including the ColorDrops Function) within AutoRoto()
6.the final shows the completed version in RGB32 (with the black background already transparent)

My function AutoRoto() has different modes so it can return one of the last four if given the first two. I'm also planning to add extra modes so that if you already have one of the other masks you can add it in as the second clip argument and call a different mode depending on which you input. the function currently has both feathering and mask expansion. (this example is using an expansion of -3 and a feathering of 10)

peter100m
28th December 2007, 10:54
Hadien: wow. nice work! Is AutoRoto something you consider making public? It would be a great addition to Avisynth!

Hadien
28th December 2007, 13:28
I hope to...I would love to contribute to the community but I will say up front that I wouldn't have gotten so far without vcmohan's ColorIt plugin, I wouldn't feel right if I didn't say I was helped.

But I feel its nowhere near ready for public use. I've only performed one test case (initially, I only planned on using it once in the project) and theres a lot of hard code, so I don't know exactly how much of that hard code actually needs to be dynamic. Plus I'm not yet fixed on how much functionality I want it to have...

currently, the way I have the function set up you can only fill one area, while the ColorDrops() allows for multiple fill locations. The way I plan to get around this is allow Autoroto() to return the masked lines clip (#4 in my example) to where the user manually ColorDrops all the areas (just so You know, I choose the areas you want to be transparent;first argument is a white blankclip, and the color to fill with is anything but that white... any color not close to white anyway) then call it back into the function using a new mode, or simply do the rest it manually