Here is my "One Line Image Sampler" (Grasshopper)

Hi there,

recently I was playing around with the built-in ImageSampler component of Grasshopper. But while this is certainly a very useful component used in thousands of projects… I was not too happy with it.

Unfortunately, my software development skills are by far not enough to build something “better”. Nevertheless I wanted to create something “more useful for my needs” - and maybe for many others as well.

So I created my own, very simple ImageSampler component. I mean VERY simple. :laughing: In fact, it is literally only one line of code in Python (I know, not the best coding style, but just for fun I squeezed it until it fit). So here it is - the “One Line Image Sampler by ORE”. :wink:

Color = Bitmap.GetPixel(round(Point[0]*(Bitmap.Width-1)),round((1-Point[1])*(Bitmap.Height-1)))

One line of code is usually not woth mentioning, but my ImageSampler component offers one important feature, that the original ImageSampler is missing: An input for the image file. This also allows getting the image dimensions programmatically - a feature that is really missing in the original ImageSampler.

Please try it out and let me know your thoughts - and give a like :heart: if you do.

ImageSampler_ORE_V1.gh (14.0 KB)

The demo allows direct comparison to the original ImageSampler.

Here is the test image used in above demo (please reference it in the file path and in both original ImageSampler components in the demo):

image

This is a personal fun project with no warranties. It has no error handling and no production level quality. Use it at your own risk. In case you think it is stupid nonsense, please be kind anyhow.

Oliver

3 Likes