# How to get color data out of the image in Rhino by Grasshopper?

How to get color data out of the image in Rhino by Grasshopper?

I tried to use “Deconstruct Mesh” to finish but failed.

Where does the image come from? Is it a bitmap? A texture?

Sorry for misunderstanding.

It’s a bitmap and PNG file.

I am thinking, Should I map this color image on a mesh, and then bake it out? Also, someone suggests me to use image sampler but I don’t know how.

I hope you could me some suggestions.

Regards
Peter

If you want to sample pixel colours off a bitmap, you can use the Image Sampler object. You set it up with the image you want, and whether you want to sample colours or luminance or …, then you feed it a collection of points that represent texture coordinates.

Thank you for your suggestion. I am not sure whether sampling pixel colors off a bitmap is what I want.

And, It’s hard for me to understand what’s the meaning of feeding the image sampler a collection of points that represent texture coordinates.

I want to do some extrusion on surface that has Gray Scale Image on it as texture. The extrusion depth should be based on the Gray Scale Image.

Thanks David

In that case you’ll want to sample the luminance of a bitmap. Black=0.0, White=1.0, hue is ignored.

Let’s say that you have a bitmap of 1200x800 pixels on your desktop. But you are sampling a surface which has unit domains for u and v (i.e. 0.0 \rightarrow 1.0). You then load your image into the Image Sampler, change the sampling from RGB to Luminance and set the image dimensions to (0 to 1) for both X and Y. You can now feed in points and get the luminance values.

Coordinate (0.0, 0.0) gets you pixel [0,0], coordinate (1.0, 0.0) gets you pixel [1200,0], etc.

Hi @DavidRutten,

I’m having similar troubles trying to extract the RGB values from the image sampler.

I’ve tried to follow your above advice but my sub-surfaces don’t seem to be matching up with the correlating image UV’s. I’m trying to get all the spheres to match the colour of the grid/bitmap below, do you know what might be the problem?

I’ve attached an image showing the desired result i’m looking to achieve, hopefully that helps.

Colour Sampler.gh (20.1 KB)

1 Like

Here is one way.

Colour SamplerV2.gh (11.7 KB)

4 Likes

This post (and many others on here) might help you understand the method:

1 Like

Thanks @Adam_M, that’s exactly what I was looking for

I’m looking to take it a step further and turn off/on modules of the grid according to their RGB input.

To give you a bit more context i’m trying to create something similar to an LED screen, so ideally i’m looking to not show shapes that are emitting complete black.

could you offer any advice on the most efficient way of doing this?

(Btw I’ve slightly modified your earlier definition with some firefly components in order to input video/sequences).

Thanks again,

Colour SamplerV2b.gh (19.4 KB)

I dont have Firefly installed at the moment, nor do I have access to the image file in your latest script, so I just went back to your original file.

You could do something like this, if you are ok with removing the sphere completely rather than setting to transparent. If you have a large number of spheres, you may want to Cull the Base input into the Mesh Sphere component (rather than the output) to reduce processing time.

2 Likes

Awesome! that’s exactly what I was after, thanks @Adam_M
And yes removing the sphere actually works better for my purposes

1 Like