CARLsim  6.1.0
CARLsim: a GPU-accelerated SNN simulator
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>

Classes

class  Impl
 

Public Member Functions

 VisualStimulus (std::string fileName, bool wrapAroundEOF=true)
 Default constructor. More...
 
 ~VisualStimulus ()
 default destructor More...
 
int getChannels ()
 returns the number of channels (1=grayscale, 3=RGB) More...
 
unsigned char * getCurrentFrameChar ()
 returns char array of current frame More...
 
int getCurrentFrameNumber ()
 
PoissonRategetCurrentFramePoisson ()
 returns PoissonRate object of current frame More...
 
int getHeight ()
 returns the stimulus height (number of pixels) More...
 
int getLength ()
 returns the stimulus length (number of frames) More...
 
stimType_t getType ()
 returns the stimulus type (STIM_GRAY, STIM_RGB, etc.) More...
 
int getWidth ()
 returns the stimulus width (number of pixels) More...
 
void print ()
 
unsigned char * readFrameChar ()
 Reads the next image frame and returns a pointer to the char array. More...
 
PoissonRatereadFramePoisson (float maxPoisson, float minPoisson=0.0f)
 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 58 of file visual_stimulus.h.

Constructor & Destructor Documentation

◆ VisualStimulus()

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.

Definition at line 229 of file visual_stimulus.cpp.

◆ ~VisualStimulus()

Definition at line 230 of file visual_stimulus.cpp.

Member Function Documentation

◆ getChannels()

int getChannels ( )

Definition at line 242 of file visual_stimulus.cpp.

Here is the call graph for this function:

◆ getCurrentFrameChar()

unsigned char * getCurrentFrameChar ( )

Definition at line 244 of file visual_stimulus.cpp.

Here is the call graph for this function:

◆ getCurrentFrameNumber()

int getCurrentFrameNumber ( )

Definition at line 246 of file visual_stimulus.cpp.

Here is the call graph for this function:

◆ getCurrentFramePoisson()

PoissonRate * getCurrentFramePoisson ( )

Definition at line 245 of file visual_stimulus.cpp.

Here is the call graph for this function:

◆ getHeight()

int getHeight ( )

Definition at line 240 of file visual_stimulus.cpp.

Here is the call graph for this function:

◆ getLength()

int getLength ( )

Definition at line 241 of file visual_stimulus.cpp.

Here is the call graph for this function:

◆ getType()

stimType_t getType ( )

Definition at line 243 of file visual_stimulus.cpp.

Here is the call graph for this function:

◆ getWidth()

int getWidth ( )

Definition at line 239 of file visual_stimulus.cpp.

Here is the call graph for this function:

◆ print()

void print ( )

Definition at line 237 of file visual_stimulus.cpp.

Here is the call graph for this function:

◆ readFrameChar()

unsigned char * readFrameChar ( )

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

Definition at line 232 of file visual_stimulus.cpp.

Here is the call graph for this function:

◆ readFramePoisson()

PoissonRate * readFramePoisson ( float  maxPoisson,
float  minPoisson = 0.0f 
)

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.

Parameters
[in]maxPoissonMaximum Poisson rate (must be positive). The range of grayscale values [0,255] will be linearly mapped to the range of Poisson rates [minPoisson,maxPoisson].
[in]minPoissonMaximum Poisson rate (must be non-negative). The range of grayscale values [0,255] will be linearly mapped to the range of Poisson rates [minPoisson,maxPoisson]. Default: 0 Hz.
Returns
pointer to a PoissonRate object
Note
maxPoisson must be greater than minPoisson. Neither of them can be
Attention
Each call to readFrame() 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.

Definition at line 233 of file visual_stimulus.cpp.

Here is the call graph for this function:

◆ rewind()

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.

Definition at line 236 of file visual_stimulus.cpp.

Here is the call graph for this function:

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