1 #include "BlobDetectorLevelSet.hh"
10 template <
class StorageType>
16 eval_ownsdata_ =
true;
19 template <
class StorageType>
22 if ( eval_ownsdata_ ==
false )
23 eval_.RedirectImageDataPointer(NULL);
31 template <
class StorageType>
int
34 std::vector<BIAS::BIASBlob>& blobs){
38 GetSegmentation(image);
39 BIASWARN(
"Implementation unfinished, see ExampleBlobDetectorLevelSet for usage instructions!");
44 template <
class StorageType>
void
48 const int w = GetImage().GetWidth();
49 const int h = GetImage().GetHeight();
53 const StorageType ** image = GetImage().GetImageDataArray();
54 const StorageType ** level = GetLevel().GetImageDataArray();
57 for (
int j = 0; j < h; j++)
58 for (
int k = 0; k < w; k++)
59 dst[j][k] = level[j][k]==0 ? image[j][k] : 255-1;
62 template <
class StorageType> std::vector<int>
68 for (
int i = 0; i < 256; i++)
69 vec.push_back(hist==0 ? _hist0[i]:_hist1[i]);
74 template <
class StorageType>
void
88 template <
class StorageType>
void
91 for(
int i = 0; i < 256; i++)
95 template <
class StorageType>
void
98 ClearHistogram( _hist0 );
99 ClearHistogram( _hist1 );
102 template <
class StorageType>
void
106 const int w = eval_.GetWidth();
107 const int h = eval_.GetHeight();
111 const StorageType ** image = image_->GetImageDataArray();
112 StorageType ** level = level_->GetImageDataArray();
113 StorageType ** eval = eval_.GetImageDataArray();
115 for(
int j = 0; j < h; j++)
116 for(
int k = 0; k < w; k++)
117 if ( eval[j][k]!=0 ) {
118 const StorageType pv = image[j][k];
120 if ( level[j][k]==0 )
127 template <
class StorageType>
void
133 const int x1 = p1[0];
134 const int y1 = p1[1];
135 const int x2 = p2[0];
136 const int y2 = p2[1];
143 BIASASSERT( p1>=
Vector2<int>(0,0) && p1<=p2 && p2<=vDim );
149 for (
int j = y1; j < y2; j++)
150 for (
int k = x1; k < x2; k++)
154 template <
class StorageType>
void
163 BIASASSERT( w==(
int)eval_.GetWidth() && h==(int)eval_.GetHeight() );
166 if ( eval_ownsdata_ ==
true )
167 eval_.ReleaseImageDataPointer();
171 eval_.RedirectImageDataPointer( (
void*)img.
GetImageData());
172 eval_ownsdata_ =
false;
175 if ( eval_ownsdata_ ==
false ) {
176 void * data =
new char[w*h];
177 eval_.RedirectImageDataPointer( data );
178 eval_ownsdata_ =
true;
183 template <
class StorageType>
void
192 Resize( *level_, w,h );
193 Resize( *level_s_, w,h );
194 Resize( eval_, w,h );
198 StorageType ** level = level_->GetImageDataArray();
199 StorageType ** level_s = level_s_->GetImageDataArray();
200 {
for (
int k = 0; k < w; k += w-1)
201 for (
int j = 0; j < h; j++)
202 level[j][k] = level_s[j][k] = 0; }
203 {
for (
int j = 0; j < h; j += h-1)
204 for (
int k = 0; k < w; k++)
205 level[j][k] = level_s[j][k] = 0; }
209 template <
class StorageType>
void
215 AddSquare( *level_, p1,p2 );
218 template <
class StorageType>
void
223 BIASASSERT( eval_ownsdata_ ==
true );
226 AddSquare( eval_, p1,p2 );
229 template <
class StorageType>
void
234 BIASASSERT( eval_ownsdata_ ==
true );
236 AddSquare( eval_, p1,p2 );
240 template <
class StorageType>
void
246 const int h = level_->GetHeight();
247 const int w = level_->GetWidth();
251 const StorageType ** image = image_->GetImageDataArray();
252 StorageType ** level = level_->GetImageDataArray();
253 StorageType ** level_s = level_s_->GetImageDataArray();
254 StorageType ** eval = eval_.GetImageDataArray();
257 for(
int j = 1; j<h-1; j++)
258 for (
int k = 1; k<w-1; k++)
259 if ( eval[j][k]!=0 ) {
261 if ( level[j][k] == val )
262 if ( level[j-1][k+1] != val ||
263 level[j-1][k+0] != val ||
264 level[j-1][k-1] != val ||
265 level[j+0][k+1] != val ||
266 level[j+0][k-1] != val ||
267 level[j+1][k-1] != val ||
268 level[j+1][k+0] != val ||
269 level[j+1][k+1] != val )
271 const StorageType grey = image[j][k];
272 if ( _hist0[grey] < _hist1[grey] )
275 if ( level[j][k] != val )
276 if ( level[j-1][k+1] == val ||
277 level[j-1][k+0] == val ||
278 level[j-1][k-1] == val ||
279 level[j+0][k+1] == val ||
280 level[j+0][k-1] == val ||
281 level[j+1][k-1] == val ||
282 level[j+1][k+0] == val ||
283 level[j+1][k+1] == val )
285 const StorageType grey = image[j][k];
286 if ( _hist1[grey] < _hist0[grey] )
305 #ifdef BUILD_IMAGE_INT
308 #ifdef BUILD_IMAGE_CHAR
311 #ifdef BUILD_IMAGE_SHORT
313 #ifdef BUILD_IMAGE_USHORT
316 #ifdef BUILD_IMAGE_UINT
318 #ifdef BUILD_IMAGE_DOUBLE
void Release()
reimplemented from ImageBase
void GetSegmentation(BIAS::Image< StorageType > &im) const
creates an image for visulalistion of the actual segmentation given by actual level set ...
void Set(const BIAS::Image< StorageType > &image, bool useROI=true)
sets image to operate on, note: image must not be modified until you delete this instance or an other...
void SetEvaluationSquare(const BIAS::Vector2< int > &p1, const BIAS::Vector2< int > &p2)
can be used only, iff image's roi is not in use (look at class discription)
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
int Detect(Image< StorageType > &image, std::vector< BIAS::BIASBlob > &blobs)
purely virtual interface definition
void Evolute()
does the hole segmentation work by modifying the level set (look at class discription) ...
void AddSquare(BIAS::Image< StorageType > &image, const BIAS::Vector2< int > &p1, const BIAS::Vector2< int > &p2)
unsigned int GetWidth() const
const void * GetImageData() const
void AddEvaluationSquare(const BIAS::Vector2< int > &p1, const BIAS::Vector2< int > &p2)
look at SetEvaluationSquare()
static void Resize(BIAS::Image< StorageType > &image, const int w, const int h)
ROI * GetROI()
Returns a pointer to the roi object.
Evaluates a segementation into fore/back-ground.
void Init(const BIAS::Image< StorageType > &image, bool useROI=true)
initialise this instance with given image, note: image must not be modified until you delete this ins...
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
unsigned int GetHeight() const
std::vector< int > GetHistogram(int hist)
The image template class for specific storage types.
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
bool MaskValid() const
is the position vector valid?
This is the base class for images in BIAS.
void InitLevelSetSquare(const BIAS::Vector2< int > &p1, const BIAS::Vector2< int > &p2)
look at class discription
int GetMaskImage(ImageBase &im) const
returns an image of StorageType unsigned char, where every pixel not in the ROI is set to UCHAR_MAX a...
static void ClearHistogram(int hist[])
virtual ~BlobDetectorLevelSet()
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase