Cryptomatte

https://www.youtube.com/watch?v=Ml1Kic4VopA

Example background replacement node setup with cryptomatte
crypto3.jpg-kN47wWmLOtYsbeY-th ladyNew30.jpg-gz27taDHt1OktNW-th

A poor & messy way to separate, correct & combine stuff