MCPcopy Create free account
hub / github.com/cpvrlab/ImagePlay / processInputData

Method processInputData

IPL/src/processes/IPLMorphologyBinary.cpp:155–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153
154
155bool IPLMorphologyBinary::processInputData(IPLData* data, int, bool useOpenCV)
156{
157 IPLImage* image = data->toImage();
158
159 // delete previous result
160 delete _result;
161 _result = NULL;
162
163 int width = image->width();
164 int height = image->height();
165
166 // get properties
167 _kernel = getProcessPropertyVectorInt("kernel");
168 _iterations = getProcessPropertyInt("iterations");
169 _operation = getProcessPropertyInt("operation");
170
171 if (std::accumulate(_kernel.begin(),_kernel.end(),0) == 0)
172 {
173 //Add an empty image - The image viewer currently may trigger
174 //a segfault if we return NULL.
175 _result = new IPLImage( IPL_IMAGE_BW, width, height);
176 addError("Empty kernel.");
177 return false;
178 }
179
180 // TODO: implement manhattan distance threshold instead of stupid iterations...
181 // TODO: implement border interpolation properties
182
183 enum Operation
184 {
185 DILATE = 0,
186 ERODE,
187 OPEN,
188 CLOSE
189 };
190
191 if (!useOpenCV)
192 {
193 _result = new IPLImage( IPL_IMAGE_BW, width, height);
194
195 //std::vector<bool> packs its elements bitwise into a vector of
196 //bytes. The kernel therefore uses much less cpu cache this way.
197 std::vector<bool> kernel;
198 kernel.reserve(_kernel.size());
199 for (auto &i: _kernel) kernel.push_back(i > 0);
200
201 std::atomic<int> progress(0);
202 int totalLines = image->height()*_iterations;
203 auto updateProgress = [&]() {
204 notifyProgressEventHandler(100*((float)++progress)/totalLines);
205 };
206
207 switch(_operation)
208 {
209 case DILATE:
210 dilate(*image->plane(0),*_result->plane(0),_iterations,kernel,updateProgress);
211 break;
212 case ERODE:

Callers

nothing calls this directly

Calls 13

dilateFunction · 0.85
erodeFunction · 0.85
openFunction · 0.85
closeFunction · 0.85
toImageMethod · 0.80
widthMethod · 0.80
heightMethod · 0.80
planeMethod · 0.80
toCvMatMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected