11import argparse
22import sys
3+ from typing import List , Union
34
45import numpy as np
56from skimage import io
@@ -17,7 +18,7 @@ def main() -> None:
1718 parser .add_argument ("--sigma" , default = 3.0 , help = "The use sigma" )
1819 parser .add_argument ("--num-peaks" , default = 20 , help = "The used number of peaks" )
1920 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 )"
2122 )
2223 parser .add_argument ("--background" , help = "The used background color" )
2324 parser .add_argument (default = None , dest = "input" , help = "Input file name" )
@@ -30,14 +31,26 @@ def main() -> None:
3031 print (f"Estimated angle: { angle } " )
3132 else :
3233 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+
3848 rotated = rotate (image , angle , resize = True , cval = - 1 ) * 255
3949 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
4154 else :
4255 rotated = rotate (image , angle , resize = True ) * 255
4356 io .imsave (options .output , rotated .astype (np .uint8 ))
0 commit comments