Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TestROI.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /**
26  @example TestROI
27  @ingroup g_examples
28  @brief Roi testing
29  @author MIP
30 */
31 
32 #include <fstream>
33 #include <Base/Image/ROI.hh>
34 
35 using namespace BIAS;
36 using namespace std;
37 
38 void WriteRead(const ROI src, ROI& dst);
39 
40 void TestIO()
41 {
42  ROI src, dst;
43  const unsigned w=100, h=75;
44  src.Resize(w, h);
45  if (src.GetWidth()!=w || src.GetHeight()!=h) { BIASABORT; }
46 
47  // corners
48  const unsigned ulx=10, uly=10, lrx=50, lry=50;
49  src.SetCorners(ulx, uly, lrx, lry);
50  WriteRead(src, dst);
51  unsigned mulx, muly, mlrx, mlry;
52  dst.GetCorners(mulx, muly, mlrx, mlry);
53  if (ulx!=mulx || uly!=muly || lrx!=mlrx || lry!=mlry){ BIASABORT; }
54 
55  // rows
56  vector<unsigned> start(h, 0), end(h, w);
57  start[42] = 42;
58  end[42] = 84;
59  src.SetRows(start, end);
60  WriteRead(src, dst);
61  vector<unsigned> mstart, mend;
62  //cout << "src: "<<src << endl;
63  //cout << "dst: "<<dst << endl;
64  if (!dst.GetRows(mstart, mend)) { BIASABORT; }
65  if (mstart.size()!=h || mend.size()!=h) { BIASABORT; }
66  for (unsigned y=0; y<h; y++){
67  if (mstart[y] != start[y]) { BIASABORT; }
68  if (mend[y] != end[y]) { BIASABORT; }
69  }
70 
71  // points
72  vector<Position> pos(2);
73  pos[0] = Position(42, 42);
74  pos[1] = Position(42, 43);
75  src.SetVector(pos);
76  WriteRead(src, dst);
77  vector<Position> dst_pos;
78  if (!dst.GetVector(dst_pos)) { BIASABORT; }
79  if (dst_pos.size()!=2) { BIASABORT; }
80  for (int i=0; i<2; i++){
81  if (dst_pos[i].x!=pos[i].x) { BIASABORT; }
82  if (dst_pos[i].y!=pos[i].y) { BIASABORT; }
83  }
84 
85  // mask
86  src.SetMask(42, 42, false);
87  WriteRead(src, dst);
88  if (dst.Mask(42, 42)!=false) { BIASABORT; }
89  if (dst.Mask(10, 10)!=true) { BIASABORT; }
90 
91 }
92 
93 
94 int main(int argc, char *argv[])
95 {
96  TestIO();
97  return 0;
98 }
99 
100 
101 void WriteRead(const ROI src, ROI& dst)
102 {
103  const string file("roi.bin");
104  ofstream of(file.c_str());
105  if (src.WriteBinary(of)!=0){ BIASABORT; }
106  of.close();
107  ifstream is(file.c_str());
108  if (dst.ReadBinary(is)!=0){ BIASABORT; }
109  is.close();
110 }
stores valid/nvalid positions in image
Definition: ROI.hh:49
class for handling different region of interest (ROI) representations...
Definition: ROI.hh:118
int SetCorners(unsigned UpperLeftX, unsigned UpperLeftY, unsigned LowerRightX, unsigned LowerRightY)
Sets a rectangular region of interest.
Definition: ROI.cpp:287
void Resize(unsigned width, unsigned height)
Resizes parent image.
Definition: ROI.cpp:227
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...
Definition: ROI.hh:443
bool Mask(const unsigned &x, const unsigned &y) const
Direct access to the mask data, const version.
Definition: ROI.cpp:488
unsigned GetWidth() const
width capacity of roi (image width)
Definition: ROI.hh:250
int WriteBinary(std::ostream &os) const
binary output to stream
Definition: ROI.cpp:507
std::vector< Position > * GetVector()
returns a pointer to the vector representation of the ROI
Definition: ROI.hh:242
int ReadBinary(std::istream &is)
binary input from stream
Definition: ROI.cpp:573
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 ...
Definition: ROI.hh:261
unsigned GetHeight() const
height capacity of roi (image height)
Definition: ROI.hh:254
void SetMask(const unsigned &x, const unsigned &y, const bool val)
Direct access to the mask data.
Definition: ROI.cpp:478
void SetVector(std::vector< Position > &pos)
Sets MaskValid_=false and VectorValid_=true.
Definition: ROI.cpp:463
void SetRows(const std::vector< unsigned > &start, const std::vector< unsigned > &end)
Horizontal start and end position per image row, the length of the vectors always corresponds to the ...
Definition: ROI.cpp:436