I've seen tools for Generative AI art which do something a lot like that [1]
Generate an image of subject A, apply a depth estimation ML model to figure out which pixels belong to the foreground and cut them out.
Then generate an image of background B with a different prompt, and paste the subject from the first step on top. A sort of automatic collage making process.