24 #ifndef __IMAGEPROCESSORS
25 #define __IMAGEPROCESSORS
29 #include <selforg/stl_adds.h>
31 #define MIN3(x,y,z) x<y ? (x<z ? x : z) : (y<z ? y : z)
32 #define MAX3(x,y,z) x>y ? (x>z ? x : z) : (y>z ? y : z)
55 virtual void process(
const osg::Image* src, osg::Image* dest) = 0;
59 assert(imgs.size()>0);
90 dest.
img->allocateImage(src.
img->s(), src.
img->t(), 1, GL_LUMINANCE, GL_UNSIGNED_BYTE);
96 printf(
"BWImageProcessor: Select: Red %i, Green %i, Blue %i : numchannels %i\n",
101 virtual void process(
const osg::Image* src, osg::Image* dest){
102 assert(src && src->getPixelFormat()==GL_RGB && src->getDataType()==GL_UNSIGNED_BYTE);
103 for(
int r=0; r < src->t(); ++r) {
104 const unsigned char* sdata = src->data(0, r);
105 unsigned char* ddata = dest->data(0, r);
106 for(
int c=0;
c < src->s(); ++
c) {
134 dest.
img->allocateImage(src.
img->s(), src.
img->t(), 1, GL_RGB, GL_UNSIGNED_BYTE);
135 dest.
name =
"hsv(" + src.
name +
")";
138 virtual void process(
const osg::Image* src, osg::Image* dest){
139 assert(src && src->getPixelFormat()==GL_RGB && src->getDataType()==GL_UNSIGNED_BYTE);
140 for(
int r=0; r < src->t(); ++r) {
141 const unsigned char* sdata = src->data(0, r);
142 unsigned char* ddata = dest->data(0, r);
143 for(
int c=0;
c < src->s(); ++
c) {
144 RGBtoHSV(*(sdata),*(sdata+1),*(sdata+2),
145 (*ddata), *(ddata+1), *(ddata+2));
158 void RGBtoHSV(
unsigned char r,
unsigned char g,
unsigned char b,
159 unsigned char& h,
unsigned char& s,
unsigned char& v ) {
163 min =
MIN3( r, g, b );
164 max =
MAX3( r, g, b );
168 s = (
unsigned char)(255.0*delta / max);
170 if( max == 0 || delta == 0){
178 hue = float( g - b ) / delta;
180 hue = 2.0 + float( b - r ) / delta;
182 hue = 4.0 + float( r - g ) / delta;
209 dest.
img->allocateImage(src.
img->s(), src.
img->t(), 1, GL_LUMINANCE, GL_UNSIGNED_BYTE);
211 dest.
name =
"spots(" + src.
name +
")";
214 virtual void process(
const osg::Image* src, osg::Image* dest){
216 assert(src && src->getPixelFormat()==GL_RGB && src->getDataType()==GL_UNSIGNED_BYTE);
217 for(
int r=0; r < src->t(); ++r) {
218 const unsigned char* sdata = src->data(0, r);
219 unsigned char* ddata = dest->data(0, r);
220 for(
int c=0;
c < src->s(); ++
c) {
223 (*ddata) = *(sdata+2);
254 dest.
img->allocateImage(
num, 1, 1, GL_LUMINANCE, GL_UNSIGNED_BYTE);
255 dest.
name =
"line(" + src.
name +
")";
258 virtual void process(
const osg::Image* src, osg::Image* dest){
260 assert(src && src->getPixelFormat()==GL_LUMINANCE && src->getDataType()==GL_UNSIGNED_BYTE);
265 int numpixel_per_segm = size*h;
267 unsigned char* destdata = dest->data();
268 for(
int k=0; k<
num; k++){
270 for(
int j=0; j<h; j++){
271 const unsigned char* pixel = src->data(k*size, j);
272 for(
int i=0; i< size; i++){
277 segmentvalue = int((
double)sum*
factor/(
double)numpixel_per_segm);
278 destdata[k] =
std::min(segmentvalue,255);
300 assert(src.
img && src.
img->getDataType()==GL_UNSIGNED_BYTE);
301 dest.
img->allocateImage(src.
img->s(), src.
img->t(), 1, src.
img->getPixelFormat(),
306 virtual void process(
const osg::Image* src, osg::Image* dest){
307 for(
int r=0; r < src->t(); ++r) {
308 const unsigned char* sdata = src->data(0, r);
309 unsigned char* ddata = dest->data(0, r);
310 for(
unsigned int c=0;
c < src->getRowSizeInBytes(); ++
c) {
311 *ddata = (
unsigned char)(((
float)*sdata)*
factor + ((
float)*ddata)*(1-
factor));
bool red
Definition: imageprocessors.h:113
virtual ~AvgImgProc()
Definition: imageprocessors.h:297
std::vector< CameraImage > CameraImages
Definition: camera.h:91
Definition: imageprocessors.h:81
BWImageProcessor(bool show, float scale, char channelmask=7)
Definition: imageprocessors.h:84
HSVImgProc(bool show, float scale)
Definition: imageprocessors.h:127
virtual void process(const osg::Image *src, osg::Image *dest)
overload this function and do processing here
Definition: imageprocessors.h:138
bool blue
Definition: imageprocessors.h:113
virtual void initDestImage(Camera::CameraImage &dest, const Camera::CameraImage &src)
overload this function and initialise the dest.img and the dest.name
Definition: imageprocessors.h:133
Definition: imageprocessors.h:124
StdImageProcessor(bool show, float scale)
Definition: imageprocessors.h:44
Definition: imageprocessors.h:81
Definition: imageprocessors.h:124
Colors
Definition: imageprocessors.h:124
Definition: imageprocessors.h:81
Definition: imageprocessors.h:125
converts the image to a HSV coded image
Definition: imageprocessors.h:123
filters for a specific color (requires HSV, so use HSVImgProc before)
Definition: imageprocessors.h:199
Definition: imageprocessors.h:124
virtual void process(const osg::Image *src, osg::Image *dest)
overload this function and do processing here
Definition: imageprocessors.h:258
virtual void initDestImage(Camera::CameraImage &dest, const Camera::CameraImage &src)
overload this function and initialise the dest.img and the dest.name
Definition: imageprocessors.h:89
Definition: imageprocessors.h:124
void RGBtoHSV(unsigned char r, unsigned char g, unsigned char b, unsigned char &h, unsigned char &s, unsigned char &v)
converts RGB to HSV color model; r,g,b values are from 0 to 255; h = [0,180]+255, s = [0...
Definition: imageprocessors.h:158
structure to store the image data and information for display
Definition: camera.h:80
virtual ~StdImageProcessor()
Definition: imageprocessors.h:48
virtual void initDestImage(Camera::CameraImage &dest, const Camera::CameraImage &src)
overload this function and initialise the dest.img and the dest.name
Definition: imageprocessors.h:299
Definition: imageprocessors.h:81
Definition: imageprocessors.h:81
virtual void process(const osg::Image *src, osg::Image *dest)
overload this function and do processing here
Definition: imageprocessors.h:306
virtual void initDestImage(Camera::CameraImage &dest, const Camera::CameraImage &src)
overload this function and initialise the dest.img and the dest.name
Definition: imageprocessors.h:208
virtual void process(const osg::Image *src, osg::Image *dest)
overload this function and do processing here
Definition: imageprocessors.h:101
int num
Definition: imageprocessors.h:281
float scale
scaling for display
Definition: camera.h:87
creates a lightsensitive sensorline.
Definition: imageprocessors.h:246
virtual void process()
perform the image calculation here
Definition: imageprocessors.h:67
double max(const matrix::Matrix &v)
returns the largest element
Definition: controller_misc.cpp:318
Definition: imageprocessors.h:125
char numchannels
Definition: imageprocessors.h:114
int time
Definition: imageprocessors.h:318
Definition: imageprocessors.h:125
virtual void process(const osg::Image *src, osg::Image *dest)
overload this function and do processing here
Definition: imageprocessors.h:214
double g(double z)
neuron transfer function
Definition: regularisation.h:35
time average of image
Definition: imageprocessors.h:288
Definition: imageprocessors.h:125
Camera::CameraImage _dest
Definition: imageprocessors.h:73
int val_threshold
Definition: imageprocessors.h:235
virtual ~LineImgProc()
Definition: imageprocessors.h:251
virtual void initDestImage(Camera::CameraImage &dest, const Camera::CameraImage &src)=0
overload this function and initialise the dest.img and the dest.name
string itos(int i)
integer to string with default formating
Definition: stl_adds.cpp:30
#define MAX3(x, y, z)
Definition: imageprocessors.h:32
ChannelMask
Definition: imageprocessors.h:81
#define MIN3(x, y, z)
Definition: imageprocessors.h:31
Camera::CameraImage _src
Definition: imageprocessors.h:74
Base class for image processing units.
Definition: imageprocessor.h:39
std::string name
name of the image
Definition: camera.h:88
char channelmask
Definition: imageprocessors.h:115
black and white image
Definition: imageprocessors.h:80
virtual Camera::CameraImage init(const Camera::CameraImages &imgs)
initialization with all images so far.
Definition: imageprocessors.h:58
Definition: imageprocessors.h:81
AvgImgProc(bool show, float scale, int time)
Definition: imageprocessors.h:291
virtual void initDestImage(Camera::CameraImage &dest, const Camera::CameraImage &src)
overload this function and initialise the dest.img and the dest.name
Definition: imageprocessors.h:253
bool green
Definition: imageprocessors.h:113
Standard image processor - convenience class for 1 to 1 image processing.
Definition: imageprocessors.h:43
double min(const matrix::Matrix &v)
returns the smallest element
Definition: controller_misc.cpp:307
int maxhue
Definition: imageprocessors.h:233
osg::Image * img
Definition: camera.h:85
int minhue
Definition: imageprocessors.h:232
Definition: imageprocessors.h:125
bool show
whether to show the image on the screen
Definition: camera.h:86
double factor
Definition: imageprocessors.h:282
ColorFilterImgProc(bool show, float scale, int minhue, int maxhue, int sat_threshold=100, int val_threshold=50)
Definition: imageprocessors.h:200
virtual ~BWImageProcessor()
Definition: imageprocessors.h:87
virtual ~HSVImgProc()
Definition: imageprocessors.h:131
LineImgProc(bool show, float scale, int num, double factor=20.0)
Definition: imageprocessors.h:247
float factor
Definition: imageprocessors.h:319
int sat_threshold
Definition: imageprocessors.h:234
int c
Definition: hexapod.cpp:56
virtual ~ColorFilterImgProc()
Definition: imageprocessors.h:206