|
1 | 1 | import argparse |
2 | 2 | import sys |
3 | | -from typing import List, Union |
4 | 3 |
|
5 | 4 | import numpy as np |
6 | 5 | from skimage import io |
@@ -31,24 +30,23 @@ def main() -> None: |
31 | 30 | print(f"Estimated angle: {angle}") |
32 | 31 | else: |
33 | 32 | if options.background: |
34 | | - background: Union[int, List[int]] |
35 | | - if len(image.shape) == 2: |
36 | | - try: |
37 | | - background = int(options.background) |
38 | | - except: # pylint: disable=bare-except |
| 33 | + try: |
| 34 | + background = [int(c) for c in options.background.split(",")] |
| 35 | + except: # pylint: disable=bare-except |
| 36 | + if len(image.shape) == 2: |
39 | 37 | print("Wrong background color, should be gray") |
40 | | - sys.exit(1) |
41 | | - else: |
42 | | - try: |
43 | | - background = [int(c) for c in options.background.split(",")] |
44 | | - except: # pylint: disable=bare-except |
| 38 | + else: |
45 | 39 | print("Wrong background color, should be r,g,b") |
46 | | - sys.exit(1) |
| 40 | + sys.exit(1) |
| 41 | + |
| 42 | + if len(image.shape) != 2 and len(background) != image.shape[2]: |
| 43 | + print("Wrong background color, should be r,g,b") |
| 44 | + sys.exit(1) |
47 | 45 |
|
48 | 46 | rotated = rotate(image, angle, resize=True, cval=-1) * 255 |
49 | 47 | pos = np.where(rotated == -255) |
50 | 48 | if len(image.shape) == 2: |
51 | | - rotated[pos[0], pos[1]] = background |
| 49 | + rotated[pos[0], pos[1]] = int(round(np.mean(background))) |
52 | 50 | else: |
53 | 51 | rotated[pos[0], pos[1], :] = background |
54 | 52 | else: |
|
0 commit comments