25 #include "ConstantRegionDetector.hh"
26 #include <Base/Image/ImageIO.hh>
27 #include <Filter/Median.hh>
39 template<
class StorageType,
class CalculationType>
41 threshold_ = (CalculationType)1;
48 template<
class StorageType,
class CalculationType>
69 bool checkMask =
false;
70 cout <<
"mask? " << maskImg_.
GetWidth() <<
" " << maskImg_.GetHeight() << endl;
71 if(maskImg_.GetWidth() == src.
GetWidth() && maskImg_.GetHeight() == src.
GetHeight()){
76 unsigned char** maskData = maskImg_.GetImageDataArray();
80 for (
int i = halfWinSize_; i < (imgWidth - halfWinSize_); i++) {
81 for (
int j = halfWinSize_; j < (imgHeight - halfWinSize_); j++) {
84 if(checkMask && (maskData[j][i] > (
unsigned char)0)){
88 CalculationType sqrDiffR = 0;
89 CalculationType sqrDiffG = 0;
90 CalculationType sqrDiffB = 0;
91 for (
int ii = -halfWinSize_; ii <= halfWinSize_; ii++) {
92 for (
int jj = -halfWinSize_; jj <= halfWinSize_; jj++) {
93 sqrDiffR = sqrDiffR + (CalculationType) pow((
float) imageData[j][i*3+0]
94 - (float) imageData[j+jj][(i+ii)*3+0], 2.0f);
95 sqrDiffG = sqrDiffG + (CalculationType) pow((
float) imageData[j][i*3+1]
96 - (float) imageData[j+jj][(i+ii)*3+1], 2.0f);
97 sqrDiffB = sqrDiffB + (CalculationType) pow((
float) imageData[j][i*3+2]
98 - (float) imageData[j+jj][(i+ii)*3+2], 2.0f);
101 float numMeasurements = (halfWinSize_ * 2.0f + 1.0f) * (halfWinSize_ * 2.0f + 1.0f) * 3.0f;
102 sqrDiffR = CalculationType((
float)sqrDiffR / numMeasurements);
103 sqrDiffG = CalculationType((
float)sqrDiffG / numMeasurements);
104 sqrDiffB = CalculationType((
float)sqrDiffB / numMeasurements);
106 CalculationType qual = sqrDiffR + sqrDiffG + sqrDiffB;
108 if (qual < threshold_) {
114 featureList_.push_back(feature);
116 colors.push_back(
Vector3<StorageType> (imageData[j][i*3+0], imageData[j][i*3+1], imageData[j][i*3+2]));
124 if(minDistance_ != -1){
125 sort(featureList_.begin(), featureList_.end());
129 unsigned char** regionMapData = regionMap.GetImageDataArray();
131 unsigned int numRegions = featureList_.size();
133 int xcoor, ycoor, winCoorX, winCoorY;
137 vector<ColFeat<StorageType> > tempList;
139 for(
unsigned int i=0; i < numRegions; i++){
140 xcoor = featureList_[i].x;
141 ycoor = featureList_[i].y;
142 if(regionMapData[ycoor][xcoor]==(
unsigned char)0){
143 for(
int xx = -minDistance_; xx <= minDistance_; xx++){
144 for(
int yy=-minDistance_; yy <= minDistance_; yy++){
145 winCoorX = xcoor + xx;
146 winCoorY = ycoor + yy;
147 if(winCoorX >= 0 && winCoorX < imgWidth && winCoorY >= 0 && winCoorY < imgHeight){
148 regionMapData[winCoorY][winCoorX] = (
unsigned char)1;
153 tempList.push_back(featureList_[i]);
154 points2d.push_back(
HomgPoint2D(xcoor, ycoor, 1.0));
155 colors.push_back(
Vector3<StorageType>(imageData[ycoor][xcoor*3+0], imageData[ycoor][xcoor*3+1], imageData[ycoor][xcoor*3+2]));
160 featureList_ = tempList;
165 if(maxNumFeatures_ != -1){
166 sort(featureList_.begin(), featureList_.end());
171 for(
int i = 0; i < maxNumFeatures_; i++){
172 featureTmp = featureList_.back();
173 featureList_.pop_back();
174 points2d.push_back(
HomgPoint2D(featureTmp.
x, featureTmp.
y, 1.0));
175 colors.push_back(featureTmp.
col);
197 #ifdef BUILD_IMAGE_INT
200 #ifdef BUILD_IMAGE_CHAR
203 #ifdef BUILD_IMAGE_SHORT
205 #ifdef BUILD_IMAGE_USHORT
207 #ifdef BUILD_IMAGE_INT
211 #ifdef BUILD_IMAGE_UINT
213 #ifdef BUILD_IMAGE_DOUBLE
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
unsigned int GetWidth() const
unsigned int GetHeight() const
detects regions with close to zero gradients in images, works on color images only ...
internal class for feature (with color) passing only
BIAS::Vector3< StorageType > col
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase