Skip to content

Commit e6909e0

Browse files
authored
Merge pull request #29 from ESA-PhiLab/fixed-clip-option
Add vmin/vmax option to config
2 parents 07602a0 + d044972 commit e6909e0

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

docs/config.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ Since this app was developed for multi-spectral satellite data (i.e. images with
149149
<li>
150150
*clip:* By default, bands are stretched between 0 and 1, relative to their minimum and maximum values. By setting a value for clip, you control the percentile of pixels that are saturated at 0 and 1, which can be helpful if there are some extreme pixel values that reduce the contrast in other parts of the image.
151151
</li>
152+
<li>
153+
*vmin/vmax* If you know the precise values you would like to clip the pixel values to, (rather than a percentile), then you can specify these with vmin and/or vmax. This cannot be used for the same view as `clip`.
154+
</li>
152155
</ul>
153156

154-
IRIS can display up to 4 views until v0.1. From v0.2 it can display an arbitrary number of views.
155-
156157
<i>Example:</i>
157158
```
158159
"views": {

iris/project.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,21 @@ def render_image(self, image_id, view):
359359

360360
# Stretch between 0->1, with percentile clip if specified in view
361361
if 'clip' in view:
362+
if 'vmin' in view or 'vmax' in view:
363+
raise ValueError("Cannot specify both 'clip' and 'vmin'/'vmax' in view")
362364
clip = float(view['clip'])
363365
linear_scale = lambda z: np.clip(
364366
(z - np.percentile(z,clip))/(np.percentile(z,100-clip)-np.percentile(z,clip)),
365367
0,
366368
1
367369
)
370+
elif 'vmin' in view or 'vmax' in view:
371+
if 'vmin' in view and 'vmax' in view:
372+
linear_scale = lambda z: np.clip((z - view['vmin'])/(view['vmax']-view['vmin']), 0, 1)
373+
elif 'vmin' in view:
374+
linear_scale = lambda z: np.clip((z - view['vmin'])/(z.max()-view['vmin']), 0, 1)
375+
elif 'vmax' in view:
376+
linear_scale = lambda z: np.clip((z - z.min())/(view['vmax']-z.min()), 0, 1)
368377
else:
369378
linear_scale = lambda z: (z - z.min())/(z.max()-z.min())
370379
rgb_bands = list(map(linear_scale, rgb_bands))

0 commit comments

Comments
 (0)