MCPcopy Create free account
hub / github.com/davisking/dlib / augment

Function augment

examples/dnn_self_supervised_learning_ex.cpp:117–143  ·  view source on GitHub ↗

A helper function to generate different kinds of augmentations.

Source from the content-addressed store, hash-verified

115
116// A helper function to generate different kinds of augmentations.
117matrix<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
145int main(const int argc, const char** argv)
146try

Callers 2

operator()Method · 0.85
mainFunction · 0.85

Calls 8

extract_image_chipFunction · 0.85
flip_image_left_rightFunction · 0.85
disturb_colorsFunction · 0.85
get_random_doubleMethod · 0.80
chip_detailsClass · 0.50
chip_dimsClass · 0.50
assign_imageFunction · 0.50

Tested by

no test coverage detected