4.1. Slice images into patches using a RegionSet¶
Sometimes it is necessary to save the actual image patches generated by a RegionSet, e.g. for a poster / talks slide or simply to verify that the correct image areas are selected. This short example script exports all patches generated by a 4x3 grid on all images from the tutorial image set (15 images) into PNG files (15 x 12 = 180 output files!).
In [2]:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from gridfix import *
"""
Creates a 4x3 grid region set, then cuts out all selected regions from every image in the
example ImageSet and save them to individual files.
"""
imgs = ImageSet('images/tutorial_images.csv', label='tutorial')
grid = GridRegionSet(imgs.size, (4, 3))
grid.export_patches_from_set(imgs, crop=True)
4.2. Effects of local saliency on fixation probability¶
This example illustrates one of the most basic use cases of the GridFix toolbox: how does the local saliency value calculated by a given model of visual saliency influence fixation probabilities?
In [2]:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from gridfix import *
"""
Evaluates maps generated by the saliency model of Itti, Koch & Niebur (1998)
for their predictive power of fixations on an 8x6 regular grid. This is a minimal
example for a GridFix analysis using a single feature.
"""
# Analysis grid
grid = GridRegionSet((800, 600), (8, 6))
# Saliency maps and corresponding feature
maps = ImageSet('maps/tutorial_maps.csv', mat_var='IKN98')
sal = MapFeature(grid, maps) # default = mean
# Fixation data with custom column names
fix = Fixations('tutorial_fixations.csv', imageid='image_id', fixid='CURRENT_FIX_INDEX',
x='CURRENT_FIX_X', y='CURRENT_FIX_Y', imageset=maps)
# Generate model predictors
salmodel = FixationModel(fix, grid, chunks=['subject_number', 'image_id'], features=[sal])
salmodel.save('example2')
print(salmodel.predictors)
subject_number image_id region dvFix fMapFe
0 201.0 106 1.0 0.0 0.011996
1 201.0 106 2.0 0.0 0.051250
2 201.0 106 3.0 0.0 0.029515
3 201.0 106 4.0 0.0 0.032837
4 201.0 106 5.0 0.0 0.020327
5 201.0 106 6.0 0.0 0.038597
6 201.0 106 7.0 0.0 0.024676
7 201.0 106 8.0 0.0 0.017135
8 201.0 106 9.0 0.0 0.029146
9 201.0 106 10.0 1.0 0.129266
10 201.0 106 11.0 0.0 0.088838
11 201.0 106 12.0 0.0 0.169775
12 201.0 106 13.0 0.0 0.093220
13 201.0 106 14.0 0.0 0.085825
14 201.0 106 15.0 0.0 0.046923
15 201.0 106 16.0 0.0 0.025545
16 201.0 106 17.0 1.0 0.209219
17 201.0 106 18.0 0.0 0.231642
18 201.0 106 19.0 1.0 0.130784
19 201.0 106 20.0 1.0 0.310311
20 201.0 106 21.0 0.0 0.447962
21 201.0 106 22.0 1.0 0.709044
22 201.0 106 23.0 1.0 0.224838
23 201.0 106 24.0 0.0 0.029678
24 201.0 106 25.0 1.0 0.343682
25 201.0 106 26.0 0.0 0.203359
26 201.0 106 27.0 1.0 0.146591
27 201.0 106 28.0 1.0 0.328040
28 201.0 106 29.0 1.0 0.507897
29 201.0 106 30.0 0.0 0.431581
.. ... ... ... ... ...
18 209.0 97 19.0 1.0 0.595876
19 209.0 97 20.0 1.0 0.411496
20 209.0 97 21.0 1.0 0.464216
21 209.0 97 22.0 1.0 0.660822
22 209.0 97 23.0 1.0 0.664543
23 209.0 97 24.0 0.0 0.308240
24 209.0 97 25.0 0.0 0.154441
25 209.0 97 26.0 1.0 0.506913
26 209.0 97 27.0 0.0 0.566026
27 209.0 97 28.0 0.0 0.508420
28 209.0 97 29.0 0.0 0.229688
29 209.0 97 30.0 0.0 0.649280
30 209.0 97 31.0 0.0 0.492168
31 209.0 97 32.0 1.0 0.264287
32 209.0 97 33.0 0.0 0.144345
33 209.0 97 34.0 0.0 0.461687
34 209.0 97 35.0 0.0 0.293705
35 209.0 97 36.0 0.0 0.096766
36 209.0 97 37.0 0.0 0.064559
37 209.0 97 38.0 0.0 0.128566
38 209.0 97 39.0 0.0 0.231390
39 209.0 97 40.0 1.0 0.324227
40 209.0 97 41.0 0.0 0.041193
41 209.0 97 42.0 0.0 0.092233
42 209.0 97 43.0 0.0 0.073489
43 209.0 97 44.0 0.0 0.038960
44 209.0 97 45.0 0.0 0.041190
45 209.0 97 46.0 0.0 0.044402
46 209.0 97 47.0 0.0 0.066324
47 209.0 97 48.0 0.0 0.141121
[5760 rows x 5 columns]
In [ ]: