-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
questionFurther information is requestedFurther information is requested
Milestone
Description
Is your feature request related to a problem? Please describe.
Low resolution labels are often too jagged.

Describe the solution you'd like
Originally I hoped that the Spacingd transform would just have some antialiasing.
But a separate transform for this might be a better solution anyway.
I implemented a simple transform using a gaussian filter combined with a threshold on every label.
class Antialiasingd(MapTransform):
def __init__(
self,
keys: KeysCollection,
sigma: Union[Sequence[float], float] = 1.0,
approx: str = "erf",
threshold: float = 0.5,
allow_missing_keys: bool = False,
) -> None:
super().__init__(keys, allow_missing_keys)
self.sigma = sigma
self.approx = approx
self.threshold = threshold
def __call__(self, data: Mapping[Hashable, NdarrayTensor]) -> Dict[Hashable, NdarrayTensor]:
d = dict(data)
for key in self.key_iterator(d):
img = d[key]
gaussian_filter = GaussianFilter(img.ndim - 1, self.sigma, approx=self.approx)
labels = torch.unique(img)[1:]
new_img = torch.zeros_like(img)
for label in labels:
label_mask = (img == label).to(torch.float)
blurred = gaussian_filter(label_mask.unsqueeze(0)).squeeze(0)
new_img[blurred > self.threshold] = label
d[key] = new_img
return dWhat do you think?
Here some results
| Parameters | Result |
|---|---|
| Original | ![]() |
| Sigma=1.0, Threshold=0.5 | ![]() |
| Sigma=4.0, Threshold=0.5 | ![]() |
| Sigma=4.0, Threshold=0.4 | ![]() |
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested
Type
Projects
Status
✅ Done



