~charon-developers/charon-utils/trunk

« back to all changes in this revision

Viewing changes to include/charon-utils/BlurByDepth.hxx

  • Committer: moritz-e-becker
  • Date: 2014-06-04 14:21:31 UTC
  • Revision ID: moritz.becker@iwr.uni-heidelberg.de-20140604142131-fvc6un8f9193r51m
Extended annotation class

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
                blurred, "blurred",
51
51
                "Blurred images",
52
52
                "CImgList<T>");
53
 
        
 
53
 
 
54
        ParameteredObject::_addParameter< bool >(
 
55
                blurQuadratic, "blurQuadratic",
 
56
                "Quadratic scheme. Near pixels are blurred stronger by quadratic weight.",
 
57
                false, "bool");
54
58
        ParameteredObject::_addParameter< float >(
55
59
                depthNear, "depthNear",
56
60
                "depth to start blur with blurNear",
71
75
                stereo, "stereo",
72
76
                "Assume two images per depth map",
73
77
                false, "bool");
 
78
        ParameteredObject::_addParameter< bool >(
 
79
                useMaxMinValues, "useMaxMinValues",
 
80
                "Use given max and min values for all frames",
 
81
                false, "bool");
 
82
        ParameteredObject::_addParameter< float >(
 
83
                maxValue, "maxValue",
 
84
                "Maxmimum value of all images",
 
85
                255, "float");
 
86
        ParameteredObject::_addParameter< float >(
 
87
                minValue, "minValue",
 
88
                "Minimum value of all images",
 
89
                0, "float");
74
90
 
75
91
}
76
92
 
97
113
        if( img.size() != 2*dm.size() && this->stereo() )
98
114
                throw( std::range_error("BlurByDepth<T>::execute: STEREO-MODE: depthmaps.size != 2* images.size") );
99
115
 
 
116
        float maxVal = 0;
 
117
 
100
118
        for( int i = 0; i < img.size(); i++ ){
101
119
 
102
120
                sout << "Image " << i << ":" << std::endl;
103
121
 
104
122
                // In this code, taller values of depth maps mean nearer pixels!
105
 
                float depthMax = dm[i].max() * this->depthNear() ;      
106
 
                float depthMin = dm[i].min() + this->depthFar() *dm[i].max();
 
123
 
 
124
                float depthMax = dm[i].max() ;  
 
125
                float depthMin = dm[i].min() ;
 
126
 
 
127
                if( this->useMaxMinValues() ){
 
128
 
 
129
                        maxVal = std::max( maxVal, depthMax );
 
130
                        
 
131
                        sout << "Replace max value of image (" << depthMax << ") by " << this->maxValue() << std::endl;
 
132
                        sout << "Replace min value of image (" << depthMin << ") by " << this->minValue() << std::endl;
 
133
 
 
134
                        depthMax = this->maxValue();
 
135
                        depthMin = this->minValue();
 
136
 
 
137
                }
 
138
 
 
139
                depthMax *= this->depthNear() ; 
 
140
                depthMin += this->depthFar() * depthMax;
107
141
                float depthRange = depthMax - depthMin ;
 
142
 
 
143
                sout << "Near value: " << depthMax << " / far value: " << depthMin << std::endl;
108
144
                                
109
145
                cimg_library::CImg<T> blur = img[i];
110
146
                blur.fill(255);
115
151
                for( int c = 0; c < spectrum; c++ ){
116
152
                        for( int y = 0; y < h; y++ ){
117
153
 
118
 
                                if( y%33 == 0 )
 
154
                                if( y%(h/3) == 0 )
119
155
                                        sout << "\tprogress: " << int(float(y)/float(h)*100.) << "%" << std::endl;
120
156
 
121
157
                                #pragma omp parallel for
126
162
                                        float sigma = blurNear;
127
163
                                        if( dm[i](x,y,0,0) != 0 ){
128
164
                                                float c1 = 1 - ( pDepth - depthMin ) / depthRange ;     // choose sigma for blur
 
165
                                                if( this->blurQuadratic() ) 
 
166
                                                        c1 *= c1;
129
167
                                                sigma = blurNear + c1 * blurRange ;
130
168
                                        }
131
169
                                
185
223
                        }
186
224
                }
187
225
 
 
226
                sout << std::endl;
 
227
 
188
228
                this->blurred().push_back( blur );
189
229
 
190
230
        }
191
231
 
 
232
        sout << "--------------------" << std::endl;
 
233
        sout << "Maximal value of all images: " << maxVal << std::endl << std::endl;
 
234
 
192
235
}
193
236
 
194
237
#endif /* _BLURBYDEPTH_HXX_ */