0
$\begingroup$

Dears,

Scientific question:

I have a bunch of images taken from a microscope.

All images have XYZ coordinates of their real world position.

How can I import them into Blender via a script to have them placed correctly?

I have placed five images manually as an example, but I will have 100+ images to process.

See below how my data is organized at the moment and what I am hoping to achieve.

Thanks in advance.

enter image description here enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$
  • Place the data in a CSV file containing the coordinates and image names.
  • Loop over each line of the CSV file:
    • use Images as Planes to import each image
    • move the image to the location.

Although given that your Z values are identical, you may want to read only the X and Y coordinates.

Here's an example CSV reader that you would have to modify to handle the format of your file

import csv
with open(csvFilename, 'r') as csvFile:
    csvreader = csv.reader(csvFile, delimiter=',', 
        quotechar='|',
        quoting=csv.QUOTE_NONNUMERIC)
    for row in csvreader:
        print(f"{int(row[0])} is ({row[1]}, {row[2]}, {row[3]})")

Once you've decided on your CSV format, replace the print statement with code to decode a row, use the importer, and move the resulting object.

Here's an example of how to import an image as a plane and move it.

from pathlib import Path

image_file = Path("c:\\tmp\\0001.png")
bpy.ops.import_image.to_plane(files=[{'name':str(image_file)}])

image = bpy.data.images[image_file.name]
image.location = (x, y, z)

So the entire loop looks like this:

import csv
from pathlib import Path

with open(csvFilename, 'r') as csvFile:
    csvreader = csv.reader(csvFile, delimiter=',', 
        quotechar='|',
        quoting=csv.QUOTE_NONNUMERIC)
    for row in csvreader:
        # YOU need to place code here to convert the row entries
        # into a file name and set of coordinates

        bpy.ops.import_image.to_plane(files=[{'name':str(image_file)}])

        image = bpy.data.images[image_file.name]
        image.location = (x, y, z)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .