Return corrupted images.

    Args:
      x: numpy array, uncorrupted image.

    Returns:
      numpy array, corrupted images.
184930
def _get_corrupted_example(self, x):
    
    corruption_type = self.builder_config.corruption_type
    severity = self.builder_config.severity

    return {
        'gaussian_noise': corruptions.gaussian_noise,
        'shot_noise': corruptions.shot_noise,
        'impulse_noise': corruptions.impulse_noise,
        'defocus_blur': corruptions.defocus_blur,
        'frosted_glass_blur': corruptions.frosted_glass_blur,
        'zoom_blur': corruptions.zoom_blur,
        'fog': corruptions.fog,
        'brightness': corruptions.brightness,
        'contrast': corruptions.contrast,
        'elastic': corruptions.elastic,
        'pixelate': corruptions.pixelate,
        'jpeg_compression': corruptions.jpeg_compression,
    }[corruption_type](x, severity)
879872
def slice_image(image, axis=None, idx=None):
    
    if image.dimension < 3:
        raise ValueError('image must have at least 3 dimensions')

    inpixeltype = image.pixeltype
    ndim = image.dimension
    if image.pixeltype != 'float':
        image = image.clone('float')

    libfn = utils.get_lib_fn('sliceImageF%i' % ndim)
    itkimage = libfn(image.pointer, axis, idx)

    return iio.ANTsImage(pixeltype='float', dimension=ndim-1, 
                         components=image.components, pointer=itkimage).clone(inpixeltype)
559142
def posterior_to_xarray(self):
        """"""
        posterior = self.posterior
        posterior_model = self.posterior_model
        # filter posterior_predictive and log_likelihood
        posterior_predictive = self.posterior_predictive
        if posterior_predictive is None:
            posterior_predictive = []
        elif isinstance(posterior_predictive, str):
            posterior_predictive = [posterior_predictive]
        log_likelihood = self.log_likelihood
        if not isinstance(log_likelihood, str):
            log_likelihood = []
        else:
            log_likelihood = [log_likelihood]

        ignore = posterior_predictive + log_likelihood

        data = get_draws_stan3(posterior, model=posterior_model, ignore=ignore)

        return dict_to_dataset(data, library=self.stan, coords=self.coords, dims=self.dims)
260715
def visual(title, X, name):
    
    assert len(X.shape) == 4
    X = X.transpose((0, 2, 3, 1))
    X = np.clip((X - np.min(X))*(255.0/(np.max(X) - np.min(X))), 0, 255).astype(np.uint8)
    n = np.ceil(np.sqrt(X.shape[0]))
    buff = np.zeros((int(n*X.shape[1]), int(n*X.shape[2]), int(X.shape[3])), dtype=np.uint8)
    for i, img in enumerate(X):
        fill_buf(buff, i, img, X.shape[1:3])
    buff = buff[:, :, ::-1]
    plt.imshow(buff)
    plt.title(title)
    plt.savefig(name)
946441
def clean_with_zeros(self,x):
        
        x[~np.any(np.isnan(x) | np.isinf(x),axis=1)] = 0
        return x
1095457
def get_X_slice(self, rmind):
        ''''''
        if self.forest.optimize_memory_use:
            return self.forest.X[:, rmind][self.subsample]
        else:
            return self.X[:, rmind]
377796
def load_image(self, idx):
        
        im = Image.open('{}/data/images/img_{}.png'.format(self.nyud_dir, idx))
        in_ = np.array(im, dtype=np.float32)
        in_ = in_[:,:,::-1]
        in_ -= self.mean_bgr
        in_ = in_.transpose((2,0,1))
        return in_
689829
def getPixels(self):
        
        array = self.toArray()
        (width, height, depth) = array.size
        for x in range(width):
            for y in range(height):
                yield Pixel(array, x, y)
872797
public INDArray getCorruptedInput(INDArray x, double corruptionLevel) {
        INDArray corrupted = Nd4j.getDistributions().createBinomial(1, 1 - corruptionLevel).sample(x.ulike());
        corrupted.muli(x.castTo(corrupted.dataType()));
        return corrupted;
    }
831227
def _bad_result(cls, error):
        
        return cls.Result(ok=False, expr='', files={}, stdout='', type='', value=error)
1179720
def from_xarray(cls, arr: "xarray.Dataset") -> "Histogram1D":
        
        kwargs = {'frequencies': arr["frequencies"],
                  'binning': arr["bins"],
                  'errors2': arr["errors2"],
                  'overflow': arr.attrs["overflow"],
                  'underflow': arr.attrs["underflow"],
                  'keep_missed': arr.attrs["keep_missed"]}
        # TODO: Add stats
        return cls(**kwargs)
1332352
def rgba_floats_tuple(self, x):
        
        if x <= self.index[0]:
            return self.colors[0]
        if x >= self.index[-1]:
            return self.colors[-1]

        i = len([u for u in self.index if u < x])  # 0 < i < n.
        return tuple(self.colors[i-1])
310697
def calc(self, x:Image, *args:Any, **kwargs:Any)->Image:
        ""
        if self._wrap: return getattr(x, self._wrap)(self.func, *args, **kwargs)
        else:          return self.func(x, *args, **kwargs)
1374284
def _check_image(self, X):
        

        if (len(X.shape) < 3) or (len(X.shape) > 4):
            raise ValueError('Input has to have shape [n_samples, n_pixels_y, n_pixels_x] '
                             'or [n_samples, n_pixels_y, n_pixels_x, n_bands].')

        self._samples = X.shape[0]
        self._image_size = X.shape[1:3]

        if (self._image_size[0] % self.receptive_field[0]) or (self._image_size[0] % self.receptive_field[0]):
            raise ValueError('Image (%d,%d) and receptive fields (%d,%d) mismatch.\n'
                             'Resize your image to be divisible with receptive field.'
                             % (self._image_size[0], self._image_size[0], self.receptive_field[0],
                                self.receptive_field[1]))
146350
def cVectorToPython(x):
    
    if isinstance(x[0], bool):
        return numpy.frombuffer(x, dtype=numpy.bool).copy()
    elif isinstance(x[0], int):
        return numpy.frombuffer(x, dtype=numpy.int32).copy()
    elif isinstance(x[0], float):
        return numpy.frombuffer(x, dtype=numpy.float64).copy()
    elif isinstance(x[0].value, bytes):
        return [toPythonString(y) for y in x]
538817
def get_plain_image_as_widget(self):
        
        arr = self.getwin_array(order=self.rgb_order)

        # convert numpy array to native image widget
        image_w = self._get_wimage(arr)
        return image_w
981321
def repair(self, x, copy_if_changed=True, copy_always=False):
        
        copy = copy_if_changed
        if copy_always:
            x = array(x, copy=True)
            copy = False
        if self.bounds is None or (self.bounds[0] is None and
                                   self.bounds[1] is None):
            return x
        return self.bounds_tf(x, copy)