Map by difference in hue/rgb

   1193   4   1
User Avatar
Member
2 posts
Joined: 10月 2023
Offline
I'll prefix this by saying I'm quite new to Houdini so please bear with me.

I am trying to make a mosaic generator from a texture. So far I have it that I can import a texture (attributefrommap), scatter points based on Cd, fracture with voronoi, exploded it a bit, and extrude then bevel top faces. All well and good. But ideally, the pieces arent just the same sizes, but based on the difference in hue/rgb. So if I have a large black dot ontop of a rainbow, the rainbow will be made of small pieces because there is a change in hue, whereas the black dot will be 1 piece (or multiple large pieces so its not just 1 large round piece).

So my thinking is I need to make a "density map" that I can use to drive the density attribute in my scatter node. The problem is I can't figure out how to create said map based on changes in rgb. And I would of course need control of the range, because not every black pixel will be exactly the same, so it would need to check for a range, and if the neighbouring pixel is outside that range, it would create a new scatter point.

Hopefully this makes sense.

Attached is my work file with the image removed from the attribfrommap node. I also added an image of an elephant that has some hue changes, but also areas of solid (or almost solid) colors.

Attachments:
Mosaic_generator.hip (302.8 KB)
IMG-6903.jpg (126.4 KB)

User Avatar
Member
8026 posts
Joined: 9月 2011
Offline
The are VOP nodes to convert from RGB to HSV and back, if that helps get you started.
User Avatar
Member
4672 posts
Joined: 2月 2012
Offline
Hi,

Here is one way:

Store hue for each point first (Point Wrangle):

vector hsv = rgbtohsv ( @Cd );
@hue = hsv.x;

float threshold = ch("threshold");

int pts [ ] = pcfind ( 0, "P", @P, ch("radius"), chi("maxpts") );
removevalue ( pts, @ptnum );

foreach ( int pt; pts )
{
    float hue = point ( 0, "hue", pt );
    if ( abs ( hue - @hue ) < threshold && @ptnum > pt )
    {
        removepoint ( 0, @ptnum );
        break;
    }
}

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
682 posts
Joined: 9月 2013
Offline
Hi Sepins,

you can transform to various color spaces:

int mode = chi('mode');
int comp = chi('component');

string space[] = array(
    "cspace:rgb",
    "cspace:hsl",
    "cspace:hsv",
    "cspace:XYZ",
    "cspace:Lab",
    "cspace:tmi"
);
vector clr = ctransform(space[mode], v@Cd);
f@val = clr[comp]; 

and extract image contours after blurring val:

f@density = abs(f@val - f@opinput1_val);

Attachments:
elephant_mosaic.png (640.8 KB)
mosaic_voronoi.hipnc (186.9 KB)

https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
2 posts
Joined: 10月 2023
Offline
Thanks a lot for the feedback! Now to read up on the code and how it works
  • Quick Links