This invention discloses a method for food
image segmentation and removal based on instance segmentation and spatial prior clustering, comprising three steps: Step 1, inferring from the photo using the YOLO instance segmentation model, extracting the segmentation
mask, and
cropping it into a black
background image; Step 2, extracting the foreground from the image using the
GrabCut algorithm, converting it to a transparent background, and generating an RGBA format image; Step 3, performing spatial partitioning on the transparent
background image based on
Euclidean distance transformation, using the outer perimeter as the plate prior and the center as the food prior, performing K-means clustering in the
Lab color space, automatically identifying the plate and food clusters based on the spatial
enrichment ratio of each cluster at the perimeter and center, and removing plate pixels based on external
reachability connectivity verification, outputting a transparent
background image containing only the food. This invention eliminates the need for manual region labeling or setting color thresholds, can adaptively
handle plates of different colors, shapes, and sizes, is suitable for diverse dining scenarios, and supports tasks such as
food recognition and nutritional
estimation.