maet3608 / nuts-ml

Flow-based data pre-processing for deep learning
Other
31 stars 10 forks source link

transforming multi-class segmentation ground-truth mask result in label interpolation #10

Closed RuwanT closed 7 years ago

RuwanT commented 7 years ago

The resulting mask image, after transforming a ground-truth mask (for multi-class segmentation) with AugmentImage will contain label values that were not present in the original mask. Looks like it happens due to interpolation.

from nutsflow import *
from nutsml import *
import numpy as np
a = np.zeros((100,100), dtype=np.int8)
a[40:60, 40:60] = 4

augment_2 = (AugmentImage((1,)).by('rotate', 1.0, [10, 50]))
img_viewer = ViewImage(imgcols=(0, 1), layout=(1, 2), pause=10)
[(a, a),] >> augment_2 >> img_viewer >> Consume()

viewimage-1

maet3608 commented 7 years ago

Thanks for the excellent bug report ; )

scikit-image performs a linear interpolation per default when rotating. There is an 'order' parameter to change the interpolation and order=0 solves the problem.

As a temporary workaround:

import skimage.transform as skt
def myrotate(image, angle):
    return skt.rotate(image, angle, preserve_range=True, order=0).astype('uint8')
TransformImage.register('myrotate', myrotate)

augment_2 = (AugmentImage((1,)).by('myrotate', 1.0, [10, 50]))

RuwanT commented 7 years ago

@maet3608, thanks for the quick response.

maet3608 commented 7 years ago

Fixed in nutsml-1.0.26 release. Default for transformations such as rotate, resize, translate and shear is now to NOT perform any interpolation of pixels. A kwargs parameter has been added allowing to set order=1 (or higher) to re-enable linear interpolation.