The degree of unsaturation is defined as the index of hydrogen deficiency (IHD) that determines the total number of rings and π bonds. It means the removal of two hydrogen atoms from a molecule is equal to one added $\mathrm{DU}.$
$$\text{rings} + \pi~\text{bonds} = C - \frac{H}{2} - \frac{X}{2} + \frac{N}{2} + 1$$
If you add a halogen to a molecule, you need to remove a hydrogen atom (decreased half-one $\mathrm{DU}).$ If you do the same for a nitrogen atom, you need to remove a hydrogen atom from the molecule and add two others to the nitrogen (for amines as a saturated substituent), so you have one more hydrogen (increased half-one $\mathrm{DU}).$ As a result, the number of halogen and nitrogen atoms must be considered in the equation, but about other atoms such as oxygen $(\ce{C-OH})$ and sulfur $(\ce{C-SH}),$ there is no change in the total number of hydrogen atoms when adding them as saturated substituents to a molecule.
In the case of the unsaturated substituents such as imines and carbonyls, it's clear that the total number of hydrogen atoms decreases, so the $\mathrm{DU}$ increases.