Coverage for src/ufig/plugins/compression_noise.py: 100%
14 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-12 19:08 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-12 19:08 +0000
1# Copyright (c) 2013 ETH Zurich, Institute of Astronomy, Lukas Gamper
2# <lukas.gamper@usystems.ch>
3"""
4Created on 04/2016
5@author: Tomasz Kacprzak
7"""
9import numpy as np
10from ivy.plugin.base_plugin import BasePlugin
13# Todo: Update documentation
14class Plugin(BasePlugin):
15 """ """
17 def __call__(self):
18 # Reseed random library
19 np.random.seed(
20 self.ctx.parameters.seed + self.ctx.parameters.compression_noise_seed_offset
21 )
23 chunk = (
24 self.ctx.parameters.chunksize,
25 self.ctx.parameters.chunksize,
26 ) # quadratic chunks for now
27 img_shape = self.ctx.image.shape
29 for i in range(img_shape[0] // chunk[0]):
30 idx0 = slice(i * chunk[0], (i + 1) * chunk[0])
31 for j in range(img_shape[1] // chunk[1]):
32 idx1 = slice(j * chunk[1], (j + 1) * chunk[1])
33 self.ctx.image[idx0, idx1] += np.random.uniform(
34 low=-self.ctx.parameters.compression_noise_level,
35 high=self.ctx.parameters.compression_noise_level,
36 size=chunk,
37 )
39 def __str__(self):
40 return "add compression noise"