31#ifndef SEGMENTAREAOP_H
32#define SEGMENTAREAOP_H
36#include "drain/image/SegmentProber.h"
94template <
class S,
class D,
class T=SizeProber>
109 SegmentAreaOp(
double min=1.0,
double max=std::numeric_limits<double>::max()) :
111 SegmentOp(__FUNCTION__,
"Computes segment sizes.") {
112 parameters.link(
"intensity", this->intensity.tuple(),
"min:max");
113 parameters.link(
"functor", this->functorStr);
114 this->intensity.set(min, max);
119 SegmentOp(__FUNCTION__,
"Computes segment sizes", ftor) {
120 parameters.link(
"intensity", this->intensity.tuple(),
"min:max");
121 this->intensity.set(min, max);
125 parameters.
copyStruct(op.getParameters(), op, *
this);
130 void getDstConf(
const ImageConf & src, ImageConf & dst)
const;
133 void traverseChannels(
const ImageTray<const Channel> & src, ImageTray<Channel> & dst)
const {
145template <
class S,
class D,
class T>
151 const std::type_info & t =
typeid(dst_t);
157 if (Type::call<typeIsFloat>(dst.
getType())){
159 mout.
warn(
"float valued destination data not supported, setting: " , Type::getTypeChar(t) );
163 dst.setArea(src.getGeometry());
164 dst.setChannelCount(std::max(src.getImageChannelCount(),dst.getImageChannelCount()), dst.getAlphaChannelCount());
171template <
class S,
class D,
class T>
177 raw.min = src.getScaling().
inv(this->intensity.min);
178 raw.max = (this->intensity.max == std::numeric_limits<double>::max()) ? src.getConf().
getTypeMax<src_t>() : src.getScaling().
inv(this->intensity.max);
180 if (raw.min <= src.getConf().
getTypeMin<src_t>()){
181 mout.
warn(
"src scaling: " , src.getScaling() );
182 mout.
warn(
"original range: " , intensity );
183 mout.
warn(
"raw (code) range: " , raw );
184 mout.
warn(
"min value=" , (
double)raw.min ,
" less or smaller than storage type min=" , src.getConf().
getTypeMin<src_t>() );
187 mout.
special(
"raw range: " , (
double)raw.min ,
'-' , (
double)raw.max );
188 mout.
debug2(
"src: " , src );
189 mout.
debug2(
"dst: " , dst );
192 T sizeProber(src, dst);
193 sizeProber.conf.anchor.set(raw.min, raw.max);
194 mout.
debug2(
"areaProber:" , sizeProber );
197 floodFill.conf.anchor.set(raw.min, raw.max);
198 mout.
debug2(
"Floodfill: " , floodFill );
200 const double scale = drain::Type::call<typeNaturalMax>(dst.
getType());
205 mout.
debug(
"Scale: " , scale );
206 mout.
debug(
"Final functor: " , ftor.
getName() ,
'(' , ftor.getParameters() ,
')' );
215 const bool HORZ_MODE = ((cp.xUnderFlowPolicy != EdgePolicy::POLAR) && (cp.xOverFlowPolicy != EdgePolicy::POLAR));
218 mout.
attention(
"scan HORIZONTAL, coordPolicy=", cp);
221 mout.
attention(
"scan VERTICAL, coordPolicy=", cp);
225 typename Limiter::value_t limit = dst.getConf().getLimiter<dst_t>();
227 const size_t width = src.getWidth();
228 const size_t height = src.getHeight();
231 for (
size_t i=0; i<width; i++){
232 for (
size_t j=0; j<height; j++){
236 sizeProber.probe(i,j, HORZ_MODE);
238 if (sizeProber.size > 0){
241 sizeMapped = limit(ftor(sizeProber.size));
249 floodFill.
probe(i,j, HORZ_MODE);
virtual const std::string & getName() const
Return the name of an instance.
Definition BeanLike.h:80
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:431
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:667
Logger & special(const TT &... args)
Other useful information.
Definition Log.h:532
Logger & attention(const TT &... args)
Possible error, but execution can continue. Special type of Logger::warn().
Definition Log.h:477
Logger & debug2(const TT &... args)
Debug information.
Definition Log.h:677
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:415
double inv(double y) const
Inverse scaling: given physically meaningful value y, returns the corresponding code value.
Definition ValueScaling.h:300
Image with static geometry.
Definition ImageChannel.h:58
Policies for coordinate underflows and overflows.
Definition CoordinatePolicy.h:100
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:488
Struct for image (excluding data)
Definition ImageConf.h:333
const CoordinatePolicy & getCoordinatePolicy() const
Coord policy.
Definition ImageLike.h:174
const std::type_info & getType() const
Get the storage type.
Definition ImageLike.h:100
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:96
virtual void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition SegmentAreaOp.h:172
SegmentAreaOp(double min=1.0, double max=std::numeric_limits< double >::max())
Definition SegmentAreaOp.h:109
void getDstConf(const ImageConf &src, ImageConf &dst) const
Resizes dst to width and height of src. Ensures integer type.
Definition SegmentAreaOp.h:146
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:75
void probe(int i, int j, bool HORIZONTAL)
Start probings.
Definition SegmentProber.h:206
Class for ensuring that variable of type D remains within limits of type S.
Definition TypeUtils.h:98
Definition DataSelector.cpp:1277
UnaryFunctor & getFunctor(const std::string &nameAndParams, char separator)
Returns functor the parameters of which have been set.
Definition FunctorBank.cpp:77