Skip to content

Instantly share code, notes, and snippets.

@lesolorzanov
Last active July 14, 2019 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lesolorzanov/f217d3d19c2f15d4c1b63fe571625fdf to your computer and use it in GitHub Desktop.
Save lesolorzanov/f217d3d19c2f15d4c1b63fe571625fdf to your computer and use it in GitHub Desktop.
Draw alpha levels blender
location="/home/leslie/Documents/alphaamd/"
imgs=["cells2little.png"]
def drawboxesat(pdx, iw, ih, q):
step=1/q
for x in range(iw):
for y in range(ih):
intensity=pdx[(x,y)][0]
if intensity==0:
continue
else:
print(intensity)
integral=step
count=1
while integral < intensity:
bpy.ops.mesh.primitive_cube_add(size=1, enter_editmode=False, location=(y+0.5+count*iw+5, x+0.5, count))
integral+=step
count+=1
bpy.ops.mesh.primitive_cube_add(size=1, enter_editmode=False, location=(y+0.5, x+0.5, count))
def idx_to_co(idx, width):
r = int(idx / width)
c = idx % width
return r, c
def px_list_to_dict(px_list, width):
px_dict = {}
for idx, px in enumerate(px_list):
px_dict[idx_to_co(idx, width)] = px
return px_dict
def loadimage(im,c,q):
#c is number of channels for png is usuually 4
bpy.ops.object.load_background_image(filepath=location+im)
D = bpy.data
img = D.images[im]
iw = img.size[0]
ih = img.size[1]
pxs = list(img.pixels)
num_values = len(pxs)
px_list = [pxs[i:i+c] for i in range(num_values)[::c]]
px_dict = px_list_to_dict(px_list, iw)
drawboxesat(px_dict, iw, ih,q)
imgs=["cells2little.png"]
q=4.0
for i in range(len(imgs)):
loadimage(imgs[i],4,q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment