Automated, Deformation-Free Expansion Microscopy


from PIL import Image, ImageDraw


# Set grid parameters
image_w = 200 #Image width (px)
image_h = 200 #Image height (px)
spacing = 20 #Spacing between intersections (starter pack = 20)
line_w = 8 #Line width (starter pack = 8)

def generate_grid_image(image_w, image_h, spacing, line_w):
# Create a new image with a white background
image = Image.new("L", (image_w, image_h), "white")
draw = ImageDraw.Draw(image)
# Draw horizontal lines
for y in range(0, image_h, spacing):
draw.line([(0, y), (image_w, y)], fill="black", width=line_w)
# Draw vertical lines
for x in range(0, image_w, spacing):
draw.line([(x, 0), (x, image_h)], fill="black", width=line_w)
return image

# Generate the grid image
grid_image = generate_grid_image(image_w, image_h, spacing, line_w)

# Save the image or display it
grid_image.save("grid_image.tif")
grid_image.show()