def update(variable, orig_img, mode):
    """Update a variable based on mode and its difference with orig_img."""
    # Apply the shrinkage-thresholding update element-wise.
    z = variable - orig_img
    if mode == "PP":
        return (z <= 0) * variable + (z > 0) * orig_img
    return (z > 0) * variable + (z <= 0) * orig_img