1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- # -*- coding: utf-8 -*-
- '''
- Created on 28.07.2012
- @author: frank
- '''
- import numpy as np
- from stim_movie import StimulusSet
- from objsimpy.stimview import run_stimview
- import os
- def main():
- file_path = "gauss.idlmov"
- generate_gauss_stim(file_path,
- output_width=20,
- output_height=20,
- fwhm=0.15, shift_x=1,
- shift_y=1,
- nx=20,
- ny=20,
- start_shifted=False,
- xy_ratio=1.7)
- run_stimview(file_path)
-
- def generate_gauss_stim(file_path="gauss.idlmov", output_width=20, output_height=20, fwhm=0.17,
- shift_x=1, shift_y=1, nx=20, ny=20, start_shifted=False, xy_ratio=None):
- """Generate a stimulus set of Gaussian blobs at different positions"""
-
- pic_prototype = make_gaussian_2d(output_width, output_height, fwhm, xy_ratio)
- if start_shifted:
- pic_prototype = np.roll(pic_prototype, 1-output_width/2, axis=1)
- pic_prototype = np.roll(pic_prototype, 1-output_height/2, axis=0)
- pics = []
- for y in range(ny):
- y_rolled = np.roll(pic_prototype, y * shift_y, axis=0)
- for x in range(nx):
- x_rolled = np.roll(y_rolled, x * shift_x, axis=1)
- pics.append(x_rolled)
- stim_set = StimulusSet(pics=pics)
- stim_set.save(file_path)
-
-
- def make_gaussian_2d(output_width, output_height, fwhm, xy_ratio=None):
- """ Make gaussian kernel
-
- parameters:
- @param output_width: image width in pixels
- @param output_height: image height in pixels
- @param fwhm: full-width-at-half_maximum, value between 0 and 1, relative to output_width
- @return: numpy array with centered gaussian
- """
- if xy_ratio is None:
- xy_ratio = float(output_width) / float(output_height)
- x = np.linspace(-0.5, 0.5, output_width)
- y = np.linspace(-0.5/xy_ratio, 0.5/xy_ratio, output_height)
- y = y[:,np.newaxis]
- sigma = fwhm / (2 * np.sqrt(2*np.log(2)))
- return np.exp(-(x**2 + y**2) / (2*sigma*sigma))
- def generate_single_stim(file_path="single.idlmov", output_width=20, output_height=20):
- pic = np.zeros([output_width, output_height])
- pic[int(output_width/2)+4,int(output_height/2)+4] = 1.
- stim_set = StimulusSet(pics = [pic])
- stim_set.save(file_path)
- if __name__ == '__main__':
- main()
|