aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Native/Tango.ProtoTest/PMR/StubGPIOReadByteRequest.pb.h
blob: d9eb017f1b5359130719fa459bfba6fe36b660ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: StubGPIOReadByteRequest.proto

#ifndef PROTOBUF_StubGPIOReadByteRequest_2eproto__INCLUDED
#define PROTOBUF_StubGPIOReadByteRequest_2eproto__INCLUDED

#include <string>

#include <google/protobuf/stubs/common.h>

#if GOOGLE_PROTOBUF_VERSION < 3004000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers.  Please update
#error your headers.
#endif
#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers.  Please
#error regenerate this file with a newer version of protoc.
#endif

#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_table_driven.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
#include <google/protobuf/repeated_field.h>  // IWYU pragma: export
#include <google/protobuf/extension_set.h>  // IWYU pragma: export
#include <google/protobuf/unknown_field_set.h>
// @@protoc_insertion_point(includes)
namespace Tango {
namespace PMR {
namespace Stubs {
class StubGPIOReadByteRequest;
class StubGPIOReadByteRequestDefaultTypeInternal;
extern StubGPIOReadByteRequestDefaultTypeInternal _StubGPIOReadByteRequest_default_instance_;
}  // namespace Stubs
}  // namespace PMR
}  // namespace Tango

namespace Tango {
namespace PMR {
namespace Stubs {

namespace protobuf_StubGPIOReadByteRequest_2eproto {
// Internal implementation detail -- do not call these.
struct TableStruct {
  static const ::google::protobuf::internal::ParseTableField entries[];
  static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
  static const ::google::protobuf::internal::ParseTable schema[];
  static const ::google::protobuf::uint32 offsets[];
  static const ::google::protobuf::internal::FieldMetadata field_metadata[];
  static const ::google::protobuf::internal::SerializationTable serialization_table[];
  static void InitDefaultsImpl();
};
void AddDescriptors();
void InitDefaults();
}  // namespace protobuf_StubGPIOReadByteRequest_2eproto

// ===================================================================

class StubGPIOReadByteRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Tango.PMR.Stubs.StubGPIOReadByteRequest) */ {
 public:
  StubGPIOReadByteRequest();
  virtual ~StubGPIOReadByteRequest();

  StubGPIOReadByteRequest(const StubGPIOReadByteRequest& from);

  inline StubGPIOReadByteRequest& operator=(const StubGPIOReadByteRequest& from) {
    CopyFrom(from);
    return *this;
  }
  #if LANG_CXX11
  StubGPIOReadByteRequest(StubGPIOReadByteRequest&& from) noexcept
    : StubGPIOReadByteRequest() {
    *this = ::std::move(from);
  }

  inline StubGPIOReadByteRequest& operator=(StubGPIOReadByteRequest&& from) noexcept {
    if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
      if (this != &from) InternalSwap(&from);
    } else {
      CopyFrom(from);
    }
    return *this;
  }
  #endif
  static const ::google::protobuf::Descriptor* descriptor();
  static const StubGPIOReadByteRequest& default_instance();

  static inline const StubGPIOReadByteRequest* internal_default_instance() {
    return reinterpret_cast<const StubGPIOReadByteRequest*>(
               &_StubGPIOReadByteRequest_default_instance_);
  }
  static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
    0;

  void Swap(StubGPIOReadByteRequest* other);
  friend void swap(StubGPIOReadByteRequest& a, StubGPIOReadByteRequest& b) {
    a.Swap(&b);
  }

  // implements Message ----------------------------------------------

  inline StubGPIOReadByteRequest* New() const PROTOBUF_FINAL { return New(NULL); }

  StubGPIOReadByteRequest* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
  void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
  void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
  void CopyFrom(const StubGPIOReadByteRequest& from);
  void MergeFrom(const StubGPIOReadByteRequest& from);
  void Clear() PROTOBUF_FINAL;
  bool IsInitialized() const PROTOBUF_FINAL;

