Deep-Learning MRI Inpainting

Medical AI2026HealthcareComputer Vision

Deep learning for filling in artificially removed regions in brain MRI slices: a comparison of an autoencoder, a U-Net and a GAN, with a focus on correct evaluation.

The challenge

Missing or corrupted regions in medical images are a known problem. The task was to fill in artificially masked regions in T1-weighted MRI slices, and to measure quality in a way that does not reward the model for pixels it had already seen.

The solution

Square regions were masked in slices from healthy control subjects, and the models received the masked image and the mask as input. Four variants were compared: a convolutional autoencoder as the baseline, an attention-gated U-Net, a GAN with a U-Net generator and a local PatchGAN discriminator, and finally a fine-tuned generator in which adversarial training was replaced with mask, boundary, gradient and SSIM-based losses.

How it was built

The project was carried out in a group; I contributed across data processing, modelling and evaluation. The PyTorch pipeline went from 3D volumes to 2D slices in three planes, with 15,120 slices from 504 people split patient-wise into training, validation and test (354/75/75 people). It used an Otsu-thresholded brain mask, 16–32-pixel masks placed inside the brain, and a correction that builds the masked input after resizing so image and mask stay aligned.

Result

Measured only inside the masked regions of the test set, the fine-tuned generator had the lowest mean absolute error (0.037 on normalised intensities), against 0.038 for the U-Net, 0.040 for the GAN and 0.045 for the autoencoder. The difference between the U-Net and the more advanced variants was therefore small.

Context

Whole-image PSNR and SSIM are not comparable between the models, because some variants copy in the known pixels before measuring; the error inside the masked region is used instead. The task concerns artificial masking in healthy brains, not reconstruction of real MRI acquisitions and not a clinically validated method.

Technologies and methods

PythonPyTorchnibabelU-NetConvolutional autoencoderGAN/PatchGANMask, boundary, gradient and SSIM-based lossesAdamWEMAMixed precision