| 263 | |
| 264 | |
| 265 | def process(arr, skip_rescale=False, skip_background=False, skip_type=False, mask=None, includes_alpha=True, drop_last_band=False): |
| 266 | if not skip_rescale and rescale is not None: |
| 267 | if includes_alpha: |
| 268 | arr[:-1, :, :] = linear_rescale(arr[:-1, :, :], in_range=rescale) |
| 269 | else: |
| 270 | arr = linear_rescale(arr, in_range=rescale) |
| 271 | if not skip_background and (mask is not None or includes_alpha): |
| 272 | if mask is not None: |
| 273 | background = mask==0 |
| 274 | elif includes_alpha: |
| 275 | background = arr[-1]==0 |
| 276 | if includes_alpha: |
| 277 | arr[:-1, :, :][:, background] = jpg_background |
| 278 | else: |
| 279 | arr[:, background] = jpg_background |
| 280 | if not skip_type and rgb and arr.dtype != np.uint8: |
| 281 | if includes_alpha: |
| 282 | arr[-1][arr[-1] > 255] = 255 |
| 283 | |
| 284 | arr = arr.astype(np.uint8) |
| 285 | |
| 286 | if drop_last_band: |
| 287 | return arr[:-1, :, :] |
| 288 | else: |
| 289 | return arr |
| 290 | |
| 291 | def update_rgb_colorinterp(dst): |
| 292 | if with_alpha: |