  size_t ByteSizeLong() const PROTOBUF_FINAL;
  bool MergePartialFromCodedStream(
      ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
  void SerializeWithCachedSizes(
      ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
  ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
      bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
  int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
  private:
  void SharedCtor();
  void SharedDtor();
  void SetCachedSize(int size) const PROTOBUF_FINAL;
  void InternalSwap(StubGPIOReadByteRequest* other);
  private:
  inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
    return NULL;
  }
  inline void* MaybeArenaPtr() const {
    return NULL;
  }
  public:

  ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;

  // nested types ----------------------------------------------------

  // accessors -------------------------------------------------------

  // string PortId = 1;
  void clear_portid();
  static const int kPortIdFieldNumber = 1;
  const ::std::string& portid() const;
  void set_portid(const ::std::string& value);
  #if LANG_CXX11
  void set_portid(::std::string&& value);
  #endif
  void set_portid(const char* value);
  void set_portid(const char* value, size_t size);
  ::std::string* mutable_portid();
  ::std::string* release_portid();
  void set_allocated_portid(::std::string* portid);

  // @@protoc_insertion_point(class_scope:Tango.PMR.Stubs.StubGPIOReadByteRequest)
 private:

  ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
  ::google::protobuf::internal::ArenaStringPtr portid_;
  mutable int _cached_size_;
  friend struct protobuf_StubGPIOReadByteRequest_2eproto::TableStruct;
};
// ===================================================================


// ===================================================================

#if !PROTOBUF_INLINE_NOT_IN_HEADERS
#ifdef __GNUC__
  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif  // __GNUC__
// StubGPIOReadByteRequest

// string PortId = 1;
inline void StubGPIOReadByteRequest::clear_portid() {
  portid_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& StubGPIOReadByteRequest::portid() const {
  // @@protoc_insertion_point(field_get:Tango.PMR.Stubs.StubGPIOReadByteRequest.PortId)
  return portid_.GetNoArena();
}
inline void StubGPIOReadByteRequest::set_portid(const ::std::string& value) {
  
  portid_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
  // @@protoc_insertion_point(field_set:Tango.PMR.Stubs.StubGPIOReadByteRequest.PortId)
}
#if LANG_CXX11
inline void StubGPIOReadByteRequest::set_portid(::std::string&& value) {
  
  portid_.SetNoArena(
    &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
  // @@protoc_insertion_point(field_set_rvalue:Tango.PMR.Stubs.StubGPIOReadByteRequest.PortId)
}
#endif
inline void StubGPIOReadByteRequest::set_portid(const char* value) {
  GOOGLE_DCHECK(value != NULL);
  
  portid_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
  // @@protoc_insertion_point(field_set_char:Tango.PMR.Stubs.StubGPIOReadByteRequest.PortId)
}
inline void StubGPIOReadByteRequest::set_portid(const char* value, size_t size) {
  
  portid_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
      ::std::string(reinterpret_cast<const char*>(value), size));
  // @@protoc_insertion_point(field_set_pointer:Tango.PMR.Stubs.StubGPIOReadByteRequest.PortId)
}
inline ::std::string* StubGPIOReadByteRequest::mutable_portid() {
  
  // @@protoc_insertion_point(field_mutable:Tango.PMR.Stubs.StubGPIOReadByteRequest.PortId)
  return portid_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline ::std::string* StubGPIOReadByteRequest::release_portid() {
  // @@protoc_insertion_point(field_release:Tango.PMR.Stubs.StubGPIOReadByteRequest.PortId)
  
  return portid_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline void StubGPIOReadByteRequest::set_allocated_portid(::std::string* portid) {
  if (portid != NULL) {
    
  } else {
    
  }
  portid_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), portid);
  // @@protoc_insertion_point(field_set_allocated:Tango.PMR.Stubs.StubGPIOReadByteRequest.PortId)
}

#ifdef __GNUC__
  #pragma GCC diagnostic pop
#endif  // __GNUC__
#endif  // !PROTOBUF_INLINE_NOT_IN_HEADERS

// @@protoc_insertion_point(namespace_scope)


}  // namespace Stubs
}  // namespace PMR
}  // namespace Tango

// @@protoc_insertion_point(global_scope)

