Skip to content
This repository was archived by the owner on May 24, 2018. It is now read-only.

Commit 4c1570a

Browse files
committed
Merge pull request #197 from superzrx/fix_aug
fix rand_crop
2 parents dc59948 + a4d0c86 commit 4c1570a

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ ps-lite
1818
dmlc-core
1919
bin
2020
rabit
21+
*.opensdf
22+
*.sdf
23+
*.pdb
24+
*.user
25+
*.suo
26+
*.deps
27+
*.cache
28+
*state
29+
*build

src/io/image_augmenter-inl.hpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,38 @@ class ImageAugmenter {
107107
cv::BORDER_CONSTANT,
108108
cv::Scalar(fill_value_, fill_value_, fill_value_));
109109
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);
117141
}
118-
cv::Rect roi(x, y, shape_[1], shape_[2]);
119-
res = res(roi);
120142
return res;
121143
}
122144
/*!

0 commit comments

Comments
 (0)