66
77import matplotlib .pyplot as plt
88import numpy as np
9- from neo .core import CircularRegionOfInterest , RectangularRegionOfInterest , PolygonRegionOfInterest
9+ from neo .core import CircularRegionOfInterest , RectangularRegionOfInterest , PolygonRegionOfInterest , ImageSequence
1010from numpy .random import rand
11+ import random
12+ import quantities as pq
1113
1214
15+ # First we create our image_sequence. Let's generate some data
16+
17+ l = []
18+ for frame in range (50 ):
19+ l .append ([])
20+ for y in range (100 ):
21+ l [frame ].append ([])
22+ for x in range (100 ):
23+ l [frame ][y ].append (random .randint (0 , 50 ))
24+
25+ image_seq = ImageSequence (l , sampling_rate = 500 * pq .Hz , spatial_scale = "m" , units = "V" )
26+
1327def plot_roi (roi , shape ):
1428 img = rand (120 , 100 )
1529 pir = np .array (roi .pixels_in_region ()).T
@@ -22,17 +36,17 @@ def plot_roi(roi, shape):
2236 ax .add_artist (shape )
2337
2438
25- roi = CircularRegionOfInterest (x = 50.3 , y = 50.8 , radius = 30.2 )
39+ roi = CircularRegionOfInterest (image_sequence = image_seq , x = 50.3 , y = 50.8 , radius = 30.2 )
2640shape = plt .Circle (roi .centre , roi .radius , color = "r" , fill = False )
2741plt .subplot (1 , 3 , 1 )
2842plot_roi (roi , shape )
2943
30- roi = RectangularRegionOfInterest (x = 50.3 , y = 40.2 , width = 40.1 , height = 50.3 )
44+ roi = RectangularRegionOfInterest (image_sequence = image_seq , x = 50.3 , y = 40.2 , width = 40.1 , height = 50.3 )
3145shape = plt .Rectangle ((roi .x - roi .width / 2.0 , roi .y - roi .height / 2.0 ), roi .width , roi .height , color = "r" , fill = False )
3246plt .subplot (1 , 3 , 2 )
3347plot_roi (roi , shape )
3448
35- roi = PolygonRegionOfInterest ((20.3 , 30.2 ), (80.7 , 30.1 ), (55.2 , 59.4 ))
49+ roi = PolygonRegionOfInterest (image_seq , (20.3 , 30.2 ), (80.7 , 30.1 ), (55.2 , 59.4 ))
3650shape = plt .Polygon (np .array (roi .vertices ), closed = True , color = "r" , fill = False )
3751plt .subplot (1 , 3 , 3 )
3852plot_roi (roi , shape )
0 commit comments