Proportional grid for Image Sampler

Been a long time since I used the Image Sampler, so I don’t remember how to do this…

I have a non-square image of x pixels by y pixels and I want to sample it with values that are in the same proportions as to x to y. I can set the sampler to use image pixel dimensions, but how do I know what the pixel proportions are beforehand so that I can set up an XY grid as input that’s proportional to the pixel dimensions?

Otherwise, if I use a square grid, if the image is not square, it becomes distorted.

TIA, --Mitch

I use Josephs setup. (132.0 KB)

1 Like

I wish there were a built-in way to extract pixel dimensions of an image in order to do this more easily. Even in Joseph’s setup, it looks like you manually have to enter in the pixel count.

1 Like

Yep, that what I was trying to avoid, but it looks like it’s not possible…

you can use this trick to get the number of pixels of the image. I put the 100 in order to have a low mesh and not a 16 millions vertexes mesh if you want to open a big image.

So with image sampler you keep using 0 to 1 width and height but has you know the number of pixel il will be easy for you to convert that in pixel size.

And you could also avoid Image Sampler if you use the mesh (from import image) as a support to get the color.


If you’re willing to rely on a plugin, shutterbug can read a bitmap from a file path and return its dimensions - it can then also sample that bitmap object just like the image sampler would:

1 Like

OK, thanks guys. I need to have this as bog-standard without plug-ins as it goes to a client, and I also want to use the image sampler for several reasons - so, either I have them simply write down the pixel dimensions from the image sampler and input them elsewhere for the calculation or I have them reference the same image file with the image import parameter component as per Laurent’s solution and use that…


Don’t actually need to have more than 2 for the x,y values if all you want is the pixel dims.


Can you use System.Drawing.Image in python? in some way???


I have used System.Drawing.Bitmap in the past in some python scripts, and even scripted a simple sampler. So yeah, I could. But that’s too much work. :stuck_out_tongue_closed_eyes: Plus the GH image sampler has a lot of possibilities already programmed in.

I threw some suggestions for the Image Sampler component into the GH2 category here: