Visualizes a wavelet decomposition produced by construct(). Args: pyr: A wavelet decomposition produced by construct(), percentile: The percentile of the deviation for each (non-residual) wavelet band to be clamped by before normalization. Seeting this to 100 causes visualizat
(pyr, percentile=99.)
| 446 | |
| 447 | |
| 448 | def visualize(pyr, percentile=99.): |
| 449 | """Visualizes a wavelet decomposition produced by construct(). |
| 450 | |
| 451 | Args: |
| 452 | pyr: A wavelet decomposition produced by construct(), |
| 453 | percentile: The percentile of the deviation for each (non-residual) wavelet |
| 454 | band to be clamped by before normalization. Seeting this to 100 causes |
| 455 | visualization to clamp to the maximum deviation, which preserves the |
| 456 | entire dynamic range but may make subtle details hard to see. A value of |
| 457 | 99 (the default) will clip away the 1% largest-magnitude values in each |
| 458 | band. |
| 459 | |
| 460 | Returns: |
| 461 | An image (a TF tensor of uint8's) of shape (width, height, num_channels). |
| 462 | Note that the input wavelet decomposition was produced from an image of |
| 463 | shape (num_channels, width, height) --- this function permutes the ordering |
| 464 | to what is expected in a planar image. |
| 465 | """ |
| 466 | vis_pyr = [] |
| 467 | for d in range(len(pyr) - 1): |
| 468 | vis_band = [] |
| 469 | for b in range(3): |
| 470 | band = pyr[d][b] |
| 471 | band = torch.as_tensor(band) |
| 472 | vec = torch.sort(torch.reshape(torch.abs(band), [-1]))[0] |
| 473 | max_mag = vec[np.int64( |
| 474 | np.floor(vec.shape[0] * np.clip(percentile / 100., 0., 1.)))] |
| 475 | vis_band.append(0.5 * (1. + torch.clamp(band / max_mag, -1., 1.))) |
| 476 | vis_pyr.append(vis_band) |
| 477 | d = len(pyr) - 1 |
| 478 | resid = torch.as_tensor(pyr[d]) |
| 479 | resid_norm = (resid - torch.min(resid)) / ( |
| 480 | torch.max(resid) - torch.min(resid)) |
| 481 | vis_pyr.append(resid_norm) |
| 482 | vis = torch.round(255. * flatten(vis_pyr).permute([1, 2, 0])).type( |
| 483 | torch.uint8) |
| 484 | return vis |