@@ -107,16 +107,38 @@ class ImageAugmenter {
107
107
cv::BORDER_CONSTANT,
108
108
cv::Scalar (fill_value_, fill_value_, fill_value_));
109
109
cv::Mat res = temp;
110
- mshadow::index_t y = res.rows - shape_[2 ];
111
- mshadow::index_t x = res.cols - shape_[1 ];
112
- if (rand_crop_ != 0 ) {
113
- y = prnd->NextUInt32 (y + 1 );
114
- x = prnd->NextUInt32 (x + 1 );
115
- } else {
116
- y /= 2 ; x /= 2 ;
110
+ if (max_crop_size_ != -1 || min_crop_size_ != -1 ){
111
+ utils::Check (res.cols >= max_crop_size_ && res.rows >= max_crop_size_&&max_crop_size_ >= min_crop_size_,
112
+ " input image size smaller than max_crop_size" );
113
+ mshadow::index_t rand_crop_size = prnd->NextUInt32 (max_crop_size_-min_crop_size_+1 )+min_crop_size_;
114
+ mshadow::index_t y = res.rows - rand_crop_size;
115
+ mshadow::index_t x = res.cols - rand_crop_size;
116
+ if (rand_crop_ != 0 ) {
117
+ y = prnd->NextUInt32 (y + 1 );
118
+ x = prnd->NextUInt32 (x + 1 );
119
+ }
120
+ else {
121
+ y /= 2 ; x /= 2 ;
122
+ }
123
+ cv::Rect roi (x, y, rand_crop_size, rand_crop_size);
124
+ res = res (roi);
125
+ cv::resize (res (roi), res, cv::Size (shape_[1 ], shape_[2 ]));
126
+ }
127
+ else {
128
+ utils::Check (static_cast <mshadow::index_t >(res.cols ) >= shape_[1 ] && static_cast <mshadow::index_t >(res.rows ) >= shape_[2 ],
129
+ " input image size smaller than input shape" );
130
+ mshadow::index_t y = res.rows - shape_[2 ];
131
+ mshadow::index_t x = res.cols - shape_[1 ];
132
+ if (rand_crop_ != 0 ) {
133
+ y = prnd->NextUInt32 (y + 1 );
134
+ x = prnd->NextUInt32 (x + 1 );
135
+ }
136
+ else {
137
+ y /= 2 ; x /= 2 ;
138
+ }
139
+ cv::Rect roi (x, y, shape_[1 ], shape_[2 ]);
140
+ res = res (roi);
117
141
}
118
- cv::Rect roi (x, y, shape_[1 ], shape_[2 ]);
119
- res = res (roi);
120
142
return res;
121
143
}
122
144
/* !
0 commit comments