Automatic Differentiation for Inverse Problems in X-ray Imaging and Microscopy