I hope you’re all doing well with this project.
With the mixed gradients method, you set the target gradient based on the gradient with the larger magnitude in source and background image. If gs is the source gradient and gb is the background gradient at the same position, then you would set the target gradient to gs if abs(gs)>abs(gb) and to gb otherwise.
A common mistake is to set to gs if gs>gb, or to set to abs(gs) if abs(gs)>abs(gb).
Derek