Skip to content

Commit

Permalink
add link for batchviewer, add example for BrightnessGradientAdditiveT…
Browse files Browse the repository at this point in the history
…ransform
  • Loading branch information
FabianIsensee committed Aug 17, 2021
1 parent 1b3286a commit a1c4be4
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions batchgenerators/transforms/local_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ def _apply_local_smoothing(self, img: np.ndarray, kernel: np.ndarray) -> np.ndar
if __name__ == '__main__':
from copy import deepcopy
from skimage.data import camera
from batchviewer import view_batch # https://github.com/FabianIsensee/BatchViewer

"""
data = {'data': np.vstack((camera()[None], camera()[None], camera()[None], camera()[None]))[None].astype(np.float32)}
Expand All @@ -473,7 +474,6 @@ def _apply_local_smoothing(self, img: np.ndarray, kernel: np.ndarray) -> np.ndar
same_for_all_channels=False
)
transformed = tr(**deepcopy(data))['data']
from batchviewer import view_batch
data['data'][0][:, 0:2, 0] = np.array((0, 255))
transformed[0][:, 0:2, 0] = np.array((0, 255))
diff = [i - j for i, j in zip(data['data'][0], transformed[0])]
Expand All @@ -487,13 +487,12 @@ def _apply_local_smoothing(self, img: np.ndarray, kernel: np.ndarray) -> np.ndar
tr = LocalGammaTransform(
lambda x, y: np.random.uniform(x[y] // 6, x[y] // 2),
(0, 1),
(0.1, 3),
(0, 3),
False,
1,
1
)
transformed = tr(**deepcopy(data))['data']
from batchviewer import view_batch
data['data'][0][:, 0:2, 0] = np.array((0, 255))
transformed[0][:, 0:2, 0] = np.array((0, 255))
diff = [i - j for i, j in zip(data['data'][0], transformed[0])]
Expand All @@ -512,9 +511,28 @@ def _apply_local_smoothing(self, img: np.ndarray, kernel: np.ndarray) -> np.ndar
1
)
transformed = tr(**deepcopy(data))['data']
from batchviewer import view_batch
data['data'][0][:, 0:2, 0] = np.array((0, 255))
transformed[0][:, 0:2, 0] = np.array((0, 255))
diff = [i - j for i, j in zip(data['data'][0], transformed[0])]
[print(i[10,10]) for i in diff]
view_batch(*data['data'][0], *transformed[0], *[i - j for i, j in zip(data['data'][0], transformed[0])])
view_batch(*data['data'][0], *transformed[0], *[i - j for i, j in zip(data['data'][0], transformed[0])])


data = {'data': np.vstack((camera()[None], camera()[None], camera()[None], camera()[None]))[None].astype(np.float32)}

tr = BrightnessGradientAdditiveTransform(
lambda x, y: np.random.uniform(x[y] // 6, x[y] // 2),
(0, 1),
(-128, 128),
False,
1,
1
)
transformed = tr(**deepcopy(data))['data']
data['data'][0][:, 0:2, 0] = np.array((0, 255))
transformed[0][:, 0:2, 0] = np.array((0, 255))
diff = [i - j for i, j in zip(data['data'][0], transformed[0])]
[print(i[10,10]) for i in diff]
view_batch(*data['data'][0], *transformed[0], *[i - j for i, j in zip(data['data'][0], transformed[0])])


0 comments on commit a1c4be4

Please sign in to comment.