Coverage for src/ufig/plugins/compression_noise.py: 100%
14 statements
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-07 15:17 +0000
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-07 15:17 +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 def __call__(self):
16 # Reseed random library
17 np.random.seed(
18 self.ctx.parameters.seed + self.ctx.parameters.compression_noise_seed_offset
19 )
21 chunk = (
22 self.ctx.parameters.chunksize,
23 self.ctx.parameters.chunksize,
24 ) # quadratic chunks for now
25 img_shape = self.ctx.image.shape
27 for i in range(img_shape[0] // chunk[0]):
28 idx0 = slice(i * chunk[0], (i + 1) * chunk[0])
29 for j in range(img_shape[1] // chunk[1]):
30 idx1 = slice(j * chunk[1], (j + 1) * chunk[1])
31 self.ctx.image[idx0, idx1] += np.random.uniform(
32 low=-self.ctx.parameters.compression_noise_level,
33 high=self.ctx.parameters.compression_noise_level,
34 size=chunk,
35 )
37 def __str__(self):
38 return "add compression noise"