31 #ifndef DISTANCETRANSFORMFILLOP_H_
32 #define DISTANCETRANSFORMFILLOP_H_
34 #include <drain/image/ImageFile.h>
35 #include <drain/util/Fuzzy.h>
36 #include "FunctorOp.h"
37 #include "DistanceTransformOp.h"
71 dstConf.setGeometry(srcConf.getGeometry());
72 if (!dstConf.hasAlphaChannel())
73 dstConf.setAlphaChannelCount(1);
83 mout.debug3(
"src: ", src);
92 if (!dstConf.hasAlphaChannel())
93 dstConf.setAlphaChannelCount(1);
98 mout.
debug(
"clearing alpha (use traverseChannel(s) to avoid)" );
101 dst.getAlphaChannel().
fill(0);
103 mout.debug3(
"dst: ", dst);
125 DistanceTransformFillOp(
const std::string &name,
const std::string &description, dist_t horz = 14.0, dist_t vert = DistanceModel::nan_f,
126 DistanceModel::topol_t topology=DistanceModel::KNIGHT) :
127 DistanceTransformOp<T>(name, description, horz, vert, topology), alphaThreshold(0.0, 0.0) {
128 this->parameters.link(
"alphaThreshold", alphaThreshold.tuple(),
"0..1").fillArray =
true;
154 mout.
debug(
"start: ", *
this );
156 if (!src.hasAlpha()){
157 mout.
warn(
"src: ", src );
158 mout.
error(
"required alpha channel missing in src" );
162 mout.
debug2(
"src: ", src );
164 if (!dst.hasAlpha()){
165 mout.
warn(
"dst: ", dst );
166 mout.
error(
"required alpha channel missing in dst" );
170 mout.
debug2(
"dst: ", dst );
174 mout.debug3(
"init params, using alpha: " );
182 mout.
debug(
"calling traverseDownRight" );
185 traverseDownRight(src, dst);
193 mout.
debug(
"calling traverseUpLeft" );
195 traverseUpLeft(dst, dst);
202 if (alphaThreshold.max > 0.0){
204 Channel & dstAlpha = dst.alpha.get();
207 threshold.functor.set(alphaThreshold);
208 mout.
debug(
"Thresholding: ", threshold.functor );
225 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
227 mout.
debug(
"distModel: ", this->distanceModel );
229 DistanceNeighbourhood chain;
230 this->distanceModel.createChain(chain,
true);
232 mout.
debug2(
"neighbourHood ", drain::sprinter(chain) );
238 mout.
debug(
"coordHandler ", coordinateHandler );
240 mout.debug3(
"src alpha:", srcAlpha );
241 mout.debug3(
"dst alpha:", dstAlpha );
253 const size_t K = std::min(srcTray.size(), dstTray.size());
255 const Range<int> & xRange = coordinateHandler.getXRange();
256 const Range<int> & yRange = coordinateHandler.getYRange();
259 size_t addressWin = 0;
261 mout.
debug(
"main loop, K=", K );
262 for (p.y=0; p.y<=yRange.max; ++p.y){
263 for (p.x=0; p.x<=xRange.max; ++p.x){
265 address = dstAlpha.
address(p.x, p.y);
268 dWin = srcAlpha.
get<dist_t>(address);
272 pTest.setLocation(p.x + elem.diff.x, p.y + elem.diff.y);
273 coordinateHandler.
handle(pTest);
274 dTest = this->distanceModel.decrease(dstAlpha.
get<dist_t>(pTest), elem.coeff);
285 dstAlpha.
put(address, dWin);
287 addressWin = dstAlpha.
address(pWin.x, pWin.y);
289 if (addressWin != address){
290 for (
size_t k=0; k<K; ++k)
291 dstTray.
get(k).put(address, dstTray.
get(k).get<dist_t>(addressWin));
294 for (
size_t k=0; k<K; ++k)
295 dstTray.
get(k).put(address, srcTray.
get(k).get<dist_t>(address));
323 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
324 mout.
debug(
"start" );
326 mout.
debug2(
"this->distanceModel", this->distanceModel );
328 DistanceNeighbourhood chain;
329 this->distanceModel.createChain(chain,
false);
350 const size_t K = std::min(srcTray.size(), dstTray.size());
352 const Range<int> & xRange = coordinateHandler.getXRange();
353 const Range<int> & yRange = coordinateHandler.getYRange();
355 mout.
debug(
"main loop, K=", K);
357 for (p.y=yRange.max; p.y>=0; --p.y){
358 for (p.x=xRange.max; p.x>=0; --p.x){
360 address = dstAlpha.
address(p.x, p.y);
362 dWin = srcAlpha.
get<dist_t>(address);
366 pTest.setLocation(p.x + elem.diff.x, p.y + elem.diff.y);
367 coordinateHandler.
handle(pTest);
368 dTest = this->distanceModel.decrease(dstAlpha.
get<dist_t>(pTest), elem.coeff);
379 dstAlpha.
put(address, dWin);
381 addressWin = dstAlpha.
address(pWin.x, pWin.y);
383 if (addressWin != address){
384 for (
size_t k=0; k<K; ++k)
385 dstTray.
get(k).put(address, dstTray.
get(k).get<dist_t>(addressWin));
388 for (
size_t k=0; k<K; ++k)
389 dstTray.
get(k).put(address, srcTray.
get(k).get<dist_t>(address));
454 DistanceModel::topol_t topology=DistanceModel::KNIGHT) :
456 horz, vert, topology) {
509 DistanceModel::topol_t topology=DistanceModel::KNIGHT) :
511 horz, vert, topology) {
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & error(const TT &... args)
Echoes.
Definition: Log.h:412
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:426
Logger & debug(const TT &... args)
Public, yet typically used "internally", when TIMING=true.
Definition: Log.h:676
Logger & debug2(const TT &... args)
Debug information.
Definition: Log.h:686
Image with static geometry.
Definition: ImageChannel.h:60
Definition: CoordinateHandler.h:62
virtual coord_overflow_t handle(int &x, int &y) const
Ensures the validity of the coordinates. If inside limits, arguments (x,y) remain intact and 0 is ret...
Definition: CoordinateHandler.h:190
Definition: DistanceModel.h:76
bool typeIsSet() const
Get the storage type.
Definition: ImageConf.h:116
const std::type_info & getType() const
Linear scaling.
Definition: ImageConf.h:110
void setType(const std::type_info &t)
Set storage type.
Definition: ImageConf.h:121
Struct for image (excluding data)
Definition: ImageConf.h:333
void setCoordinatePolicy(const T &policy)
Does not set any CoordinateHandler object.
Definition: ImageConf.h:368
void put(size_t i, T x)
Sets the intensity in location i to x. See \address.
Definition: ImageFrame.h:192
size_t address(size_t i) const
Computes the index location from image coordinates. Does not involve bit resolution.
Definition: ImageFrame.h:148
T get(size_t i) const
Gets the intensity at location i. See address().
Definition: ImageFrame.h:254
void fill(T x)
Sets the intensities to given value. Does not change image geometry.
Definition: ImageFrame.h:330
Container applicable for Channels and Images, with alpha support.
Definition: ImageTray.h:267
void setChannels(T2 &img)
Splits.
Definition: ImageTray.h:402
void setAlphaChannels(T2 &img)
Splits.
Definition: ImageTray.h:434
const image_t & getAlpha(size_t i=0) const
Returns the i'th alpha image.
Definition: ImageTray.h:329
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition: Image.h:184
const image_t & get(size_t i=0) const
Returns the i'th image.
Definition: ImageTray.h:81
Class for using simple function objects (like std::functor) for sequential pixel iteration.
Definition: FunctorOp.h:135
void traverseChannel(const Channel &src, Channel &dst) const
Process the image.
Definition: FunctorOp.h:225
Definition: DataSelector.cpp:1277