A formula for the total variation of SBV functions