Indeed you can do image analysis on Foundry as you have access to files and can use arbitrary libraries (for example pillow or skimage for python). This can be done at scale as well as it can be parallelised.
A simple python snippet to stitch two pictures together should get you started:
from transforms.api import transform, Input, Output
from PIL import Image
@transform(
output=Output("/processed/stitched_images"),
raw=Input("/raw/images"),
image_meta=Input("/processed/image_meta")
)
def my_compute_function(raw, image_meta, output, ctx):
image_meta = image_meta.dataframe()
def stitch_images(clone):
left = clone["left_file_name"]
right = clone["right_file_name"]
image_name = clone["image_name"]
with raw.filesystem().open(left, mode="rb") as left_file:
with raw.filesystem().open(right, mode="rb") as right_file:
with output.filesystem().open(image_name, 'wb') as out_file:
left_image = Image.open(left_file)
right_image = Image.open(right_file)
(width, height) = left_image.size
result_width = width * 2
result_height = height
result = Image.new('RGB', (result_width, result_height))
result.paste(im=left_image, box=(0, 0))
result.paste(im=right_image, box=(height, 0))
result.save(out_file, format='jpeg', quality=90)
image_meta.rdd.foreach(stitch_images)
The image_meta dataset is just a dataset that has 2 file names per row. To extract filenames from a dataset of raw files you can use something like:
@transform(
output=Output("/processed/image_meta"),
raw=Input("/raw/images"),
)
def my_compute_function(raw, output, ctx):
file_names = [(file_status.path, 1) for file_status in raw.filesystem().ls(glob="*.jpg")]
# create and write spark dataframe based on array