Skip to content

Instantly share code, notes, and snippets.

import SimpleITK as sitk
import matplotlib.pyplot as plt
from neverfault.resample import resample_new
import numpy as np
def test(im):
""" Use Simple ITK to random deform (elastic deform) an 2D image. Can be easily
used for 3D. There are two ways of elastic deforming an image. One is to define
a sparse control points, and use B-Spline to interpolate the deformation field.
Another is to directly define the deformation field. For data augmentation purpose,
@weiliu620
weiliu620 / Dice_coeff_loss.py
Last active July 19, 2023 10:30
Dice coefficient loss function in PyTorch
def dice_loss(pred, target):
"""This definition generalize to real valued pred and target vector.
This should be differentiable.
pred: tensor with first dimension as batch
target: tensor with first dimension as batch
"""
smooth = 1.