Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
script to process 1-bit pngs that define solid and void regions for ToPy topology optimization problems
# read in black & white pngs and create PASV_ELEM and ACTV_ELEM lists
# for topy input decks
# void.png: black pixels indicate regions that should be void
# solid.png: black pixels indicate regions that should be solid
from PIL import Image
solidim ="solid.png")
voidim ="void.png")
# transpose because topy numbering scheme is by columns, and PIL is by rows
solidim = solidim.transpose(Image.FLIP_TOP_BOTTOM)
solidim = solidim.transpose(Image.ROTATE_270)
voidim = voidim.transpose(Image.FLIP_TOP_BOTTOM)
voidim = voidim.transpose(Image.ROTATE_270)
actv_elem = ""
actv_count = 0
for i,p in enumerate(list(solidim.getdata())):
if p==1:
if actv_count==0:
actv_elem = "ACTV_ELEM: %d"%i
actv_elem = actv_elem + "; %d"%i
actv_count = actv_count + 1
pasv_elem = ""
pasv_count = 0
for i,p in enumerate(list(voidim.getdata())):
if p==1:
if pasv_count==0:
pasv_elem = "PASV_ELEM: %d"%i
pasv_elem = pasv_elem + "; %d"%i
pasv_count = pasv_count + 1
actvf = open("actv_elem.txt","w")
pasvf = open("pasv_elem.txt","w")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment