(density_map, downsample_lvl=None)
| 537 | #we randomly samples some indices from it considering the density as probability |
| 538 | #return binary_map of B,1,H,W with some pixels on white where we should sample strands and some on black where there shouldn't be any strand |
| 539 | def sample_from_density_map(density_map, downsample_lvl=None): |
| 540 | if downsample_lvl is not None: |
| 541 | density_map = torch.nn.functional.interpolate(density_map, scale_factor=1.0/downsample_lvl) |
| 542 | |
| 543 | rand_map = torch.rand_like(density_map) |
| 544 | |
| 545 | density_clamped= torch.clamp(density_map, 0.0, 1.0) |
| 546 | |
| 547 | binary_map = (rand_map<=density_clamped).float() |
| 548 | |
| 549 | return binary_map |
| 550 | |
| 551 | |
| 552 | def sample_strands_from_scalp_with_density(scalp_texture, density_map, strand_codec, normalization_dict, |
no outgoing calls
no test coverage detected