1
1
import argparse
2
2
import sys
3
+ from typing import List , Union
3
4
4
5
import numpy as np
5
6
from skimage import io
@@ -17,7 +18,7 @@ def main() -> None:
17
18
parser .add_argument ("--sigma" , default = 3.0 , help = "The use sigma" )
18
19
parser .add_argument ("--num-peaks" , default = 20 , help = "The used number of peaks" )
19
20
parser .add_argument (
20
- "--num-angles" , default = 180 , help = "The used number of angle (determine the pressision )"
21
+ "--num-angles" , default = 180 , help = "The used number of angle (determine the precision )"
21
22
)
22
23
parser .add_argument ("--background" , help = "The used background color" )
23
24
parser .add_argument (default = None , dest = "input" , help = "Input file name" )
@@ -30,14 +31,26 @@ def main() -> None:
30
31
print (f"Estimated angle: { angle } " )
31
32
else :
32
33
if options .background :
33
- try :
34
- background = [int (c ) for c in options .background .split ("," )]
35
- except : # pylint: disable=bare-except
36
- print ("Wrong background color, should be r,g,b" )
37
- sys .exit (1 )
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
39
+ 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
45
+ print ("Wrong background color, should be r,g,b" )
46
+ sys .exit (1 )
47
+
38
48
rotated = rotate (image , angle , resize = True , cval = - 1 ) * 255
39
49
pos = np .where (rotated == - 255 )
40
- rotated [pos [0 ], pos [1 ], :] = background
50
+ if len (image .shape ) == 2 :
51
+ rotated [pos [0 ], pos [1 ]] = background
52
+ else :
53
+ rotated [pos [0 ], pos [1 ], :] = background
41
54
else :
42
55
rotated = rotate (image , angle , resize = True ) * 255
43
56
io .imsave (options .output , rotated .astype (np .uint8 ))
0 commit comments