Image segmentation with Unet. I make a big Pandas dataframe with paths to all images and masks, along with other image attributes. The DataBlock is like this:
src_datablock = DataBlock(
blocks=(ImageBlock, MaskBlock),
getters=[make_image, make_mask],
splitter=TrainTestSplitter(stratify=src_df_big["dataset"].to_list()),
item_tfms=[
Resize(size=(960, 720), method="squish"),
# I need to crop borders here
Resize(size=224, method="squish")
],
batch_tfms=None,
)
The getters simply ensure that all images and masks are 8 bits per pixel, but they make no other changes, so I’m not including them here.
Most images are 960x720. But a few are much bigger than that. So in item_tfms
I first resize to 960x720 to ensure everyone is on the same page. Then I resize to the size that the model needs.
But in between those two Resize
calls I need to crop borders - crop out a few dozen pixels from each border, because most images have a frame around them that I don’t need. Basically, I need to keep an inner box from each item and discard the outer region. I know the size and coordinates of the box, they are the same for all images.
Perhaps I’m missing something obvious - but I can’t figure out what is the right method there to crop out the border.
If all this is too hard, perhaps I can move all the resizing / cropping / resizing to the getters, but first I would like to try doing it with item_tfms
. This is to improve my understanding of fast.ai. Also, I think it’s better code structure to keep low level processing in the getters, while doing higher level processing in item_tfms
.
Thank you.