compute_gradient_loss.m 619 B

12345678910111213141516171819
  1. % compute the gradient error given a prediction, a ground truth and a trimap.
  2. % author Ning Xu
  3. % date 2018-1-1
  4. % pred: the predicted alpha matte
  5. % target: the ground truth alpha matte
  6. % trimap: the given trimap
  7. % step = 0.1
  8. function loss = compute_gradient_loss(pred,target,trimap)
  9. pred = mat2gray(pred);
  10. target = mat2gray(target);
  11. [pred_x,pred_y] = gaussgradient(pred,1.4);
  12. [target_x,target_y] = gaussgradient(target,1.4);
  13. pred_amp = sqrt(pred_x.^2 + pred_y.^2);
  14. target_amp = sqrt(target_x.^2 + target_y.^2);
  15. error_map = (single(pred_amp) - single(target_amp)).^2;
  16. loss = sum(sum(error_map.*single(trimap==128))) ;