31 #ifndef SEGMENTAREAOP_H
32 #define SEGMENTAREAOP_H
36 #include "drain/util/FunctorBank.h"
37 #include "drain/image/SegmentProber.h"
42 #include "SegmentOp.h"
95 template <
class S,
class D,
class T=SizeProber>
110 SegmentAreaOp(
double min=1.0,
double max=std::numeric_limits<double>::max()) :
112 SegmentOp(__FUNCTION__,
"Computes segment sizes.") {
113 parameters.link(
"intensity", this->intensity.tuple(),
"min:max");
114 parameters.link(
"functor", this->functorStr);
115 this->intensity.set(min, max);
120 SegmentOp(__FUNCTION__,
"Computes segment sizes", ftor) {
121 parameters.link(
"intensity", this->intensity.tuple(),
"min:max");
122 this->intensity.set(min, max);
126 parameters.
copyStruct(op.getParameters(), op, *
this);
131 void getDstConf(
const ImageConf & src, ImageConf & dst)
const;
134 void traverseChannels(
const ImageTray<const Channel> & src, ImageTray<Channel> & dst)
const {
146 template <
class S,
class D,
class T>
152 const std::type_info & t =
typeid(dst_t);
158 if (Type::call<typeIsFloat>(dst.
getType())){
160 mout.
warn(
"float valued destination data not supported, setting: " , Type::getTypeChar(t) );
164 dst.setArea(src.getGeometry());
165 dst.setChannelCount(std::max(src.getImageChannelCount(),dst.getImageChannelCount()), dst.getAlphaChannelCount());
172 template <
class S,
class D,
class T>
178 raw.min = src.getScaling().
inv(this->intensity.min);
179 raw.max = (this->intensity.max == std::numeric_limits<double>::max()) ? src.getConf().
getTypeMax<src_t>() : src.getScaling().
inv(this->intensity.max);
181 if (raw.min <= src.getConf().
getTypeMin<src_t>()){
182 mout.
warn(
"src scaling: " , src.getScaling() );
183 mout.
warn(
"original range: " , intensity );
184 mout.
warn(
"raw (code) range: " , raw );
185 mout.
warn(
"min value=" , (
double)raw.min ,
" less or smaller than storage type min=" , src.getConf().
getTypeMin<src_t>() );
188 mout.
special(
"raw range: " , (
double)raw.min ,
'-' , (double)raw.max );
189 mout.
debug2(
"src: " , src );
190 mout.
debug2(
"dst: " , dst );
193 T sizeProber(src, dst);
194 sizeProber.conf.anchor.set(raw.min, raw.max);
195 mout.
debug2(
"areaProber:" , sizeProber );
198 floodFill.conf.anchor.set(raw.min, raw.max);
199 mout.
debug2(
"Floodfill: " , floodFill );
201 const double scale = drain::Type::call<typeNaturalMax>(dst.
getType());
206 mout.
debug(
"Scale: " , scale );
207 mout.
debug(
"Final functor: " , ftor.
getName() ,
'(' , ftor.getParameters() ,
')' );
216 const bool HORZ_MODE = ((cp.xUnderFlowPolicy != EdgePolicy::POLAR) && (cp.xOverFlowPolicy != EdgePolicy::POLAR));
219 mout.
attention(
"scan HORIZONTAL, coordPolicy=", cp);
222 mout.
attention(
"scan VERTICAL, coordPolicy=", cp);
226 typename Limiter::value_t limit = dst.getConf().getLimiter<dst_t>();
228 const size_t width = src.getWidth();
229 const size_t height = src.getHeight();
232 for (
size_t i=0; i<width; i++){
233 for (
size_t j=0; j<height; j++){
237 sizeProber.probe(i,j, HORZ_MODE);
239 if (sizeProber.size > 0){
242 sizeMapped = limit(ftor(sizeProber.size));
250 floodFill.
probe(i,j, HORZ_MODE);
virtual const std::string & getName() const
Return the name of an instance.
Definition: BeanLike.h:69
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & attention(const TT &... args)
Possible error, but execution can continue. Special type of Logger::warn().
Definition: Log.h:472
Logger & special(const TT &... args)
Other useful information.
Definition: Log.h:527
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
void copyStruct(const ReferenceMap &m, const T &src, T &dst, extLinkPolicy policy=RESERVE)
Experimental. Copies references and values of a structure to another.
Definition: ReferenceMap.h:399
double inv(double y) const
Inverse scaling: given physically meaningful value y, returns the corresponding code value.
Definition: ValueScaling.h:301
Image with static geometry.
Definition: ImageChannel.h:60
Policies for coordinate underflows and overflows.
Definition: CoordinatePolicy.h:106
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
T getTypeMax() const
Returns the maximum value supported by the current storage type.
Definition: ImageConf.h:281
T getTypeMin() const
Returns the minimum value supported by the current storage type.
Definition: ImageConf.h:267
Definition: SegmentProber.h:490
Struct for image (excluding data)
Definition: ImageConf.h:333
const std::type_info & getType() const
Get the storage type.
Definition: ImageLike.h:100
const CoordinatePolicy & getCoordinatePolicy() const
Coord policy.
Definition: ImageLike.h:167
void traverseChannelsSeparately(const ImageTray< const Channel > &src, ImageTray< Channel > &dst) const
Process each (src,dst) channel pair independently. Raise error if their counts differ.
Definition: ImageOp.cpp:340
Computes sizes of connected pixel areas.
Definition: SegmentAreaOp.h:97
virtual void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition: SegmentAreaOp.h:173
SegmentAreaOp(double min=1.0, double max=std::numeric_limits< double >::max())
Definition: SegmentAreaOp.h:110
void getDstConf(const ImageConf &src, ImageConf &dst) const
Resizes dst to width and height of src. Ensures integer type.
Definition: SegmentAreaOp.h:147
A base class for computing statistics of segments. As segment is an area of connected pixels.
Definition: SegmentOp.h:53
D markerValue
"fill value", also dynamically changing visit marker?
Definition: SegmentProber.h:77
void probe(int i, int j, bool HORIZONTAL)
Start probings.
Definition: SegmentProber.h:208
Class for ensuring that variable of type D remains within limits of type S.
Definition: TypeUtils.h:653
Definition: DataSelector.cpp:1277
UnaryFunctor & getFunctor(const std::string &nameAndParams, char separator)
Returns functor the parameters of which have been set.
Definition: FunctorBank.cpp:81
Definition: Functor.h:116