#endif  // PROTOBUF_StubGPIOReadByteRequest_2eproto__INCLUDED
an>/=(float)this->getNBpixels(); std::cout<<"Color channels proportions: pR, pG, pB= "<<_pR<<", "<<_pG<<", "<<_pB<<", "<<std::endl; break; case RETINA_COLOR_DIAGONAL: for (unsigned int index=0 ; index<this->getNBpixels(); ++index) { _colorSampling[index] = index+((index%3+(index%_filterOutput.getNBcolumns()))%3)*_filterOutput.getNBpixels(); } _pR=_pB=_pG=1.f/3; break; case RETINA_COLOR_BAYER: // default sets bayer sampling for (unsigned int index=0 ; index<_filterOutput.getNBpixels(); ++index) { //First line: R G R G _colorSampling[index] = index+((index/_filterOutput.getNBcolumns())%2)*_filterOutput.getNBpixels()+((index%_filterOutput.getNBcolumns())%2)*_filterOutput.getNBpixels(); //First line: G R G R //_colorSampling[index] = 3*index+((index/_filterOutput.getNBcolumns())%2)+((index%_filterOutput.getNBcolumns()+1)%2); } _pR=_pB=0.25; _pG=0.5; break; default: #ifdef RETINACOLORDEBUG std::cerr<<"RetinaColor::No or wrong color sampling method, skeeping"<<std::endl; #endif return; break;//.. not useful, yes } // feeling the mosaic buffer: _RGBmosaic=0; for (unsigned int index=0 ; index<_filterOutput.getNBpixels(); ++index) // the RGB _RGBmosaic buffer contains 1 where the pixel corresponds to a sampled color _RGBmosaic[_colorSampling[index]]=1.0; // computing photoreceptors local density _spatiotemporalLPfilter(&_RGBmosaic[0], &_colorLocalDensity[0]); _spatiotemporalLPfilter(&_RGBmosaic[0]+_filterOutput.getNBpixels(), &_colorLocalDensity[0]+_filterOutput.getNBpixels()); _spatiotemporalLPfilter(&_RGBmosaic[0]+_filterOutput.getDoubleNBpixels(), &_colorLocalDensity[0]+_filterOutput.getDoubleNBpixels()); unsigned int maxNBpixels=3*_filterOutput.getNBpixels(); float *colorLocalDensityPTR=&_colorLocalDensity[0]; for (unsigned int i=0;i<maxNBpixels;++i, ++colorLocalDensityPTR) *colorLocalDensityPTR=1.f/ *colorLocalDensityPTR; #ifdef RETINACOLORDEBUG std::cout<<"INIT _colorLocalDensity max, min: "<<_colorLocalDensity.max()<<", "<<_colorLocalDensity.min()<<std::endl; #endif // end of the init step _objectInit=true; } // public functions void RetinaColor::runColorDemultiplexing(const std::valarray<float> &multiplexedColorFrame, const bool adaptiveFiltering, const float maxInputValue) { // demultiplex the grey frame to RGB frame // -> first set demultiplexed frame to 0 _demultiplexedTempBuffer=0; // -> demultiplex process unsigned int *colorSamplingPRT=&_colorSampling[0]; const float *multiplexedColorFramePtr=get_data(multiplexedColorFrame); for (unsigned int indexa=0; indexa<_filterOutput.getNBpixels() ; ++indexa) _demultiplexedTempBuffer[*(colorSamplingPRT++)]=*(multiplexedColorFramePtr++); // interpolate the demultiplexed frame depending on the color sampling method if (!adaptiveFiltering) _interpolateImageDemultiplexedImage(&_demultiplexedTempBuffer[0]); // low pass filtering the demultiplexed frame _spatiotemporalLPfilter(&_demultiplexedTempBuffer[0], &_chrominance[0]); _spatiotemporalLPfilter(&_demultiplexedTempBuffer[0]+_filterOutput.getNBpixels(), &_chrominance[0]+_filterOutput.getNBpixels()); _spatiotemporalLPfilter(&_demultiplexedTempBuffer[0]+_filterOutput.getDoubleNBpixels(), &_chrominance[0]+_filterOutput.getDoubleNBpixels()); /*if (_samplingMethod=BAYER) { _applyRIFfilter(_chrominance, _chrominance); _applyRIFfilter(_chrominance+_filterOutput.getNBpixels(), _chrominance+_filterOutput.getNBpixels()); _applyRIFfilter(_chrominance+_filterOutput.getDoubleNBpixels(), _chrominance+_filterOutput.getDoubleNBpixels()); }*/ // normalize by the photoreceptors local density and retrieve the local luminance float *chrominancePTR= &_chrominance[0]; float *colorLocalDensityPTR= &_colorLocalDensity[0]; float *luminance= &(*_luminance)[0]; if (!adaptiveFiltering)// compute the gradient on the luminance { if (_samplingMethod==RETINA_COLOR_RANDOM) for (unsigned int indexc=0; indexc<_filterOutput.getNBpixels() ; ++indexc, ++chrominancePTR, ++colorLocalDensityPTR, ++luminance) { // normalize by photoreceptors density float Cr=*(chrominancePTR)*_colorLocalDensity[indexc]; float Cg=*(chrominancePTR+_filterOutput.getNBpixels())*_colorLocalDensity[indexc+_filterOutput.getNBpixels()]; float Cb=*(chrominancePTR+_filterOutput.getDoubleNBpixels())*_colorLocalDensity[indexc+_filterOutput.getDoubleNBpixels()]; *luminance=(Cr+Cg+Cb)*_pG; *(chrominancePTR)=Cr-*luminance; *(chrominancePTR+_filterOutput.getNBpixels())=Cg-*luminance; *(chrominancePTR+_filterOutput.getDoubleNBpixels())=Cb-*luminance; } else for (unsigned int indexc=0; indexc<_filterOutput.getNBpixels() ; ++indexc, ++chrominancePTR, ++colorLocalDensityPTR, ++luminance) { float Cr=*(chrominancePTR); float Cg=*(chrominancePTR+_filterOutput.getNBpixels()); float Cb=*(chrominancePTR+_filterOutput.getDoubleNBpixels()); *luminance=_pR*Cr+_pG*Cg+_pB*Cb; *(chrominancePTR)=Cr-*luminance; *(chrominancePTR+_filterOutput.getNBpixels())=Cg-*luminance; *(chrominancePTR+_filterOutput.getDoubleNBpixels())=Cb-*luminance; } // in order to get the color image, each colored map needs to be added the luminance // -> to do so, compute: multiplexedColorFrame - remultiplexed chrominances runColorMultiplexing(_chrominance, _tempMultiplexedFrame); //lum = 1/3((f*(ImR))/(f*mR) + (f*(ImG))/(f*mG) + (f*(ImB))/(f*mB)); float *luminancePTR= &(*_luminance)[0]; chrominancePTR= &_chrominance[0]; float *demultiplexedColorFramePTR= &_demultiplexedColorFrame[0]; for (unsigned int indexp=0; indexp<_filterOutput.getNBpixels() ; ++indexp, ++luminancePTR, ++chrominancePTR, ++demultiplexedColorFramePTR) { *luminancePTR=(multiplexedColorFrame[indexp]-_tempMultiplexedFrame[indexp]); *(demultiplexedColorFramePTR)=*(chrominancePTR)+*luminancePTR; *(demultiplexedColorFramePTR+_filterOutput.getNBpixels())=*(chrominancePTR+_filterOutput.getNBpixels())+*luminancePTR; *(demultiplexedColorFramePTR+_filterOutput.getDoubleNBpixels())=*(chrominancePTR+_filterOutput.getDoubleNBpixels())+*luminancePTR; } }else { const float *multiplexedColorFramePTR= get_data(multiplexedColorFrame); for (unsigned int indexc=0; indexc<_filterOutput.getNBpixels() ; ++indexc, ++chrominancePTR, ++colorLocalDensityPTR, ++luminance, ++multiplexedColorFramePTR) { // normalize by photoreceptors density float Cr=*(chrominancePTR)*_colorLocalDensity[indexc]; float Cg=*(chrominancePTR+_filterOutput.getNBpixels())*_colorLocalDensity[indexc+_filterOutput.getNBpixels()]; float Cb=*(chrominancePTR+_filterOutput.getDoubleNBpixels())*_colorLocalDensity[indexc+_filterOutput.getDoubleNBpixels()]; *luminance=(Cr+Cg+Cb)*_pG; _demultiplexedTempBuffer[_colorSampling[indexc]] = *multiplexedColorFramePTR - *luminance; } // compute the gradient of the luminance #ifdef MAKE_PARALLEL // call the TemplateBuffer TBB clipping method cv::parallel_for_(cv::Range(2,_filterOutput.getNBrows()-2), Parallel_computeGradient(_filterOutput.getNBcolumns(), _filterOutput.getNBrows(), &(*_luminance)[0], &_imageGradient[0])); #else _computeGradient(&(*_luminance)[0]); #endif // adaptively filter the submosaics to get the adaptive densities, here the buffer _chrominance is used as a temp buffer _adaptiveSpatialLPfilter(&_RGBmosaic[0], &_chrominance[0]); _adaptiveSpatialLPfilter(&_RGBmosaic[0]+_filterOutput.getNBpixels(), &_chrominance[0]+_filterOutput.getNBpixels()); _adaptiveSpatialLPfilter(&_RGBmosaic[0]+_filterOutput.getDoubleNBpixels(), &_chrominance[0]+_filterOutput.getDoubleNBpixels()); _adaptiveSpatialLPfilter(&_demultiplexedTempBuffer[0], &_demultiplexedColorFrame[0]); _adaptiveSpatialLPfilter(&_demultiplexedTempBuffer[0]+_filterOutput.getNBpixels(), &_demultiplexedColorFrame[0]+_filterOutput.getNBpixels()); _adaptiveSpatialLPfilter(&_demultiplexedTempBuffer[0]+_filterOutput.getDoubleNBpixels(), &_demultiplexedColorFrame[0]+_filterOutput.getDoubleNBpixels()); /* for (unsigned int index=0; index<_filterOutput.getNBpixels()*3 ; ++index) // cette boucle pourrait �tre supprimee en passant la densit� � la fonction de filtrage _demultiplexedColorFrame[index] /= _chrominance[index];*/ _demultiplexedColorFrame/=_chrominance; // more optimal ;o) // compute and substract the residual luminance for (unsigned int index=0; index<_filterOutput.getNBpixels() ; ++index) { float residu = _pR*_demultiplexedColorFrame[index] + _pG*_demultiplexedColorFrame[index+_filterOutput.getNBpixels()] + _pB*_demultiplexedColorFrame[index+_filterOutput.getDoubleNBpixels()]; _demultiplexedColorFrame[index] = _demultiplexedColorFrame[index] - residu; _demultiplexedColorFrame[index+_filterOutput.getNBpixels()] = _demultiplexedColorFrame[index+_filterOutput.getNBpixels()] - residu; _demultiplexedColorFrame[index+_filterOutput.getDoubleNBpixels()] = _demultiplexedColorFrame[index+_filterOutput.getDoubleNBpixels()] - residu; } // multiplex the obtained chrominance runColorMultiplexing(_demultiplexedColorFrame, _tempMultiplexedFrame); _demultiplexedTempBuffer=0; // get the luminance, et and add it to each chrominance for (unsigned int index=0; index<_filterOutput.getNBpixels() ; ++index) { (*_luminance)[index]=multiplexedColorFrame[index]-_tempMultiplexedFrame[index]; _demultiplexedTempBuffer[_colorSampling[index]] = _demultiplexedColorFrame[_colorSampling[index]];//multiplexedColorFrame[index] - (*_luminance)[index]; } _spatiotemporalLPfilter(&_demultiplexedTempBuffer[0], &_demultiplexedTempBuffer[0]); _spatiotemporalLPfilter(&_demultiplexedTempBuffer[0]+_filterOutput.getNBpixels(), &_demultiplexedTempBuffer[0]+_filterOutput.getNBpixels()); _spatiotemporalLPfilter(&_demultiplexedTempBuffer[0]+_filterOutput.getDoubleNBpixels(), &_demultiplexedTempBuffer[0]+_filterOutput.getDoubleNBpixels()); // get the luminance and add it to each chrominance for (unsigned int index=0; index<_filterOutput.getNBpixels() ; ++index) { _demultiplexedColorFrame[index] = _demultiplexedTempBuffer[index]*_colorLocalDensity[index]+ (*_luminance)[index]; _demultiplexedColorFrame[index+_filterOutput.getNBpixels()] = _demultiplexedTempBuffer[index+_filterOutput.getNBpixels()]*_colorLocalDensity[index+_filterOutput.getNBpixels()]+ (*_luminance)[index]; _demultiplexedColorFrame[index+_filterOutput.getDoubleNBpixels()] = _demultiplexedTempBuffer[index+_filterOutput.getDoubleNBpixels()]*_colorLocalDensity[index+_filterOutput.getDoubleNBpixels()]+ (*_luminance)[index]; } } // eliminate saturated colors by simple clipping values to the input range clipRGBOutput_0_maxInputValue(NULL, maxInputValue); /* transfert image gradient in order to check validity memcpy((*_luminance), _imageGradient, sizeof(float)*_filterOutput.getNBpixels()); memcpy(_demultiplexedColorFrame, _imageGradient+_filterOutput.getNBpixels(), sizeof(float)*_filterOutput.getNBpixels()); memcpy(_demultiplexedColorFrame+_filterOutput.getNBpixels(), _imageGradient+_filterOutput.getNBpixels(), sizeof(float)*_filterOutput.getNBpixels()); memcpy(_demultiplexedColorFrame+2*_filterOutput.getNBpixels(), _imageGradient+_filterOutput.getNBpixels(), sizeof(float)*_filterOutput.getNBpixels()); */ if (_saturateColors) { TemplateBuffer<float>::normalizeGrayOutputCentredSigmoide(128, _colorSaturationValue, maxInputValue, &_demultiplexedColorFrame[0], &_demultiplexedColorFrame[0], _filterOutput.getNBpixels()); TemplateBuffer<float>::normalizeGrayOutputCentredSigmoide(128, _colorSaturationValue, maxInputValue, &_demultiplexedColorFrame[0]+_filterOutput.getNBpixels(), &_demultiplexedColorFrame[0]+_filterOutput.getNBpixels(), _filterOutput.getNBpixels()); TemplateBuffer<float>::normalizeGrayOutputCentredSigmoide(128, _colorSaturationValue, maxInputValue, &_demultiplexedColorFrame[0]+_filterOutput.getNBpixels()*2, &_demultiplexedColorFrame[0]+_filterOutput.getNBpixels()*2, _filterOutput.getNBpixels()); } } // color multiplexing: input frame size=_NBrows*_filterOutput.getNBcolumns()*3, multiplexedFrame output size=_NBrows*_filterOutput.getNBcolumns() void RetinaColor::runColorMultiplexing(const std::valarray<float> &demultiplexedInputFrame, std::valarray<float> &multiplexedFrame) { // multiply each color layer by its bayer mask unsigned int *colorSamplingPTR= &_colorSampling[0]; float *multiplexedFramePTR= &multiplexedFrame[0]; for (unsigned int indexp=0; indexp<_filterOutput.getNBpixels(); ++indexp) *(multiplexedFramePTR++)=demultiplexedInputFrame[*(colorSamplingPTR++)]; } void RetinaColor::normalizeRGBOutput_0_maxOutputValue(const float maxOutputValue) { //normalizeGrayOutputCentredSigmoide(0.0, 2, _chrominance); TemplateBuffer<float>::normalizeGrayOutput_0_maxOutputValue(&_demultiplexedColorFrame[0], 3*_filterOutput.getNBpixels(), maxOutputValue); //normalizeGrayOutputCentredSigmoide(0.0, 2, _chrominance+_filterOutput.getNBpixels()); //normalizeGrayOutput_0_maxOutputValue(_demultiplexedColorFrame+_filterOutput.getNBpixels(), _filterOutput.getNBpixels(), maxOutputValue); //normalizeGrayOutputCentredSigmoide(0.0, 2, _chrominance+2*_filterOutput.getNBpixels()); //normalizeGrayOutput_0_maxOutputValue(_demultiplexedColorFrame+_filterOutput.getDoubleNBpixels(), _filterOutput.getNBpixels(), maxOutputValue); TemplateBuffer<float>::normalizeGrayOutput_0_maxOutputValue(&(*_luminance)[0], _filterOutput.getNBpixels(), maxOutputValue); } /// normalize output between 0 and maxOutputValue; void RetinaColor::clipRGBOutput_0_maxInputValue(float *inputOutputBuffer, const float maxInputValue) { //std::cout<<"RetinaColor::normalizing RGB frame..."<<std::endl; // if outputBuffer unsassigned, the rewrite the buffer if (inputOutputBuffer==NULL) inputOutputBuffer= &_demultiplexedColorFrame[0]; #ifdef MAKE_PARALLEL // call the TemplateBuffer TBB clipping method cv::parallel_for_(cv::Range(0,_filterOutput.getNBpixels()*3), Parallel_clipBufferValues<float>(inputOutputBuffer, 0, maxInputValue)); #else float *inputOutputBufferPTR=inputOutputBuffer; for (unsigned int jf = 0; jf < _filterOutput.getNBpixels()*3; ++jf, ++inputOutputBufferPTR) { if (*inputOutputBufferPTR>maxInputValue) *inputOutputBufferPTR=maxInputValue; else if (*inputOutputBufferPTR<0) *inputOutputBufferPTR=0; } #endif //std::cout<<"RetinaColor::...normalizing RGB frame OK"<<std::endl; } void RetinaColor::_interpolateImageDemultiplexedImage(float *inputOutputBuffer) { switch(_samplingMethod) { case RETINA_COLOR_RANDOM: return; // no need to interpolate break; case RETINA_COLOR_DIAGONAL: _interpolateSingleChannelImage111(inputOutputBuffer); break; case RETINA_COLOR_BAYER: // default sets bayer sampling _interpolateBayerRGBchannels(inputOutputBuffer); break; default: std::cerr<<"RetinaColor::No or wrong color sampling method, skeeping"<<std::endl; return; break;//.. not useful, yes } } void RetinaColor::_interpolateSingleChannelImage111(float *inputOutputBuffer) { for (unsigned int indexr=0 ; indexr<_filterOutput.getNBrows(); ++indexr) { for (unsigned int indexc=1 ; indexc<_filterOutput.getNBcolumns()-1; ++indexc) { unsigned int index=indexc+indexr*_filterOutput.getNBcolumns(); inputOutputBuffer[index]=(inputOutputBuffer[index-1]+inputOutputBuffer[index]+inputOutputBuffer[index+1])/3.f; } } for (unsigned int indexc=0 ; indexc<_filterOutput.getNBcolumns(); ++indexc) { for (unsigned int indexr=1 ; indexr<_filterOutput.getNBrows()-1; ++indexr) { unsigned int index=indexc+indexr*_filterOutput.getNBcolumns(); inputOutputBuffer[index]=(inputOutputBuffer[index-_filterOutput.getNBcolumns()]+inputOutputBuffer[index]+inputOutputBuffer[index+_filterOutput.getNBcolumns()])/3.f; } } } void RetinaColor::_interpolateBayerRGBchannels(float *inputOutputBuffer) { for (unsigned int indexr=0 ; indexr<_filterOutput.getNBrows()-1; indexr+=2) { for (unsigned int indexc=1 ; indexc<_filterOutput.getNBcolumns()-1; indexc+=2) { unsigned int indexR=indexc+indexr*_filterOutput.getNBcolumns(); unsigned int indexB=_filterOutput.getDoubleNBpixels()+indexc+1+(indexr+1)*_filterOutput.getNBcolumns(); inputOutputBuffer[indexR]=(inputOutputBuffer[indexR-1]+inputOutputBuffer[indexR+1])/2.f; inputOutputBuffer[indexB]=(inputOutputBuffer[indexB-1]+inputOutputBuffer[indexB+1])/2.f; } } for (unsigned int indexr=1 ; indexr<_filterOutput.getNBrows()-1; indexr+=2) { for (unsigned int indexc=0 ; indexc<_filterOutput.getNBcolumns(); ++indexc) { unsigned int indexR=indexc+indexr*_filterOutput.getNBcolumns(); unsigned int indexB=_filterOutput.getDoubleNBpixels()+indexc+1+(indexr+1)*_filterOutput.getNBcolumns(); inputOutputBuffer[indexR]=(inputOutputBuffer[indexR-_filterOutput.getNBcolumns()]+inputOutputBuffer[indexR+_filterOutput.getNBcolumns()])/2.f; inputOutputBuffer[indexB]=(inputOutputBuffer[indexB-_filterOutput.getNBcolumns()]+inputOutputBuffer[indexB+_filterOutput.getNBcolumns()])/2.f; } } for (unsigned int indexr=1 ; indexr<_filterOutput.getNBrows()-1; ++indexr) for (unsigned int indexc=0 ; indexc<_filterOutput.getNBcolumns(); indexc+=2) { unsigned int indexG=_filterOutput.getNBpixels()+indexc+(indexr)*_filterOutput.getNBcolumns()+indexr%2; inputOutputBuffer[indexG]=(inputOutputBuffer[indexG-1]+inputOutputBuffer[indexG+1]+inputOutputBuffer[indexG-_filterOutput.getNBcolumns()]+inputOutputBuffer[indexG+_filterOutput.getNBcolumns()])*0.25f; } } void RetinaColor::_applyRIFfilter(const float *sourceBuffer, float *destinationBuffer) { for (unsigned int indexr=1 ; indexr<_filterOutput.getNBrows()-1; ++indexr) { for (unsigned int indexc=1 ; indexc<_filterOutput.getNBcolumns()-1; ++indexc) { unsigned int index=indexc+indexr*_filterOutput.getNBcolumns(); _tempMultiplexedFrame[index]=(4.f*sourceBuffer[index]+sourceBuffer[index-1-_filterOutput.getNBcolumns()]+sourceBuffer[index-1+_filterOutput.getNBcolumns()]+sourceBuffer[index+1-_filterOutput.getNBcolumns()]+sourceBuffer[index+1+_filterOutput.getNBcolumns()])*0.125f; } } memcpy(destinationBuffer, &_tempMultiplexedFrame[0], sizeof(float)*_filterOutput.getNBpixels()); } void RetinaColor::_getNormalizedContoursImage(const float *inputFrame, float *outputFrame) { float maxValue=0.f; float normalisationFactor=1.f/3.f; for (unsigned int indexr=1 ; indexr<_filterOutput.getNBrows()-1; ++indexr) { for (unsigned int indexc=1 ; indexc<_filterOutput.getNBcolumns()-1; ++indexc) { unsigned int index=indexc+indexr*_filterOutput.getNBcolumns(); outputFrame[index]=normalisationFactor*fabs(8.f*inputFrame[index]-inputFrame[index-1]-inputFrame[index+1]-inputFrame[index-_filterOutput.getNBcolumns()]-inputFrame[index+_filterOutput.getNBcolumns()]-inputFrame[index-1-_filterOutput.getNBcolumns()]-inputFrame[index-1+_filterOutput.getNBcolumns()]-inputFrame[index+1-_filterOutput.getNBcolumns()]-inputFrame[index+1+_filterOutput.getNBcolumns()]); if (outputFrame[index]>maxValue) maxValue=outputFrame[index]; } } normalisationFactor=1.f/maxValue; // normalisation [0, 1] for (unsigned int indexp=1 ; indexp<_filterOutput.getNBrows()-1; ++indexp) outputFrame[indexp]=outputFrame[indexp]*normalisationFactor; } ////////////////////////////////////////////////////////// // ADAPTIVE BASIC RETINA FILTER ////////////////////////////////////////////////////////// // run LP filter for a new frame input and save result at a specific output adress void RetinaColor::_adaptiveSpatialLPfilter(const float *inputFrame, float *outputFrame) { /**********/ _gain = (1-0.57f)*(1-0.57f)*(1-0.06f)*(1-0.06f); // launch the serie of 1D directional filters in order to compute the 2D low pass filter // -> horizontal filters work with the first layer of imageGradient _adaptiveHorizontalCausalFilter_addInput(inputFrame, outputFrame, 0, _filterOutput.getNBrows()); _horizontalAnticausalFilter_Irregular(outputFrame, 0, _filterOutput.getNBrows(), &_imageGradient[0]); // -> horizontal filters work with the second layer of imageGradient _verticalCausalFilter_Irregular(outputFrame, 0, _filterOutput.getNBcolumns(), &_imageGradient[0]+_filterOutput.getNBpixels()); _adaptiveVerticalAnticausalFilter_multGain(outputFrame, 0, _filterOutput.getNBcolumns()); } // horizontal causal filter which adds the input inside... replaces the parent _horizontalCausalFilter_Irregular_addInput by avoiding a product for each pixel void RetinaColor::_adaptiveHorizontalCausalFilter_addInput(const float *inputFrame, float *outputFrame, unsigned int IDrowStart, unsigned int IDrowEnd) { #ifdef MAKE_PARALLEL cv::parallel_for_(cv::Range(IDrowStart,IDrowEnd), Parallel_adaptiveHorizontalCausalFilter_addInput(inputFrame, outputFrame, &_imageGradient[0], _filterOutput.getNBcolumns())); #else float* outputPTR=outputFrame+IDrowStart*_filterOutput.getNBcolumns(); const float* inputPTR=inputFrame+IDrowStart*_filterOutput.getNBcolumns(); const float *imageGradientPTR= &_imageGradient[0]+IDrowStart*_filterOutput.getNBcolumns(); for (unsigned int IDrow=IDrowStart; IDrow<IDrowEnd; ++IDrow) { float result=0; for (unsigned int index=0; index<_filterOutput.getNBcolumns(); ++index) { //std::cout<<(*imageGradientPTR)<<" "; result = *(inputPTR++) + (*imageGradientPTR)* result; *(outputPTR++) = result; ++imageGradientPTR; } // std::cout<<" "<<std::endl; } #endif } // vertical anticausal filter which multiplies the output by _gain... replaces the parent _verticalAnticausalFilter_multGain by avoiding a product for each pixel and taking into account the second layer of the _imageGradient buffer void RetinaColor::_adaptiveVerticalAnticausalFilter_multGain(float *outputFrame, unsigned int IDcolumnStart, unsigned int IDcolumnEnd) { #ifdef MAKE_PARALLEL cv::parallel_for_(cv::Range(IDcolumnStart,IDcolumnEnd), Parallel_adaptiveVerticalAnticausalFilter_multGain(outputFrame, &_imageGradient[0]+_filterOutput.getNBpixels(), _filterOutput.getNBrows(), _filterOutput.getNBcolumns(), _gain)); #else float* outputOffset=outputFrame+_filterOutput.getNBpixels()-_filterOutput.getNBcolumns(); float* gradOffset= &_imageGradient[0]+_filterOutput.getNBpixels()*2-_filterOutput.getNBcolumns(); for (unsigned int IDcolumn=IDcolumnStart; IDcolumn<IDcolumnEnd; ++IDcolumn) { float result=0; float *outputPTR=outputOffset+IDcolumn; float *imageGradientPTR=gradOffset+IDcolumn; for (unsigned int index=0; index<_filterOutput.getNBrows(); ++index) { result = *(outputPTR) + (*(imageGradientPTR)) * result; *(outputPTR) = _gain*result; outputPTR-=_filterOutput.getNBcolumns(); imageGradientPTR-=_filterOutput.getNBcolumns(); } } #endif } /////////////////////////// void RetinaColor::_computeGradient(const float *luminance) { for (unsigned int idLine=2;idLine<_filterOutput.getNBrows()-2;++idLine) { for (unsigned int idColumn=2;idColumn<_filterOutput.getNBcolumns()-2;++idColumn) { const unsigned int pixelIndex=idColumn+_filterOutput.getNBcolumns()*idLine; // horizontal and vertical local gradients const float verticalGrad=fabs(luminance[pixelIndex+_filterOutput.getNBcolumns()]-luminance[pixelIndex-_filterOutput.getNBcolumns()]); const float horizontalGrad=fabs(luminance[pixelIndex+1]-luminance[pixelIndex-1]); // neighborhood horizontal and vertical gradients const float verticalGrad_p=fabs(luminance[pixelIndex]-luminance[pixelIndex-2*_filterOutput.getNBcolumns()]); const float horizontalGrad_p=fabs(luminance[pixelIndex]-luminance[pixelIndex-2]); const float verticalGrad_n=fabs(luminance[pixelIndex+2*_filterOutput.getNBcolumns()]-luminance[pixelIndex]); const float horizontalGrad_n=fabs(luminance[pixelIndex+2]-luminance[pixelIndex]); const float horizontalGradient=0.5f*horizontalGrad+0.25f*(horizontalGrad_p+horizontalGrad_n); const float verticalGradient=0.5f*verticalGrad+0.25f*(verticalGrad_p+verticalGrad_n); // compare local gradient means and fill the appropriate filtering coefficient value that will be used in adaptative filters if (horizontalGradient<verticalGradient) { _imageGradient[pixelIndex+_filterOutput.getNBpixels()]=0.06f; _imageGradient[pixelIndex]=0.57f; } else { _imageGradient[pixelIndex+_filterOutput.getNBpixels()]=0.57f; _imageGradient[pixelIndex]=0.06f; } } } } bool RetinaColor::applyKrauskopfLMS2Acr1cr2Transform(std::valarray<float> &result) { bool processSuccess=true; // basic preliminary error check if (result.size()!=_demultiplexedColorFrame.size()) { std::cerr<<"RetinaColor::applyKrauskopfLMS2Acr1cr2Transform: input buffer does not match retina buffer size, conversion aborted"<<std::endl; return false; } // apply transformation _applyImageColorSpaceConversion(_demultiplexedColorFrame, result, _LMStoACr1Cr2); return processSuccess; } bool RetinaColor::applyLMS2LabTransform(std::valarray<float> &result) { bool processSuccess=true; // basic preliminary error check if (result.size()!=_demultiplexedColorFrame.size()) { std::cerr<<"RetinaColor::applyKrauskopfLMS2Acr1cr2Transform: input buffer does not match retina buffer size, conversion aborted"<<std::endl; return false; } // apply transformation _applyImageColorSpaceConversion(_demultiplexedColorFrame, result, _LMStoLab); return processSuccess; } // template function able to perform a custom color space transformation void RetinaColor::_applyImageColorSpaceConversion(const std::valarray<float> &inputFrameBuffer, std::valarray<float> &outputFrameBuffer, const float *transformTable) { // two step methods in order to allow inputFrame and outputFrame to be the same unsigned int nbPixels=(unsigned int)(inputFrameBuffer.size()/3), dbpixels=(unsigned int)(2*inputFrameBuffer.size()/3); const float *inputFrame=get_data(inputFrameBuffer); float *outputFrame= &outputFrameBuffer[0]; for (unsigned int dataIndex=0; dataIndex<nbPixels;++dataIndex, ++outputFrame, ++inputFrame) { // first step, compute each new values float layer1 = *(inputFrame)**(transformTable+0) +*(inputFrame+nbPixels)**(transformTable+1) +*(inputFrame+dbpixels)**(transformTable+2); float layer2 = *(inputFrame)**(transformTable+3) +*(inputFrame+nbPixels)**(transformTable+4) +*(inputFrame+dbpixels)**(transformTable+5); float layer3 = *(inputFrame)**(transformTable+6) +*(inputFrame+nbPixels)**(transformTable+7) +*(inputFrame+dbpixels)**(transformTable+8); // second, affect the output *(outputFrame) = layer1; *(outputFrame+nbPixels) = layer2; *(outputFrame+dbpixels) = layer3; } } }// end of namespace bioinspired }// end of namespace cv