(image, exposure, prefilter=False)
| 48 | |
| 49 | # Returns a preprocessed image (also changes the original image!) |
| 50 | def preprocess_image(image, exposure, prefilter=False): |
| 51 | # Apply the transfer function to the main feature |
| 52 | color = image[..., 0:num_main_channels] |
| 53 | color = torch.from_numpy(color).to(device) |
| 54 | if main_feature == 'hdr': |
| 55 | color *= exposure |
| 56 | color = transfer.forward(color) |
| 57 | color = torch.clamp(color, max=1.) |
| 58 | color = color.cpu().numpy() |
| 59 | image[..., 0:num_main_channels] = color |
| 60 | |
| 61 | # Prefilter the auxiliary features |
| 62 | if prefilter: |
| 63 | for aux_feature, aux_infer in aux_infers.items(): |
| 64 | aux_channels = get_dataset_channels(aux_feature) |
| 65 | aux_channel_indices = get_channel_indices(aux_channels, all_channels) |
| 66 | aux = image[..., aux_channel_indices] |
| 67 | aux = image_to_tensor(aux, batch=True).to(device) |
| 68 | aux = aux_infer(aux) |
| 69 | aux = tensor_to_image(aux) |
| 70 | image[..., aux_channel_indices] = aux |
| 71 | |
| 72 | # Convert to FP16 |
| 73 | return np.nan_to_num(image.astype(np.float16)) |
| 74 | |
| 75 | # Preprocesses a group of input and target images at different SPPs |
| 76 | def preprocess_sample_group(input_dir, output_tza, input_names, target_name): |
no test coverage detected