Randomly flip a img left to right. Args: num_case: num of cases, must be in {1,2}; if 2, then add the orignal and flipped img inplace: inplace imgs or not (return new_imgs)
(self, num_case=1, inplace=True)
| 539 | return new_imgs |
| 540 | |
| 541 | def flip(self, num_case=1, inplace=True): |
| 542 | '''Randomly flip a img left to right. |
| 543 | |
| 544 | Args: |
| 545 | num_case: num of cases, must be in {1,2}; if 2, then add the orignal |
| 546 | and flipped img |
| 547 | inplace: inplace imgs or not (return new_imgs) |
| 548 | ''' |
| 549 | new_imgs = [] |
| 550 | for img in self.imgs: |
| 551 | if num_case == 1: |
| 552 | if random.randint(0, 1): |
| 553 | new_imgs.append(flip(img)) |
| 554 | else: |
| 555 | new_imgs.append(img) |
| 556 | elif num_case == 2: |
| 557 | new_imgs.append(flip(img)) |
| 558 | new_imgs.append(img) |
| 559 | else: |
| 560 | raise Exception('num_case must be in [0,2]') |
| 561 | |
| 562 | if inplace: |
| 563 | self.imgs = new_imgs |
| 564 | return self |
| 565 | else: |
| 566 | return new_imgs |
| 567 | |
| 568 | def flip_down(self, num_case=1, inplace=True): |
| 569 | '''Randomly flip a img top to bottom. |
no test coverage detected