MCPcopy Create free account
hub / github.com/apache/singa / ImageTool

Class ImageTool

python/singa/image_tool.py:214–629  ·  view source on GitHub ↗

A tool for image augmentation. For operations with inplace=True, the returned value is the ImageTool instance self, which is for chaining multiple operations; Otherwise, the preprocessed images would be returned. For operations that has countable pre-processing cases, argument num_

Source from the content-addressed store, hash-verified

212
213
214class ImageTool(object):
215 '''A tool for image augmentation.
216
217 For operations with inplace=True, the returned value is the ImageTool
218 instance self, which is for chaining multiple operations; Otherwise, the
219 preprocessed images would be returned.
220
221 For operations that has countable pre-processing cases, argument num_case
222 could be set to decide the number of pre-processing cases to apply.
223 Typically, it is set to 1 for training phases and to the max for test
224 phases.
225 '''
226
227 def __init__(self):
228 self.imgs = []
229 return
230
231 def load(self, path, grayscale=False):
232 img = load_img(path, grayscale)
233 self.imgs = [img]
234 return self
235
236 def set(self, imgs):
237 self.imgs = imgs
238 return self
239
240 def append(self, img):
241 self.imgs.append(img)
242 return self
243
244 def get(self):
245 return self.imgs
246
247 def num_augmentation(self):
248 '''Return the total number of augmentations to each image'''
249 pass
250
251 def scale_by_range(self, rng, inplace=True):
252 '''
253 Args:
254 rng: a tuple (begin,end), include begin, exclude end
255 inplace: inplace imgs or not ( return new_imgs)
256 '''
257 return self.resize_by_range(rng, inplace)
258
259 def scale_by_list(self, size_list, num_case=1, inplace=True):
260 '''
261 Args:
262 num_case: num of resize cases, must be <= the length of size_list
263 inplace: inplace imgs or not ( return new_imgs)
264 ''&#x27;
265 return self.resize_by_list(size_list, num_case, inplace)
266
267 def resize_by_range(self, rng, inplace=True):
268 ''&#x27;
269 Args:
270 rng: a tuple (begin,end), include begin, exclude end
271 inplace: inplace imgs or not ( return new_imgs)

Callers 1

image_tool.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected