55"""
66from imagepy import IPy , root_dir
77import wx , numpy as np , os
8- from imagepy .core .engine import Simple
9- from imagepy .core .roi import PointRoi
8+ from imagepy .core .engine import Filter , Simple
9+ from imagepy .core .roi import PointRoi , LineRoi
1010from imagepy .core .manager import ImageManager , WindowsManager
1111from imagepy .ui .widgets import HistCanvas
1212from pubsub import pub
1313import pandas as pd
1414
15+ from skimage .graph import route_through_array
16+ from imagepy .core .mark import GeometryMark
1517class HistogramFrame (wx .Frame ):
1618 def __init__ (self , parent , title , hist ):
1719 wx .Frame .__init__ (self , parent , title = title , style = wx .DEFAULT_DIALOG_STYLE )
@@ -200,4 +202,44 @@ def run(self, ips, imgs, para = None):
200202 IPy .show_table (pd .DataFrame (data , columns = titles ), ips .title + '-points' )
201203 if para ['buf' ]:ips .mark = Mark (mark )
202204
203- plgs = [Frequence , Statistic , Histogram , PointsValue ]
205+ class ShortRoute (Filter ):
206+ title = 'Short Route'
207+ note = ['auto_snap' ,'8-bit' , '16-bit' ,'int' , 'float' , 'req_roi' ,'preview' ]
208+
209+ para = {'fully connected' :True , 'geometric' :True ,'type' :'white line' }
210+ view = [(bool , 'fully connected' , 'fully connected' ),
211+ (bool , 'geometric' , 'geometric' ),
212+ (list , 'type' , ['white line' , 'gray line' , 'white line on ori' ], str , 'output' , '' )]
213+
214+ def load (self , ips ):
215+ if not isinstance (ips .roi , LineRoi ):
216+ IPy .alert ('LineRoi are needed!' )
217+ return False
218+ return True
219+
220+ def run (self , ips , snap , img , para = None ):
221+ img [:] = snap
222+ print (np .array (ips .roi .body ))
223+ pts = np .array (ips .roi .body ).astype (np .int )
224+ img_min ,img_max = snap .min (),snap .max ()
225+ arr = img .copy ()
226+ arr = (arr - arr .min ())/ np .ptp (arr )
227+
228+ print (pts )
229+
230+ if para ['type' ]== 'gray line' or para ['type' ]== 'white line' :
231+ img [:] = img_min
232+ for i in pts :
233+ for j in range (len (i )- 1 ):
234+ p0 = (i [j ][1 ],i [j ][0 ])
235+ p1 = (i [j + 1 ][1 ],i [j + 1 ][0 ])
236+ indices , weight = route_through_array (arr ,p0 , p1 )
237+ indices = np .array (indices )
238+ if para ['type' ]== 'white line on ori' :
239+ img [indices [:,0 ],indices [:,1 ]]= img_max
240+ elif para ['type' ]== 'gray line' :
241+ img [indices [:,0 ],indices [:,1 ]] = snap [indices [:,0 ],indices [:,1 ]]
242+ elif para ['type' ]== 'white line' :
243+ img [indices [:,0 ],indices [:,1 ]] = img_max
244+
245+ plgs = [Frequence , Statistic , Histogram , PointsValue ,ShortRoute ]
0 commit comments