0
$\begingroup$

enter image description here

enter image description here

Hi people, my goal here is to read the 2D images pixel intensity and transfer those values to the corresponding cubes I made in Blender. The image is 28px by 28px.

My first question is if I already extracted the pixel values from the 2D image how can proceed and transfer its value to the cubes? For each cube, I should first create a texture correct? Then I can simply write a loop to copy over each corresponding value to replace the texture color?

Second question would be can I set the color for each cube in blender to only gray scale? Its will be much easier that way.

The third question is, is there something faster like grouping all texture values into a matrix, then set all the values to 1s, finally we just do a matrix multiplication to change all the values at once? If I read the image with Pillow and numpy I can get an array back so I don't have to loop 28x28 times.

Can someone give me some advice? I am currently using Blender 2.8 and would like to run this in realtime with Eevee.

For a better idea on what I am trying to do in Blender please check out this video.

https://youtu.be/3JQ3hYko51Y?t=15

I am basically going to do the same thing but visualizing a different network structure.

$\endgroup$
1
$\begingroup$

This is the fastest way: 1. add a cube 2. add two array modifiers to x and y axis and apply them 3. go to edit mode, use orthagonic view (num5), hit "u" and select "projection from view (boundary)" 4. hit "p" select "by loose parts" 5. go back to object mode, select everything and hit ctrl+shift+alt+c and select "origin to center of mass" enter image description here

$\endgroup$
  • $\begingroup$ If I do it your way will each block contains its own values for color texture? Basically, if I change the color for the block will the entire cube change its color? I think you misunderstood me. Grayscale image colors are between 0 and 1 and I would like to grab that value for each pixel and apply that color to the corresponding cube in Blender. I think I might have to do a for-loop after all. $\endgroup$ – Inkplay_ Feb 13 at 13:26
  • $\begingroup$ If you have a 28x28 picture, then only one pixel will be the whole texture of one cube, so yes the entrie cube will change it's color. $\endgroup$ – FFeller Feb 13 at 14:31
  • $\begingroup$ you can also do this with an array (or individual objects if you apply the array modifiers) and a single texture controlled by an empty. Read: blender.stackexchange.com/questions/39508/… $\endgroup$ – cegaton Feb 13 at 15:58
0
$\begingroup$

Add a 28 x 28 grid with UV

Add a Grid Primitive, 28 x 28, go into top view NUMPAD 7 in edit mode select all, Mesh > UV Unwrap > Project from View Bounds

Assign it a material with an image texture for color. Choose your image. Set other material settings here , eg brightness as mentioned in your next question. Example using Cycles

enter image description here

Give the grid mesh a solidify modifier. Choose thickness, and also whether to fill the rim. This will apply to all cubes the same when its split apart.

Now with all edges selected run the edge split (Space bar search edge split, not sure of shortcut)

P Separate by loose parts.

Toggle out of edit mode TAB Will now have a "cube" for each, and all selected. If not sure of "clean" selection, do a quick border select and have all cubes selected instead.

Make each cubes origin its bbox centre with transform > Origin to geometry then using one of the methods outlined in Moving objects away from 3D cursor equally like scale, without actually scaling

to put a gap between each "cube".

enter image description here

Now have 28 x 28 individual cube objects, each really a simple one face plane mesh, having a solidify modifier, each using their (n x n)th part of the UV map. All using the one material.

Please note: the image used is a quick screen grab of image in question, which hasn't been fixed to exact dimension or size.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.