<s> import numpy <EOL> from ilastik . core . overlays import thresholdOverlay <EOL> import vigra <EOL> class dummyOverlay : <EOL> def __init__ ( self , data , color ) : <EOL> self . _data = data <EOL> self . _data = self . _data . reshape ( self . _data . shape + ( <NUM_LIT:1> , ) ) <EOL> self . color = color <EOL> class SynapseFilterAndSegmentor ( object ) : <EOL> def __init__ ( self , parent = None , labelnum = None , minsize = None , maxsize = None , cc_overlay = None , input_overlay = None ) : <EOL> self . parent = parent <EOL> self . labelnum = labelnum <EOL> self . minsize = minsize <EOL> self . maxsize = maxsize <EOL> activeImage = self . parent . _activeImage <EOL> self . labels = activeImage . overlayMgr [ "<STR_LIT>" ] <EOL> self . cc = cc_overlay <EOL> self . thres = input_overlay <EOL> print self . cc . shape <EOL> self . ndim = <NUM_LIT:3> if cc_overlay . shape [ <NUM_LIT:1> ] > <NUM_LIT:1> else <NUM_LIT:2> <EOL> self . goodsizes = [ ] <EOL> '''<STR_LIT>''' <EOL> def objectsSlow3d ( self , cc ) : <EOL> objs = { } <EOL> nzindex = numpy . nonzero ( cc ) <EOL> for i in range ( len ( nzindex [ <NUM_LIT:0> ] ) ) : <EOL> value = cc [ nzindex [ <NUM_LIT:0> ] [ i ] , nzindex [ <NUM_LIT:1> ] [ i ] , nzindex [ <NUM_LIT:2> ] [ i ] ] <EOL> if value > <NUM_LIT:0> : <EOL> if value not in objs : <EOL> objs [ value ] = [ [ ] , [ ] , [ ] ] <EOL> objs [ value ] [ <NUM_LIT:0> ] . append ( nzindex [ <NUM_LIT:0> ] [ i ] ) <EOL> objs [ value ] [ <NUM_LIT:1> ] . append ( nzindex [ <NUM_LIT:1> ] [ i ] ) <EOL> objs [ value ] [ <NUM_LIT:2> ] . append ( nzindex [ <NUM_LIT:2> ] [ i ] ) <EOL> return objs <EOL> def computeUserThreshObjects ( self ) : <EOL> candidates = self . objectsSlow3d ( self . cc [ <NUM_LIT:0> , : , : , : , <NUM_LIT:0> ] ) <EOL> return candidates <EOL> def computeReferenceObjects ( self ) : <EOL> threshref = [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] <EOL> self . thres . setThresholds ( threshref ) <EOL> accessor = thresholdOverlay . MultivariateThresholdAccessor ( self . thres ) <EOL> data = numpy . asarray ( accessor [ <NUM_LIT:0> , : , : , : , <NUM_LIT:0> ] , dtype = '<STR_LIT>' ) <EOL> data = data . swapaxes ( <NUM_LIT:0> , <NUM_LIT:2> ) . view ( ) <EOL> cc = vigra . analysis . labelVolumeWithBackground ( data , <NUM_LIT:6> , <NUM_LIT:2> ) <EOL> cc = cc . swapaxes ( <NUM_LIT:0> , <NUM_LIT:2> ) . view ( ) <EOL> objs_ref = self . objectsSlow3d ( cc ) <EOL> return objs_ref <EOL> def filterObjects ( self , objsbig , objsref ) : <EOL> goodobjs = [ ] <EOL> bboxes = [ ] <EOL> print "<STR_LIT>" , self . minsize , "<STR_LIT>" , self . maxsize <EOL> for key , value in objsbig . iteritems ( ) : <EOL> if len ( value [ <NUM_LIT:0> ] ) > self . minsize : <EOL> goodobjs . append ( value ) <EOL> bboxes . append ( [ numpy . amin ( value [ <NUM_LIT:0> ] ) , numpy . amin ( value [ <NUM_LIT:1> ] ) , numpy . amin ( value [ <NUM_LIT:2> ] ) , numpy . amax ( value [ <NUM_LIT:0> ] ) , numpy . amax ( value [ <NUM_LIT:1> ] ) , numpy . amax ( value [ <NUM_LIT:2> ] ) ] ) <EOL> goodobjsref = [ ] <EOL> bboxesref = [ ] <EOL> for key , value in objsref . iteritems ( ) : <EOL> if len ( value [ <NUM_LIT:0> ] ) > self . minsize : <EOL> goodobjsref . append ( value ) <EOL> bboxesref . append ( [ numpy . amin ( value [ <NUM_LIT:0> ] ) , numpy . amin ( value [ <NUM_LIT:1> ] ) , numpy . amin ( value [ <NUM_LIT:2> ] ) , numpy . amax ( value [ <NUM_LIT:0> ] ) , numpy . amax ( value [ <NUM_LIT:1> ] ) , numpy . amax ( value [ <NUM_LIT:2> ] ) ] ) <EOL> found = False <EOL> foundlist = [ ] <EOL> objs_final = [ ] <EOL> for i , big in enumerate ( bboxesref ) : <EOL> found = False <EOL> for j , small in enumerate ( bboxes ) : <EOL> if small [ <NUM_LIT:0> ] >= big [ <NUM_LIT:0> ] and small [ <NUM_LIT:3> ] <= big [ <NUM_LIT:3> ] and small [ <NUM_LIT:1> ] >= big [ <NUM_LIT:1> ] and small [ <NUM_LIT:4> ] <= big [ <NUM_LIT:4> ] and small [ <NUM_LIT:2> ] >= big [ <NUM_LIT:2> ] and small [ <NUM_LIT:5> ] <= big [ <NUM_LIT:5> ] : <EOL> found = True <EOL> break <EOL> else : <EOL> continue <EOL> if found == True : <EOL> if len ( goodobjsref [ i ] [ <NUM_LIT:0> ] ) < self . maxsize : <EOL> objs_final . append ( goodobjsref [ i ] ) <EOL> print "<STR_LIT>" , len ( objs_final ) <EOL> return objs_final </s>
