A helper function to generate different kinds of augmentations.
| 115 | |
| 116 | // A helper function to generate different kinds of augmentations. |
| 117 | matrix<rgb_pixel> augment( |
| 118 | const matrix<rgb_pixel>& image, |
| 119 | dlib::rand& rnd |
| 120 | ) |
| 121 | { |
| 122 | // randomly crop |
| 123 | matrix<rgb_pixel> crop; |
| 124 | const auto rect = make_random_cropping_rect(image, rnd); |
| 125 | extract_image_chip(image, chip_details(rect, chip_dims(32, 32)), crop); |
| 126 | |
| 127 | // image left-right flip |
| 128 | if (rnd.get_random_double() < 0.5) |
| 129 | flip_image_left_right(crop); |
| 130 | |
| 131 | // color augmentation |
| 132 | if (rnd.get_random_double() < 0.8) |
| 133 | disturb_colors(crop, rnd, 1.0, 0.5); |
| 134 | |
| 135 | // grayscale |
| 136 | if (rnd.get_random_double() < 0.2) |
| 137 | { |
| 138 | matrix<unsigned char> gray; |
| 139 | assign_image(gray, crop); |
| 140 | assign_image(crop, gray); |
| 141 | } |
| 142 | return crop; |
| 143 | } |
| 144 | |
| 145 | int main(const int argc, const char** argv) |
| 146 | try |
no test coverage detected