| 153 | |
| 154 | |
| 155 | bool 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: |
nothing calls this directly
no test coverage detected