cv.jit.blobs.centroids on fluid patch

Diego Sirigu's icon

Hello,

I've replicated the patch from this video:

and am looking to integrate the cv.jit.blobs.centroids object into it. Could anyone provide guidance on how to achieve this integration effectively?

Thank you!

TFL's icon

The help file of [cv.jit.blobs.centroids] is quite self-explanatory already, difficult to be more explicit. You could just apply it after [jit.matrix dye] or [jit.matrix @t render] I guess, but maybe there are more clever way to find centroids/blobs in here given that you already have some matrices with the underlying values of the simulation. It really depends on what you want to do with these centroïds at the end.

Diego Sirigu's icon

Thank you for the explanation! My goal is to extract the coordinates of the fluid elements and their respective areas so I can map them to some controls (e.g., MIDI or other interactive parameters).

Could you suggest the best approach to achieve this using [cv.jit.blobs.centroids]? Should I preprocess the matrix (e.g., applying a threshold or filtering) to get better results, or is there a specific setup you’d recommend for this type of mapping?

Thanks again for your help!

Wil's icon

From cv.jit.blobs.centroids

spill 4 planes

you only need to map horizontal and vertical (plane 0 and 1) to mouse position of that fluid patch

Here I use jit.grap and absdiff to detect motion

look inside [p spill]

Max Patch
Copy patch and select New From Clipboard in Max.

TFL's icon

Could you suggest the best approach to achieve this using [cv.jit.blobs.centroids]? Should I preprocess the matrix (e.g., applying a threshold or filtering) to get better results, or is there a specific setup you’d recommend for this type of mapping?

Did you try anything yet? You ask for what to do, not how to do it, and you have pretty good guess about what to do already, so why don't you try yourself and see? Unless your question is actually a how, which would need to be more explicit then :)

Anyway, if you could provide what you did already, even if it's just the patch for the fluid simulation, it would be easier for us to help you. as we could make some testings without having to follow the tutorial to remake the patch ourselves, and without having to guess and assume what you already have. "A patch is sometimes worth a thousand words".

But since you asked what:

Looking at the outputs of the fluid simulation in the video, a wild guess would be: set a quick fading time in the simulation (the fade parameter is implemented at the very end of the video). If you want to detect blobs, you actually need blobs, ie. areas that can be considered as detached from each other, and a quick fading time seems to produce more of these. Then, use high contrasting colors, black and white should be best, and maybe you'll indeed need some preprocessing, like increasing contrast, applying a threshold... But you had theses answers by yourself already!