Inpanting bugfix to calculate SSD only of necessary regions