Take a look at the specification of US Patent 9,269,157 - "Methods for extracting objects from digital images and for performing color change on the object" - https://ppubs.uspto.gov/pubwebapp/ - maybe you'll find it useful.