{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "## Slice images into patches using a RegionSet\n", "\n", "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!). " ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "#!/usr/bin/python3\n", "# -*- coding: utf-8 -*-\n", "\n", "from gridfix import * \n", "\"\"\"\n", "Creates a 4x3 grid region set, then cuts out all selected regions from every image in the\n", "example ImageSet and save them to individual files.\n", "\"\"\"\n", "\n", "imgs = ImageSet('images/tutorial_images.csv', label='tutorial')\n", "grid = GridRegionSet(imgs.size, (4, 3))\n", "\n", "grid.export_patches_from_set(imgs, crop=True)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "## Effects of local saliency on fixation probability\n", "\n", "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?" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " subject_number image_id region dvFix fMapFe\n", "0 201.0 106 1.0 0.0 0.011996\n", "1 201.0 106 2.0 0.0 0.051250\n", "2 201.0 106 3.0 0.0 0.029515\n", "3 201.0 106 4.0 0.0 0.032837\n", "4 201.0 106 5.0 0.0 0.020327\n", "5 201.0 106 6.0 0.0 0.038597\n", "6 201.0 106 7.0 0.0 0.024676\n", "7 201.0 106 8.0 0.0 0.017135\n", "8 201.0 106 9.0 0.0 0.029146\n", "9 201.0 106 10.0 1.0 0.129266\n", "10 201.0 106 11.0 0.0 0.088838\n", "11 201.0 106 12.0 0.0 0.169775\n", "12 201.0 106 13.0 0.0 0.093220\n", "13 201.0 106 14.0 0.0 0.085825\n", "14 201.0 106 15.0 0.0 0.046923\n", "15 201.0 106 16.0 0.0 0.025545\n", "16 201.0 106 17.0 1.0 0.209219\n", "17 201.0 106 18.0 0.0 0.231642\n", "18 201.0 106 19.0 1.0 0.130784\n", "19 201.0 106 20.0 1.0 0.310311\n", "20 201.0 106 21.0 0.0 0.447962\n", "21 201.0 106 22.0 1.0 0.709044\n", "22 201.0 106 23.0 1.0 0.224838\n", "23 201.0 106 24.0 0.0 0.029678\n", "24 201.0 106 25.0 1.0 0.343682\n", "25 201.0 106 26.0 0.0 0.203359\n", "26 201.0 106 27.0 1.0 0.146591\n", "27 201.0 106 28.0 1.0 0.328040\n", "28 201.0 106 29.0 1.0 0.507897\n", "29 201.0 106 30.0 0.0 0.431581\n", ".. ... ... ... ... ...\n", "18 209.0 97 19.0 1.0 0.595876\n", "19 209.0 97 20.0 1.0 0.411496\n", "20 209.0 97 21.0 1.0 0.464216\n", "21 209.0 97 22.0 1.0 0.660822\n", "22 209.0 97 23.0 1.0 0.664543\n", "23 209.0 97 24.0 0.0 0.308240\n", "24 209.0 97 25.0 0.0 0.154441\n", "25 209.0 97 26.0 1.0 0.506913\n", "26 209.0 97 27.0 0.0 0.566026\n", "27 209.0 97 28.0 0.0 0.508420\n", "28 209.0 97 29.0 0.0 0.229688\n", "29 209.0 97 30.0 0.0 0.649280\n", "30 209.0 97 31.0 0.0 0.492168\n", "31 209.0 97 32.0 1.0 0.264287\n", "32 209.0 97 33.0 0.0 0.144345\n", "33 209.0 97 34.0 0.0 0.461687\n", "34 209.0 97 35.0 0.0 0.293705\n", "35 209.0 97 36.0 0.0 0.096766\n", "36 209.0 97 37.0 0.0 0.064559\n", "37 209.0 97 38.0 0.0 0.128566\n", "38 209.0 97 39.0 0.0 0.231390\n", "39 209.0 97 40.0 1.0 0.324227\n", "40 209.0 97 41.0 0.0 0.041193\n", "41 209.0 97 42.0 0.0 0.092233\n", "42 209.0 97 43.0 0.0 0.073489\n", "43 209.0 97 44.0 0.0 0.038960\n", "44 209.0 97 45.0 0.0 0.041190\n", "45 209.0 97 46.0 0.0 0.044402\n", "46 209.0 97 47.0 0.0 0.066324\n", "47 209.0 97 48.0 0.0 0.141121\n", "\n", "[5760 rows x 5 columns]\n" ] } ], "source": [ "#!/usr/bin/python3\n", "# -*- coding: utf-8 -*-\n", "\n", "from gridfix import * \n", "\"\"\"\n", "Evaluates maps generated by the saliency model of Itti, Koch & Niebur (1998) \n", "for their predictive power of fixations on an 8x6 regular grid. This is a minimal\n", "example for a GridFix analysis using a single feature. \n", "\"\"\"\n", "\n", "# Analysis grid\n", "grid = GridRegionSet((800, 600), (8, 6))\n", "\n", "# Saliency maps and corresponding feature\n", "maps = ImageSet('maps/tutorial_maps.csv', mat_var='IKN98')\n", "sal = MapFeature(grid, maps) # default = mean\n", "\n", "# Fixation data with custom column names\n", "fix = Fixations('tutorial_fixations.csv', imageid='image_id', fixid='CURRENT_FIX_INDEX', \n", " x='CURRENT_FIX_X', y='CURRENT_FIX_Y', imageset=maps)\n", "\n", "# Generate model predictors\n", "salmodel = FixationModel(fix, grid, chunks=['subject_number', 'image_id'], features=[sal])\n", "salmodel.save('example2')\n", "\n", "print(salmodel.predictors)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.2" } }, "nbformat": 4, "nbformat_minor": 2 }