Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TestPyramidImage.cpp
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8 
9  BIAS is free software; you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation; either version 2.1 of the License, or
12  (at your option) any later version.
13 
14  BIAS is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with BIAS; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
22 
23 
24 /**
25  * @example TestPyramidImage.cpp
26  * @relates PyramidImage
27  * @brief shows usage of pyramid image
28  * @author MIP
29  * @date 2007
30  */
31 
32 #include <Image/PyramidImage.hh>
33 
34 using namespace BIAS;
35 using namespace std;
36 
37 void TestInit()
38 {
39  const unsigned width = 640, height = 480, channelcount=3, size = 2;
40  Image<unsigned char> im(width, height, channelcount);
41  ImageBase imb(im);
43  if (!pim.IsEmpty()) { BIASABORT; }
44 
45  pim.Init(size);
46  if (!(pim.Size()==size)) { BIASABORT; }
47  if (pim.Size()>0 && !pim[0]->IsEmpty()) { BIASABORT; }
48  pim.Clear();
49  if (!pim.IsEmpty()) { BIASABORT; }
50 
51  pim.Init(width, height, channelcount, size);
52  if (!(pim.Size()==size)) { BIASABORT; }
53  if ((pim.Size()>0) && (pim[0]->GetWidth()!=width)) { BIASABORT; }
54  if ((pim.Size()>0) && (pim[0]->GetChannelCount()!=channelcount)) { BIASABORT; }
55  pim.Clear();
56  if (!pim.IsEmpty()) { BIASABORT; }
57 
58  pim.Init(im, size);
59  if (!(pim.Size()==size)) { BIASABORT; }
60  if ((pim.Size()>0) && (pim[0]->GetWidth()!=width)) { BIASABORT; }
61  if ((pim.Size()>0) && (pim[0]->GetChannelCount()!=channelcount)) { BIASABORT; }
62  if ((pim.Size()>1) && pim[1]->IsEmpty()) { BIASABORT; }
63 
64  pim.InitFromImageBase(imb, size);
65  if (!(pim.Size()==size)) { BIASABORT; }
66  if ((pim.Size()>0) && (pim[0]->GetWidth()!=width)) { BIASABORT; }
67  if ((pim.Size()>0) && (pim[0]->GetChannelCount()!=channelcount)) { BIASABORT; }
68  if ((pim.Size()>1) && pim[1]->IsEmpty()) { BIASABORT; }
69 
71  if (!(pim2.Size()==size)) { BIASABORT; }
72  if ((pim2.Size()>0) && (pim2[0]->GetWidth()!=width)) { BIASABORT; }
73  if ((pim2.Size()>0) && (pim2[0]->GetChannelCount()!=channelcount)) { BIASABORT; }
74  if ((pim2.Size()>1) && pim2[1]->IsEmpty()) { BIASABORT; }
75 }
76 
77 void TestCopy()
78 {
79  const unsigned width = 640, height = 480, channelcount=3, size = 2;
81  if (!pim.IsEmpty()) { BIASABORT; }
82 
83  pim.Init(width, height, channelcount, size);
84 
85  PyramidImage<unsigned char> pim2 = pim;
86  if (!(pim2.Size()==size)) { BIASABORT; }
87  if ((pim2.Size()>0) && (pim2[0]->GetWidth()!=width)) { BIASABORT; }
88  if ((pim2.Size()>0) && (pim2[0]->GetChannelCount()!=channelcount)) { BIASABORT; }
89  if ((pim2.Size()>1) && pim2[1]->IsEmpty()) { BIASABORT; }
90 
92  if (!(pim3.Size()==size)) { BIASABORT; }
93  if ((pim3.Size()>0) && (pim3[0]->GetWidth()!=width)) { BIASABORT; }
94  if ((pim3.Size()>0) && (pim3[0]->GetChannelCount()!=channelcount)) { BIASABORT; }
95  if ((pim3.Size()>1) && pim3[1]->IsEmpty()) { BIASABORT; }
96  if (RefCount(pim3[0])!=1) { BIASABORT; }
97 
98  pim2.ShallowCopy(pim);
99  if (!(pim2.Size()==size)) { BIASABORT; }
100  if ((pim2.Size()>0) && (pim2[0]->GetWidth()!=width)) { BIASABORT; }
101  if ((pim2.Size()>0) && (pim2[0]->GetChannelCount()!=channelcount)) { BIASABORT; }
102  if ((pim2.Size()>1) && pim2[1]->IsEmpty()) { BIASABORT; }
103  if (RefCount(pim2[0])!=2) { BIASABORT; }
104 }
105 
106 void TestResize()
107 {
108  const unsigned width = 640, height = 480, channelcount=3, size = 2;
109  Image<unsigned char> im(width, height, channelcount);
111  if (!pim.IsEmpty()) { BIASABORT; }
112 
113  pim.Init(width, height, channelcount, size);
114  pim.resize(3);
115  if (!pim[2]) { BIASABORT; }
116  if (!pim[2]->IsEmpty()) { BIASABORT; }
117  pim.Downsample();
118  if (pim[2]->IsEmpty()) { BIASABORT; }
119  // the following should creat a total of 5 levels when th ebiggest image
120  // has size 640x480
121  pim.CreateAdditionalLayer(2u, 32);
122  if (pim.Size()!=5u) { BIASABORT; }
123 
124 }
125 
126 int main(int argc, char *argv[])
127 {
128  TestInit();
129  TestCopy();
130  TestResize();
131 
132  return 0;
133 }
void InitFromImageBase(const ImageBase &image, const unsigned py_size=0)
same as Init(Image) but can use different ST, e.g.
virtual void resize(const unsigned size)
int Downsample()
downsamples from (*this)[0] assumes that all pointers e.g.
bool IsEmpty() const
void Init(const Image< StorageType > &image, const unsigned py_size=0)
copy image into level 0 and create other levels according to parameters set so far (pyramidsize...
unsigned RefCount(const SharedPtr< T > &t)
unsigned Size() const
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
int CreateAdditionalLayer(unsigned int numnewLayers=1, unsigned int minImageWidth=32)
resizes this and fills correctly with smaller images
PyramidImage< StorageType > & ShallowCopy(const PyramidImage< StorageType > &pim)
sets this as shallow copy of pim