Displacement map from image

Hi there,

Should be a quick one. I wrote some code to import an image and create a mesh based on the displacement of the brightness of the pixels corresponding with an amount of vertices that is set parametrically. This is my first time doing displacement mapping in grasshopper and the result is totally off. I followed a tutorial with the only difference being that the size of the mesh is extracted from the image imported as a surface and the resolution of the mesh is set parametrically.

This is the tutorial I followed: [displacing a mesh with an image]

image displacement.gh (1.5 MB)

Thanks in advance

Hello

Your surface in not internalized :sob:

image

I think your problem is that your Image Sampler has a 2D Domain going from 0 to 1, but your surface is most likely bigger, so the point coordinates are outside this domain. You need to remap your X & Y coordinates from the original surface domain to [0,1].

image

2 Likes

Oops, forgot to internalize it…

Aah, ok. Thats most likely it. Will try once I get home :slight_smile:

I found out I have no idea how to remap coordinates. The best thing I could come up with is to extract the max number of the coordinates list and divide the coordinates by it. However, even this doesn’t fit the total x length of the image, and it doesn’t fix the problem of the v-coordinates being cut off because of the image not being square.

So I’m at your mercy once again …:slight_smile:

This time I did internalize the image :wink:

image displacement.zip (1.5 MB)

Hello,

The simplest solution was to Reparameterize the input surface, so its domain goes from 0 to 1 (right clic > Reparameterize). With your soltion it could have worked if you did the division on U and V coordinates separately.

I also took the liberty of simplifying your grid creation… You could also use the Paneling Tools library, downloadable from Package Manager.

image displacement.gh (1.5 MB)

To reparameterize was my first guess actually. Except I didn’t consider reparameterising the surface itself. Instead I tried the input and the last component, both of which didn’t work of course. Well, this is how you learn.

I am a little confused by one thing, if you don’t mind me asking. What does the “dimension” component measure exactly? Because the dimensions remain unchanged after repam. You would assume both u and v dimensions would change to 1 after. Instead, they remain unchanged. Pretty curious about that.

Does that mean I should extract the u and v coordinated seperately, divide them and then create points based on u and v coordinates? I thought about that too, but I didn’t find the right components for it. What would you have used?

Thanks a lot for everything. People like you make learning grasshopper manageable :smiley:

It measures the lenghts of the surface, in both directions.
Not exactly sure what happens if the surface is not a nice rectangle though ! I guess it takes sort of a bounding box in that case. Maybe better to use Deconstruct Brep to retrieve the real edges and measure their lengths.

The 2D parameters are actually Points, so you can access coordinates using Deconstruct. Then normalize the U/V (X/Y) by the surface dimensions.
There is a slight complexity coming from the fact that your surface doesn’t start at 0,0,0, I used the parameters here, if you want to stick with points, then you have to compute the coordinates of the bottom left corner of the surface and add them before dividing.

I know, but I meant: doesn’t repam reduce those lengths to 1?

Ok, that all makes perfect sense. I forgot about the “Deconstruct” function. So many to remember haha. How do you wright your functions so that they appear with mockup?

No, it only changes the surface domain, which is a sort of local coordinate system. It doesn’t scale the surface.
Usually, the surface domain is defined by Rhino when the surface is created, based of the curve domains of the borders, or the rail curves (for a loft or a sweep for instance).

Without reparameterize :

With reparameterize :

I don’t understand what you are asking for ?

Did you try import image?

disp_.gh (8.3 KB)

Ahh, ok. Thanks. Good to know

I studied this code for a bit, but frankly there’s too many functions I have never used nor know the purpose of in here. For now I wouldn’t know how to use it. But thanks for the effort and at some point it might be of use for me.

Is there a different way to create a mesh from the displacement? Due to the triangulated nature, the mesh becomes very jittery and uneven.

Hi again,

I’ve changed the mesh creation using Mesh Plane, to have a regular grid. This has a better aspect in XY plane.

Then you could use Smooth Mesh, or convert the mesh to a SubD at the end to have something less kinky. Reducing the amount of points will also help getting somethign smoother.

image displacement.gh (1.5 MB)

You’re amazing. Thank you so much :smiley:

1 Like

Texture Displacement: