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

Function randomly_crop_image

examples/dnn_semantic_segmentation_train_ex.cpp:62–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60// ----------------------------------------------------------------------------------------
61
62void 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

Callers 1

mainFunction · 0.70

Calls 8

extract_image_chipFunction · 0.85
fliplrFunction · 0.85
get_random_doubleMethod · 0.80
chip_dimsClass · 0.50

Tested by

no test coverage detected