CARLsim  3.0.3
CARLsim: a GPU-accelerated SNN simulator
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VisualStimulus Class Reference

Class to integrate CARLsim with a stimulus created using VisualStimulus.m Version: 4/11/14 Author: Michael Beyeler mbeye.nosp@m.ler@.nosp@m.uci.e.nosp@m.du More...

#include <visual_stimulus.h>

Public Types

enum  stimType_t { STIM_GRAY, STIM_RGB, STIM_UNKNOWN }
 List of stimulus file types. More...
 

Public Member Functions

 VisualStimulus (std::string fileName, bool wrapAroundEOF=true)
 Default constructor. More...
 
 ~VisualStimulus ()
 default destructor More...
 
unsigned char * getCurrentFrameChar ()
 returns char array of current frame More...
 
int getCurrentFrameNumber ()
 
PoissonRategetCurrentFramePoisson ()
 returns PoissonRate object of current frame More...
 
int getStimulusChannels ()
 returns the number of channels (1=grayscale, 3=RGB) More...
 
int getStimulusHeight ()
 returns the stimulus height (number of pixels) More...
 
int getStimulusLength ()
 returns the stimulus length (number of frames) More...
 
stimType_t getStimulusType ()
 returns the stimulus type (STIM_GRAY, STIM_RGB, etc.) More...
 
int getStimulusWidth ()
 returns the stimulus width (number of pixels) More...
 
unsigned char * readFrame ()
 Reads the next image frame and returns a pointer to the char array. More...
 
PoissonRatereadFrame (float maxPoisson)
 Reads the next image frame and returns a pointer to a PoissonRate object. More...
 
void rewind ()
 Rewinds the file pointer to the top. More...
 

Detailed Description

This class provides a means to integrate CARLsim with a stimulus created using VisualStimulus.m. The class reads from binary file, and returns either the raw character array or a PoissonRate object with the same size as number of pixels in a stimulus frame.

Common workflow:

  • 1. Create a stimulus in Matlab:
    * >> VS = VisualStimulus(32,32);
    * >> VS.addSinGrating
    * >> VS.saveToFile
    * 
    Successfully saved stimulus to file "inpGrating_gray_32x32x80.dat"
  • 2. In your main_.cpp, read from binary file:
    VisualStimulus VS("inpGrating_gray_32x32x80.dat");
    int videoLength = VS.getStimulusLength();
  • 3. Assign each frame to a SpikeGenerator group and run network
    for (int i=0; i<videoLength; i++) {
    PoissonRate * rates = VS.readFrame(50.0f); // grayscale value 255 will be mapped to 50 Hz
    snn.setSpikeRate(g1, rates); // for this to work, there must be 32x32=1024 neurons in g1
    snn.runNetwork(1,0); // run the network
    }

Definition at line 40 of file visual_stimulus.h.

Member Enumeration Documentation

enum stimType_t

STIM_GRAY: grayscale image STIM_RGB: RGB image STIM_UNKNOWN: unknown image type

Enumerator
STIM_GRAY 
STIM_RGB 
STIM_UNKNOWN 

Definition at line 65 of file visual_stimulus.h.

Constructor & Destructor Documentation

VisualStimulus ( std::string  fileName,
bool  wrapAroundEOF = true 
)

Instantiates an VisualStimulus object.

Parameters
[in]fileNamepath to binary file that was created using VisualStimulus.m
[in]wrapAroundEOFafter reaching the end of the file, whether to jump back to the top and start reading the first frame again. If this flag is false and the EOF is reached, a warning will be printed. Default: true.

Member Function Documentation

unsigned char* getCurrentFrameChar ( )
inline

Definition at line 120 of file visual_stimulus.h.

int getCurrentFrameNumber ( )
inline

Definition at line 122 of file visual_stimulus.h.

PoissonRate* getCurrentFramePoisson ( )
inline

Definition at line 121 of file visual_stimulus.h.

int getStimulusChannels ( )
inline

Definition at line 117 of file visual_stimulus.h.

int getStimulusHeight ( )
inline

Definition at line 115 of file visual_stimulus.h.

int getStimulusLength ( )
inline

Definition at line 116 of file visual_stimulus.h.

stimType_t getStimulusType ( )
inline

Definition at line 118 of file visual_stimulus.h.

int getStimulusWidth ( )
inline

Definition at line 114 of file visual_stimulus.h.

unsigned char* readFrame ( )

Advances the frame index by 1 (getCurrentFrameNumber) and returns the raw grayscale values for each pixel. The char array will have a total of getStimulusWidth()*getStimulusHeight()*getStimulusChannels() entries. The order is columns first (so the first getStimulusWidth() number of pixels will correspond to the top image row). Currently, only grayscale images are supported. Note that this will advance the frame index. If you want to access the char array or PoissonRate object of a frame that has already been read, use getCurrentFrameChar() or getCurrentFramePoisson() instead.

Returns
pointer to the char array of raw grayscale values
PoissonRate* readFrame ( float  maxPoisson)

Advances the frame index by 1 (getCurrentFrameNumber) and returns a pointer to a PoissonRate object. The object will have a total of getStimulusWidth()*getStimulusHeight()*getStimulusChannels() entries. The order is columns first (so the first getStimulusWidth() number of pixels will correspond to the top image row). The PoissonRate object can then be applied to a group: PoissonRate* rates = IS.readFrame(50.0f); snn.setSpikeRate(g1, rates); Currently, only grayscale images are supported. Note that this will advance the frame index. If you want to access the char array or PoissonRate object of a frame that has already been read, use getCurrentFrameChar() or getCurrentFramePoisson() instead.

Parameters
[in]maxPoissonthe range of grayscale values [0,255] will be linearly mapped to the range of Poisson rates [0,maxPoisson]. Default: 50 Hz.
Returns
pointer to a PoissonRate object
void rewind ( )

This function rewinds the file pointer back to the beginning of the file, so that the user can re-start reading the stimulus from the top.


The documentation for this class was generated from the following file: