| 60 | // ---------------------------------------------------------------------------------------- |
| 61 | |
| 62 | void randomly_crop_image ( |
| 63 | const matrix<rgb_pixel>& input_image, |
| 64 | const matrix<uint16_t>& label_image, |
| 65 | training_sample& crop, |
| 66 | dlib::rand& rnd |
| 67 | ) |
| 68 | { |
| 69 | const auto rect = make_random_cropping_rect(input_image, rnd); |
| 70 | |
| 71 | const chip_details chip_details(rect, chip_dims(227, 227)); |
| 72 | |
| 73 | // Crop the input image. |
| 74 | extract_image_chip(input_image, chip_details, crop.input_image, interpolate_bilinear()); |
| 75 | |
| 76 | // Crop the labels correspondingly. However, note that here bilinear |
| 77 | // interpolation would make absolutely no sense - you wouldn't say that |
| 78 | // a bicycle is half-way between an aeroplane and a bird, would you? |
| 79 | extract_image_chip(label_image, chip_details, crop.label_image, interpolate_nearest_neighbor()); |
| 80 | |
| 81 | // Also randomly flip the input image and the labels. |
| 82 | if (rnd.get_random_double() > 0.5) |
| 83 | { |
| 84 | crop.input_image = fliplr(crop.input_image); |
| 85 | crop.label_image = fliplr(crop.label_image); |
| 86 | } |
| 87 | |
| 88 | // And then randomly adjust the colors. |
| 89 | apply_random_color_offset(crop.input_image, rnd); |
| 90 | } |
| 91 | |
| 92 | // ---------------------------------------------------------------------------------------- |
| 93 |
no test coverage detected