24 #include <Base/Common/BIASpragmaStart.hh>
26 #include <Base/Debug/Debug.hh>
27 #include <Base/Debug/Error.hh>
28 #include <Base/Debug/Exception.hh>
33 #define ROI_VERSION_NUMBER 200
42 BIASImageBase_EXPORT std::ostream&
operator<<(std::ostream& os,
const enum ERoiType& type);
53 Position(
unsigned xx,
unsigned yy) : x(xx), y(yy) {};
63 {
return (y==p.
y)?(x<p.
x):(y<p.
y); }
66 {
return (y!=p.
y)||(x!=p.
x); }
68 friend BIASImageBase_EXPORT
139 void Resize(
unsigned width,
unsigned height);
146 ROI& operator=(
const ROI& roi);
149 void SetROIType(
const enum ERoiType& type);
152 bool operator==(
const ROI& roi)
const;
154 {
return !operator==(roi); }
166 int SetCorners(
unsigned UpperLeftX,
unsigned UpperLeftY,
167 unsigned LowerRightX,
unsigned LowerRightY);
174 inline void GetCorners(
unsigned &UpperLeftX,
unsigned &UpperLeftY,
175 unsigned &LowerRightX,
176 unsigned &LowerRightY)
const;
182 inline void GetCorners(
int& UpperLeftX,
int& UpperLeftY,
183 int& LowerRightX,
int& LowerRightY)
const;
210 inline bool IsInROI(
const double& x,
const double& y)
const;
214 inline bool IsInROI(
const double& left,
const double& top,
215 const double& right,
const double& bottom)
const;
229 void SetMask(
const unsigned& x,
const unsigned& y,
const bool val);
233 bool Mask(
const unsigned& x,
const unsigned& y)
const;
239 void SetVector(std::vector<Position>& pos);
243 {
if (RoiType_!=
ROI_Points)
return NULL;
return &Vector_; }
247 bool GetVector(std::vector<Position>& vec)
const;
261 inline bool GetRows(std::vector<unsigned>& start,
262 std::vector<unsigned>& end)
const
263 { start = RowStart_; end = RowEnd_;
return (RoiType_==
ROI_Rows); }
269 void SetRows(
const std::vector<unsigned>& start,
270 const std::vector<unsigned>& end);
280 inline bool CheckBilinearInterpolation(
const double x,
281 const double y)
const;
286 inline bool CheckBicubicInterpolation(
const double x,
287 const double y)
const;
293 inline int GetBilinearInterpolationNeighbors(
const double x,
295 std::vector<int> &nx,
296 std::vector<int> &ny)
const;
317 bool SameSize(
const ROI& roi)
const;
325 friend BIASImageBase_EXPORT std::ostream&
330 int WriteBinary(std::ostream& os)
const;
334 int ReadBinary(std::istream& is);
346 int ConvertROIType(
const enum ERoiType& type);
350 void Erode(
const ROI &src,
const unsigned half_mask_size);
389 int Corners2Vector_();
409 int Vector2Corners_();
434 BIASImageBase_EXPORT std::ostream&
444 unsigned &LowerRightX,
unsigned &LowerRightY)
const
454 int& LowerRightX,
int& LowerRightY)
const
461 # define rint(x) (floor(x+0.5))
473 int iy = (int)rint(y);
474 int ix = (int)rint(x);
475 if (ix<0 || iy<0 || ix>=(
int)
Width_ || iy>=(int)
Height_)
return false;
476 return Mask((
unsigned)ix, (
unsigned)iy);
481 unsigned iy = (unsigned)rint(y);
482 unsigned ix = (unsigned)rint(x);
483 std::vector<Position>::const_iterator iter;
485 if (iter->x==ix && iter->y==iy)
return true;
492 int iy = (int)rint(y);
493 if (iy<0 || iy>=(
int)
Height_)
return false;
494 int ix = (int)rint(x);
499 BEXCEPTION(
"Unknown ROI type "<<
RoiType_<<
" found");
506 const double& right,
const double& bottom)
const
516 int il = (int)rint(left);
517 int it = (int)rint(top);
518 int ir = (int)rint(right);
519 int ib = (int)rint(bottom);
520 if (il<0 || it<0 || ir>=(
int)
Width_ || ib>=(int)
Height_)
return false;
521 for (
register int iy = it; iy <= ib; iy++)
522 for (
register int ix = il; ix <= ir; ix++)
523 if (!
Mask((
unsigned)ix, (unsigned)iy))
return false;
530 unsigned il = (unsigned)rint(left);
531 unsigned it = (unsigned)rint(top);
532 unsigned ir = (unsigned)rint(right);
533 unsigned ib = (unsigned)rint(bottom);
535 const int size = (ir-il+1)*(ib-it+1);
536 std::vector<Position>::const_iterator iter;
537 for (iter=
Vector_.begin(); iter!=
Vector_.end() && count<size; iter++) {
538 if (iter->x >= il && iter->x <= ir && iter->y >= it && iter->y <= ib)
541 return (count == size);
546 int il = (int)rint(left);
547 int it = (int)rint(top);
548 int ir = (int)rint(right);
549 int ib = (int)rint(bottom);
550 if (it<0 || ib>=(
int)
Height_)
return false;
551 for (
register int iy = it; iy <= ib; iy++) {
558 BEXCEPTION(
"Unknown ROI type "<<
RoiType_<<
" found");
567 return IsInROI(floor(x), floor(y), ceil(x), ceil(y));
573 return IsInROI(floor(x)-1, floor(y)-1, floor(x)+2, floor(y)+2);
578 std::vector<int> &nx,
579 std::vector<int> &ny)
const
583 const int fx = floor(x);
584 const int cx = ceil(x);
585 const int fy = floor(y);
586 const int cy = ceil(y);
587 if (
IsInROI(fx, fy)) { nx.push_back(fx); ny.push_back(fy); }
588 if (
IsInROI(cx, fy)) { nx.push_back(cx); ny.push_back(fy); }
589 if (
IsInROI(fx, cy)) { nx.push_back(fx); ny.push_back(cy); }
590 if (
IsInROI(cx, cy)) { nx.push_back(cx); ny.push_back(cy); }
591 return int(nx.size());
596 #include <Base/Common/BIASpragmaEnd.hh>
stores valid/nvalid positions in image
class for handling different region of interest (ROI) representations...
Position(const Position &pos)
void GetCorners(unsigned &UpperLeftX, unsigned &UpperLeftY, unsigned &LowerRightX, unsigned &LowerRightY) const
Return the region of interest, by saving the coordinates within the variables defined by the paramete...
std::vector< bool > Mask_
internal data for ROI of type ROI_Mask the mask data: Mask_[y*Width_+x] corresponds to pixel at (x...
int GetBilinearInterpolationNeighbors(const double x, const double y, std::vector< int > &nx, std::vector< int > &ny) const
Get valid neighbor pixels in ROI for bilinear interpolation at subpixel position (x,y).
unsigned x
member variables
bool operator<(const Position &p) const
comparison, needed for sorting
bool Mask(const unsigned &x, const unsigned &y) const
Direct access to the mask data, const version.
unsigned GetWidth() const
width capacity of roi (image width)
Position(unsigned xx, unsigned yy)
bool operator!=(const Position &p) const
comparison
enum ERoiType RoiType_
which method is used to store the ROI
unsigned Width_
maximum dimension of roi data
std::vector< Position > * GetVector()
returns a pointer to the vector representation of the ROI
bool VectorValid() const
is the position vector valid?
bool IsInROI(const double &x, const double &y) const
ROI check if pixel position is inside the ROI.
bool GetRows(std::vector< unsigned > &start, std::vector< unsigned > &end) const
Horizontal start and end position per image row, the length of the vectors always corresponds to the ...
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
unsigned UpperLeftX_
internal data for ROI of type ROI_Corners rectangular region of interest defined by upper left and lo...
Position & operator=(const Position &p)
assignment operator
static const int Version_
version number of ROI class
std::vector< unsigned > RowEnd_
bool CheckBilinearInterpolation(const double x, const double y) const
Check if subpixel position (x,y) in ROI is valid for bilinear interpolation (i.e. ...
bool MaskValid() const
is the position vector valid?
bool CheckBicubicInterpolation(const double x, const double y) const
Check if subpixel position (x,y) in ROI is valid for bicubic interpolation (i.e.
unsigned GetHeight() const
height capacity of roi (image height)
bool operator!=(const ROI &roi) const
unsigned GetCornerLowerRightY() const
fetch individual ROI corner coordinate
This is the base class for images in BIAS.
unsigned GetCornerUpperLeftY() const
fetch individual ROI corner coordinate
std::vector< Position > Vector_
internal data for ROI of type ROI_Points Vector instance of ROI, always sorted from top left to botto...
unsigned GetCornerLowerRightX() const
fetch individual ROI corner coordinate
unsigned GetCornerUpperLeftX() const
fetch individual ROI corner coordinate
std::vector< unsigned > RowStart_
internal data for ROI of type ROI_Rows the ROI is specified by a min and a max value for each row in ...