OPEN_IMAGE
Load an image file from disk and return a DataContainer of type 'image'. Inputs
------
default: None Params: file_path : File path to the file to be loaded Returns: out : Image Image loaded from specified file path
Python Code
from os import path
from flojoy import File, Image, flojoy
from matplotlib import image
from numpy import asarray
@flojoy
def OPEN_IMAGE(file_path: File | None = None) -> Image:
"""Load an image file from disk and return a DataContainer of type 'image'.
Inputs
------
default: None
Parameters
----------
file_path : File
path to the file to be loaded
Returns
-------
Image
Image loaded from specified file path
"""
if not path.exists(file_path):
raise ValueError("File path does not exist!")
read_image = image.imread(file_path)
data = asarray(read_image)
red_channel = data[:, :, 0]
green_channel = data[:, :, 1]
blue_channel = data[:, :, 2]
if data.shape[2] == 4:
alpha_channel = data[:, :, 3]
else:
alpha_channel = None
return Image(
r=red_channel,
g=green_channel,
b=blue_channel,
a=alpha_channel,
)
Example
Having problems with this example app? Join our Discord community and we will help you out!
In this example, OPEN_IMAGE
loads an image from a local disk and returns an image
type DataContainer
object.
It passes the data into IMAGE
visualiser and displays the image.