A denoising framework for 3D and 2D imaging techniques based on photon detection statistics