JeVoisBase  1.21
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
env_motion_channel.c
Go to the documentation of this file.
1/*!@file env_motion_channel.c */
2
3// //////////////////////////////////////////////////////////////////// //
4// The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 //
5// by the University of Southern California (USC) and the iLab at USC. //
6// See http://iLab.usc.edu for information about this project. //
7// //////////////////////////////////////////////////////////////////// //
8// Major portions of the iLab Neuromorphic Vision Toolkit are protected //
9// under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
10// in Visual Environments, and Applications'' by Christof Koch and //
11// Laurent Itti, California Institute of Technology, 2001 (patent //
12// pending; application number 09/912,225 filed July 23, 2001; see //
13// http://pair.uspto.gov/cgi-bin/final/home.pl for current status). //
14// //////////////////////////////////////////////////////////////////// //
15// This file is part of the iLab Neuromorphic Vision C++ Toolkit. //
16// //
17// The iLab Neuromorphic Vision C++ Toolkit is free software; you can //
18// redistribute it and/or modify it under the terms of the GNU General //
19// Public License as published by the Free Software Foundation; either //
20// version 2 of the License, or (at your option) any later version. //
21// //
22// The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope //
23// that it will be useful, but WITHOUT ANY WARRANTY; without even the //
24// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
25// PURPOSE. See the GNU General Public License for more details. //
26// //
27// You should have received a copy of the GNU General Public License //
28// along with the iLab Neuromorphic Vision C++ Toolkit; if not, write //
29// to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, //
30// Boston, MA 02111-1307 USA. //
31// //////////////////////////////////////////////////////////////////// //
32//
33// Primary maintainer for this file: Rob Peters <rjpeters at usc dot edu>
34// $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Envision/env_motion_channel.c $
35// $Id: env_motion_channel.c 9830 2008-06-18 18:50:22Z lior $
36//
37
39
45
46// ######################################################################
47// env_motion_channel function definitions:
48// ######################################################################
49
50// ######################################################################
52 const struct env_params* envp)
53{
54 env_pyr_init_empty(&chan->unshifted_prev);
56 chan->shifted_prev = (struct env_pyr*)env_allocate(envp->num_motion_directions * sizeof(struct env_pyr));
57 for (env_size_t i = 0; i < envp->num_motion_directions; ++i) env_pyr_init_empty(&chan->shifted_prev[i]);
58}
59
60// ######################################################################
62{
64 for (env_size_t i = 0; i < chan->num_directions; ++i) env_pyr_make_empty(&chan->shifted_prev[i]);
66 chan->num_directions = 0;
67 chan->shifted_prev = 0;
68}
69
70// ######################################################################
72 const char* tagName,
73 const struct env_params* envp,
74 const struct env_math* imath,
75 const struct env_dims inputdims,
76 struct env_pyr* unshiftedCur,
77 env_chan_status_func* status_func,
78 void* status_userdata,
79 struct env_image* result)
80{
81 env_img_make_empty(result);
82
83 if (chan->num_directions != envp->num_motion_directions)
84 {
86 env_motion_channel_init(chan, envp);
87 }
88
89 if (chan->num_directions == 0) return;
90
91 const env_size_t firstlevel = envp->cs_lev_min;
93
94 struct env_image chanOut = env_img_initializer;
95
96 char buf[17] =
97 {
98 'r', 'e', 'i', 'c', 'h', 'a', 'r', 'd', 't', // 0--8
99 '(', '_', '_', // 9--11
100 '/', '_', '_', ')', '\0' // 12--16
101 };
102
103 ENV_ASSERT(chan->num_directions <= 99);
104
105 buf[13] = '0' + (chan->num_directions / 10);
106 buf[14] = '0' + (chan->num_directions % 10);
107
108 // compute Reichardt motion detection into several directions
109 for (env_size_t dir = 0; dir < chan->num_directions; ++dir)
110 {
111 // theta = (360.0 * i) / chan->num_directions;
112 const env_size_t thetaidx = (dir * ENV_TRIG_TABSIZ) / chan->num_directions;
113
114 ENV_ASSERT(thetaidx < ENV_TRIG_TABSIZ);
115
116 buf[10] = '0' + ((dir+1) / 10);
117 buf[11] = '0' + ((dir+1) % 10);
118
119 // create an empty pyramid
120 struct env_pyr shiftedCur;
121 env_pyr_init(&shiftedCur, depth);
122
123 // fill the empty pyramid with the shifted version
124 for (env_size_t i = firstlevel; i < depth; ++i)
125 {
126 env_img_resize_dims(env_pyr_imgw(&shiftedCur, i), env_pyr_img(unshiftedCur, i)->dims);
127 env_shift_image(env_pyr_img(unshiftedCur, i), imath->costab[thetaidx], -imath->sintab[thetaidx],
128 ENV_TRIG_NBITS, env_pyr_imgw(&shiftedCur, i));
129 }
130
131 env_chan_direction(buf, envp, imath, inputdims, &chan->unshifted_prev, unshiftedCur,
132 &chan->shifted_prev[dir], &shiftedCur, status_func, status_userdata, &chanOut);
133
134 env_pyr_swap(&chan->shifted_prev[dir], &shiftedCur);
135 env_pyr_make_empty(&shiftedCur);
136
137 if (env_img_initialized(&chanOut))
138 {
139 if (!env_img_initialized(result))
140 {
141 env_img_resize_dims(result, chanOut.dims);
142 env_c_image_div_scalar(env_img_pixels(&chanOut), env_img_size(&chanOut), (intg32) chan->num_directions,
143 env_img_pixelsw(result));
144 }
145 else
146 {
147 ENV_ASSERT(env_dims_equal(chanOut.dims, result->dims));
148 env_c_image_div_scalar_accum(env_img_pixels(&chanOut), env_img_size(&chanOut), (intg32) chan->num_directions,
149 env_img_pixelsw(result));
150 }
151 }
152 }
153
154 env_img_make_empty(&chanOut);
155
156 if (env_img_initialized(result))
157 {
159 if (status_func) (*status_func)(status_userdata, tagName, result);
160 }
161
162 ///// BEWARE THIS SEGFAULTS the other channels that need the pyr!! FIXME
163 env_pyr_swap(unshiftedCur, &chan->unshifted_prev);
164 env_pyr_make_empty(unshiftedCur);
165 // USE THIS INSEAD IF MULTITHREADED:
166 //env_pyr_copy_src_dst(unshiftedCur, &chan->unshifted_prev);
167}
168
void env_c_image_div_scalar_accum(const intg32 *const a, const env_size_t sz, intg32 val, intg32 *const dst)
result += a / val
void env_c_image_div_scalar(const intg32 *const a, const env_size_t sz, intg32 val, intg32 *const dst)
result = a / val
void env_chan_direction(const char *tagName, const struct env_params *envp, const struct env_math *imath, const struct env_dims inputdims, const struct env_pyr *unshiftedPrev, const struct env_pyr *unshiftedCur, const struct env_pyr *shiftedPrev, const struct env_pyr *shiftedCur, env_chan_status_func *status_func, void *status_userdata, struct env_image *result)
A motion sensitive channel with direction selectivity.
void() env_chan_status_func(void *userdata, const char *tagName, const struct env_image *img)
Definition env_channel.h:55
void * env_allocate(unsigned long nbytes)
Definition env_config.h:58
void env_deallocate(void *mem)
Definition env_config.h:59
void env_img_resize_dims(struct env_image *img, const struct env_dims d)
Definition env_image.c:64
#define env_img_initializer
Definition env_image.h:49
void env_img_make_empty(struct env_image *img)
Definition env_image.c:56
#define INTMAXNORMMAX
#define INTMAXNORMMIN
void env_max_normalize_inplace(struct env_image *src, intg32 min, intg32 max, enum env_maxnorm_type typ, const intg32 rangeThresh)
void env_shift_image(const struct env_image *srcImg, const env_ssize_t dxnumer, const env_ssize_t dynumer, const env_size_t denombits, struct env_image *result)
#define ENV_ASSERT(expr)
Definition env_log.h:63
#define ENV_TRIG_TABSIZ
Definition env_math.h:44
#define ENV_TRIG_NBITS
Definition env_math.h:45
void env_motion_channel_init(struct env_motion_channel *chan, const struct env_params *envp)
void env_motion_channel_input_and_consume_pyr(struct env_motion_channel *chan, const char *tagName, const struct env_params *envp, const struct env_math *imath, const struct env_dims inputdims, struct env_pyr *unshiftedCur, env_chan_status_func *status_func, void *status_userdata, struct env_image *result)
env_motion_channel only requires luminosity input
void env_motion_channel_destroy(struct env_motion_channel *chan)
env_size_t env_max_pyr_depth(const struct env_params *envp)
Definition env_params.c:79
void env_pyr_init(struct env_pyr *pyr, const env_size_t n)
Construct with a given number of empty images.
Definition env_pyr.c:41
void env_pyr_swap(struct env_pyr *pyr1, struct env_pyr *pyr2)
Swap contents with another env_pyr.
Definition env_pyr.c:60
void env_pyr_make_empty(struct env_pyr *dst)
Definition env_pyr.c:51
ENV_INTG32_TYPE intg32
32-bit signed integer
Definition env_types.h:52
unsigned long env_size_t
Definition env_types.h:71
A simple struct to hold a pair of width/height dimensions.
Definition env_types.h:81
Basic image class.
Definition env_image.h:44
struct env_dims dims
Definition env_image.h:45
const intg16 * costab
Definition env_math.h:52
const intg16 * sintab
Definition env_math.h:51
A composite channel containing a set of direction channels.
struct env_pyr unshifted_prev
struct env_pyr * shifted_prev
intg32 range_thresh
Definition env_params.h:47
env_size_t num_motion_directions
Definition env_params.h:49
enum env_maxnorm_type maxnorm_type
Definition env_params.h:46
env_size_t cs_lev_min
Definition env_params.h:54
This class implements a set of images, often used as a dyadic pyramid.
Definition env_pyr.h:46
env_size_t depth
Definition env_pyr.h:48