Image displacement UV's have different values

Hello All

Ive been down a deep path of trying to understand how a image/bmp is refrenced in gh and rhino common.

When I move the points of a mesh or surface with the selected brightness value refrenced in a image, the sides do not tessilate.

First i debuged myself to see if im the problem, does the image match side by side… which it thankfully does. so the generations of the gradients are sound.

Secondly i move the mesh to the side in X to check the diffrence in just the grey scale parts and as you can see from the pink and green lines they do not match?

Any ideas on this? Or how does the point call a pixel
Color c = bmp.GetPixel();

Attached the file and the image im using.


Image tessilation Forum.gh (10.1 KB)

Hi @Peter_Davis,
which plugIn are you using to show the values inside the parameters?

Thanks

Hi by value i mean the color value as brightness

I meant, how you got these:
grafik

PersistentDataEditor and i can highly recommend QuickConnections also. all found in package manager in rhino. Yak for the win.

1 Like

As I remember, if not input x and y, one pixel = one mm. But last vertices on mesh may not match to last pixel in each raw.

1 Like

what do you mean by the last vertices?
Thanks for the help, just want to understand it then code something to mitigate the problem

Last vertices In one direction u or v.

So after some coding yesterday the UVs must be less than the pixels or the function throws an argument. (as seen in the picture, If i add +1 to the width In resize bitmap it works fine)

This means that its alway referencing at minimum one pixel inwards on the picture, and if that gradient is not linear then then you will get a gap.

Same thing happens with the gradients on your Surface Relief plugin @zhuangjia777 ,also all other functions inside gh.

I did find a work around, where i replace the left most points with the right most points and this smooths out the mesh, but in short its a shame you cant reference every pixel as a point.

1 Like

Interesting. Thank you! I will look at this.
I would like to issue you a SurfaceRelief license as gift. So you you can use it freely.
There is a UID component (at second position from left). It will generate your unique id (like xxxx-xxxx-xxxx-xxxx). copy and pass it to me. I will write your UID into a license file.

1 Like

Not on my pc now but I think some of the problem are due to the fact that pixel data of an image are put on the vertex and not on the face. But face represent the pixels
It is more difficult to put a color on a face but it is doable. I encoutered this problems with my plugin.

Nice, this was my inital thinking. thanks for the responce.
Currenly coding something similar

I choose for one of my tool “Populate Image” to put color at vertex (black an white image) so there is a shift of 0.5 pixel
The other tool put color at face (not fast on big image)
The Legacy tool is Grasshopper tool
All here with a 10x10 pixel image
test images

image differences.gh (7.9 KB)

Here is the code

/// <summary>
  /// https://discourse.mcneel.com/t/color-mesh-by-faces-one-single-color-for-one-face-using-api/143074
  /// </summary>
  /// <param name="fileName"></param>
  /// <returns></returns>
  public Mesh ImageToMeshColorOnFace(string fileName)
  {
    Bitmap bitmap = new Bitmap(fileName);
    int height = bitmap.Height;
    int width = bitmap.Width;

    List<Color> colors = new   List<Color>();


    for (int j = 0; j < height; j++)
    {
      for (int i = 0; i < width; i++)
      {
        Color col = bitmap.GetPixel(i, j);
        colors.Add(col);
      }
    }
    bitmap.Dispose();

    Mesh mesh = new Mesh();


    for (int j = 0; j < height + 1; j++)
    {
      for (int i = 0; i < width + 1; i++)
      {
        mesh.Vertices.Add(new Point3d(i, height - j, 0));
      }
    }
    for (int j = 0; j < height; j++)
    {
      for (int i = 0; i < width; i++)
      {
        mesh.Faces.AddFace(new MeshFace(i + j * (width + 1), i + 1 + j * (width + 1), i + 1 + (j + 1) * (width + 1), i + (j + 1) * (width + 1)));
      }
    }
    mesh.RebuildNormals();

    mesh.VertexColors.CreateMonotoneMesh(System.Drawing.Color.Black);
    mesh.Unweld(0, false);
    for (int i = 0; i < mesh.Faces.Count; i++)
    {
      mesh.VertexColors.SetColor(mesh.Faces[i], colors[i]);
    }

    return mesh;
  }
[image differences.gh|attachment](upload://aMkRYbanIyf0pRufZagzW7cTeOQ.gh) (7.9 KB)
2 Likes