I have a png mask that looks like this
I want to be able to fill the inside of the subject also with black.
I think the easiest algorithm would be to trim all the transparent pixels outside the subject and then apply a solid background to the whole image. There might be other ways.
I was able to draw an outline of the subject with how to add colored border to uiimage in swift so I assume it should be possible to trim the outside pixels?
For example using the code above
Image(uiImage: UIImage(named: "outline")!.stroked())
.resizable()
.aspectRatio(contentMode: .fit)
.background(.red)
I am able to accurately outline the subject
But what I would need it the following final result: