photoshop paint bucket
Hello,
Does anyone know how to fill a custom shape made in lcd (or jit.lcd) with full color?
Is there a paint pot feature somewhere or at least a way to do it ...?
But I use photoshop. its coool.
wow, that would be cool... and I'm thinking pretty tough. maybe you could do a hack like this:
1--start where you click, and assume you're inside the shape.
2--get the color where you are, and assume the color is the same everywhere in the shape. change the pixel to the desired new color.
3--go left (- pixels in X direction) and repeat until you hit another color, and assume that's the shape edge. stop.
4--go right (+ pixels in X direction, from original point, do similar change until the other edge. stop.
5--go up one pixel and repeat everything, until another edge. then repeat going down. however, this won't work all the way unless you're in the middle of the shape, argh.
Probably there is a much more savvy trick using better edge detection techniques. But this might provide some interesting results, even if it doesn't always work perfectly. Example: if the shape is mostly closed, but not all the way, will it spill out? With this technique it would, but only in the direction of the break. Etc...
An interesting challenge regardless. Just trying to make something hacked together for it should yield some new tools and insights. Using jit.lcd is probably better, so you can take advantage of the matrix operations. Maybe there's a combination of several jit.ops which will do most of what you want.
A flood fill algorithm isn't too hard to build, but i'm not sure how to do the recursion in Max. It'll probably generate a stack overflow relatively quickly if you do it with Max-objects, but maybe in Java?
This will fill a space (and go around corners too and spill) and stop when it reaches pixels with a different color. Anyone feel like getting this into Max? Hehe.
Edit: you could probably build a stack of pixels to be updated in Max as well and pop items to avoid recursion.
floodfill(x, y, selectedcolor, newcolor)
{
if (kleur(x, y) == selectedcolor) // insert threshold here
{
changecolor(x, y, newcolor) //function that sets new color
floodfill(x, y + 1, selectedcolor, newcolor)
floodfill(x, y - 1, selectedcolor, newcolor)
floodfill(x + 1, y, selectedcolor, newcolor)
floodfill(x - 1, y, selectedcolor, newcolor)
}
}
The recursion/stack overflow might not be an issue, as long as you have a comparison operator for each new pixel tested, and you also stop the recursion if X or Y coordinates go below 0 or above your maximum (dimensions of the LCD or whatever you're using). A [trigger b b b b] where each of the bangs deals with the X+1, X-1, Y+1, Y-1 respectively, and probably a [defer] before the recursion in each. Though I don't know if the [defer] or a [deferlow] would allow the other trigger bangs to fire before the recursion is done?
By comparison operator, do you mean a boolean per pixel that says whether it's triggered? You don't need that, when a pixel is tested that's already colored it will not have the original color, and will not add new pixels to the 'stack', and the code will continue to the next pixel.
And you're correct about the edges, of course. I'm a little bit scared of using [deferlow] and [defer] in cases like this, but in theory it doesn't matter in what order pixels are handled, as long as every item is processed. So you could theoretically use the thread as a stack, but I don't know how long the stack can be (theorically it could reach 4 * amount of pixels in the image). May be a better idea to build a separate stack?
ok,
so I suppose dilate and erode and morphology objects would be of any use in that case.
As the jit.conway object ...
Also the xray data process objects can probably do something here.
I'm just starting with OOP, but I understand that it would be easy to do it in JS.
So many thanks, I will investigate further and come back here if I get clever results.
Did you know this cv.jit.floodfill?
Hi all, I'm hoping to build my own fill algorithm, here seeking advice
I'd like more granular options than I see in cv.jit.floodfill-- I want to be able to tweak parameters and animate it
I understand that trying to do it with standard max objects would be pretty computationally inefficient, but I'm not sure where else to start-- is this something I could make happen with gen objects? Or something else?
i have given up on this long ago because it is more work than you would first think.
filling means making selections, and that can get very laborious in jitter since making selections in photoshop style means having one extra matrix for each selection (mouse movement), which consists of one or multiple alpha channels, and which then can be combined or substracted from each other using yet another matrix...
Thank you Roman! Yeah, its been more of a head-scratcher than I bargained for.
Hi,
Here's a flood-fill algorithm implemented with javascript
The algorithm uses recursion, therefore, it's straightforward to implement in Javascript but not trivial to implement using standard Max programming, although not impossible.
(Here's a version of the same algorithm without recursion: https://it.wikipedia.org/wiki/Algoritmo_flood_fill )
hi matteo,
sadly i get this error message:
js: fillSelection.js: Javascript InternalError: too much recursion, line 23
I am on ARM64, Mac, v 8.5.5.
p.
Hi Petcode,
I see, I get the same error when trying to fill large chunks of the image. There's an internal protection of javascript against potentially infinite recursion.
Here's a version of the code above which doesn't use recursion but instead keeps track of the pixels still to evaluate using a stack:
It should work as expected now
hi matteo,
works great! thanks for the fast reply.
p.