Use ImageSegments as labels in SegmentationItemList?

I want to adapt the following code from the camvid example in lesson 3:
src = (SegmentationItemList.from_folder(path_img)
.label_from_func(get_y_fn, classes=codes))

In my case, I do not have a folder where the masks are stored as pngs. Instead, I wrote a function which for each image_name returns an ImageSegment which is the mask, containing 0 for “background” and 1 for “mask here”.
In the above code, get_y_fn returns a path to a .png where the mask is stored. What about my case: Do I need to re-convert the ImageSegments into arrays and store them as .pngs on the disk, or is there a more elegant way to directly use the ImageSegment-masks?