File tree Expand file tree Collapse file tree 1 file changed +9
-10
lines changed
Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change 66import numpy as np
77import cv2
88import pydensecrf .densecrf as dcrf
9- import matplotlib .pylab as plt
109from skimage .segmentation import relabel_sequential
1110
1211from pydensecrf .utils import compute_unary , create_pairwise_bilateral , \
1312 create_pairwise_gaussian
1413
15- if len (sys .argv ) != 3 :
16- print ("Usage: python {} IMAGE ANNO" .format (sys .argv [0 ]))
14+ if len (sys .argv ) != 4 :
15+ print ("Usage: python {} IMAGE ANNO OUTPUT" .format (sys .argv [0 ]))
16+ print ("" )
17+ print ("IMAGE and ANNO are inputs and OUTPUT is where the result should be written." )
1718 sys .exit (1 )
1819
1920fn_im = sys .argv [1 ]
2021fn_anno = sys .argv [2 ]
22+ fn_output = sys .argv [3 ]
2123
2224##################################
2325### Read images and annotation ###
7375### Do inference and compute map ###
7476####################################
7577Q = d .inference (5 )
76- map = np .argmax (Q , axis = 0 ).reshape (img .shape [:2 ])
77-
78- res = map .astype ('float32' ) * 255 / map .max ()
79- plt .imshow (res )
80- plt .show ()
81-
78+ MAP = np .argmax (Q , axis = 0 ).astype ('float32' )
79+ MAP *= 255 / MAP .max ()
80+ MAP = MAP .reshape (img .shape [:2 ])
81+ cv2 .imwrite (fn_output , MAP .astype ('uint8' ))
8282
8383# Manually inference
8484Q , tmp1 , tmp2 = d .startInference ()
8585for i in range (5 ):
8686 print ("KL-divergence at {}: {}" .format (i , d .klDivergence (Q )))
8787 d .stepInference (Q , tmp1 , tmp2 )
88-
You can’t perform that action at this time.
0 commit comments