26 #include "Dilation.hh"
27 #include "Base/Image/ImageConvert.hh"
28 #include <Base/Common/BIASpragma.hh>
35 template <
class InputStorageType,
class OutputStorageType>
42 template <
class InputStorageType,
class OutputStorageType>
51 #ifdef BIAS_BOUNDS_CHECK
53 BIASERR(
"Dilation::Dilate() only implemented for grey images");
55 BIASERR(
"Dilation::Dilate() wrong images izes");
56 if (KernelSize % 2 != 1)
57 BIASERR(
"Dilation::Dilate() odd KernelSize required");
62 register int HalfKernelSize = (KernelSize - 1) / 2;
63 OutputStorageType *Dest = NULL;
64 register OutputStorageType **DestArray;
68 Dest =
new OutputStorageType[Height * Width];
69 DestArray =
new OutputStorageType*[Height];
71 for (
register int i=1; i< Height; i++) {
72 DestArray[i] = DestArray[i-1] + Width;
78 for (
register int y = HalfKernelSize;
79 y < ((int)Source.
GetHeight() - HalfKernelSize); y++){
80 for (
register int x = HalfKernelSize;
81 x < ((int)Source.
GetWidth() - HalfKernelSize); x++) {
83 for (
register int ky = -HalfKernelSize; ky <= HalfKernelSize; ky++)
84 for (
register int kx = -HalfKernelSize; kx <= HalfKernelSize; kx++)
86 if (SourceArray[y+ky][x+kx]>DestArray[y][x])
87 DestArray[y][x]=SourceArray[y+ky][x+kx];
89 if ((DestArray[y][x]==0 && SourceArray[y+ky][x+kx]>0) ||
90 (SourceArray[y+ky][x+kx]<DestArray[y][x] && SourceArray[y+ky][x+kx]>0))
91 DestArray[y][x]=SourceArray[y+ky][x+kx];
102 this->FillBorderConst(Destination, (
unsigned short int)HalfKernelSize,
103 (
unsigned short int)HalfKernelSize, (OutputStorageType)0);
107 template <
class InputStorageType,
class OutputStorageType>
116 BIASERR(
"Dilation::Dilate3Fast() only implemented for grey images");
120 BIASERR(
"Dilation::Dilate3Fast(): src has less than 25 pixel");
124 BIASERR(
"Dilation::Dilate3Fast(): src has less than 5 cols or rows");
128 BIASERR(
"Dilation::Dilate3Fast(): src and dest have different sizes");
143 register const InputStorageType *p2=p1+1, *p3 = p2+1;
145 register const InputStorageType *p5 = p4+1, *p6=p5+1;
147 register const InputStorageType *p8 = p7+1, *p9=p8+1;
157 p2++; p4++; p5++; p6++; p8++; d++;
171 p1++; p2++; p3++; p4++; p5++; p6++; p7++; p8++; p9++; d++;
176 register OutputStorageType *o1,*o2,*o9,*olast;
185 register unsigned int offset = dest.
GetWidth();
197 template <
class InputStorageType,
class OutputStorageType>
204 BIASERR(
"Dilation::Dilate3Fast() only implemented for grey images");
208 BIASERR(
"Dilation::Dilate3Fast(): src has less than 25 pixel");
212 BIASERR(
"Dilation::Dilate3Fast(): src has less than 5 cols or rows");
216 BIASERR(
"Dilation::Dilate3Fast(): src and dest have different sizes");
224 register const InputStorageType *p2=p1+1, *p3 = p2+1;
226 register const InputStorageType *p5 = p4+1, *p6=p5+1;
228 register const InputStorageType *p8 = p7+1, *p9=p8+1;
232 *d = OutputStorageType(255);
239 p2++; p4++; p5++; p6++; p8++; d++;
243 *d = OutputStorageType(255);
254 p1++; p2++; p3++; p4++; p5++; p6++; p7++; p8++; p9++; d++;
259 register OutputStorageType *o1,*o2,*o9,*olast;
268 register unsigned int offset = dest.
GetWidth();
280 template <
class InputStorageType,
class OutputStorageType>
285 BIASERR(
"Erosion only for 1 channel images");
288 if (_FilterBorderHandling==TBH_valid) {
289 if (kernelSize_==3) {
296 Dilate3Fast(src,tmp,dst,
false);
299 Dilate(src,dst,kernelSize_);
302 }
else if (_FilterBorderHandling==TBH_same) {
310 Dilate(tmp,dst,kernelSize_);
316 BIASERR(
"Unknown border handling.");
323 template <
class InputStorageType,
class OutputStorageType>
327 BIASERR(
"no parameter support");
335 #define FILTER_INSTANTIATION_CLASS Dilation
336 #include "Filterinst.hh"
void Release()
reimplemented from ImageBase
int Cut2ROI()
reduces image to current ROI, !!! image size changes !!!
int SetCorners(unsigned UpperLeftX, unsigned UpperLeftY, unsigned LowerRightX, unsigned LowerRightY)
Sets a rectangular region of interest.
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Dilation operator for binary images (black and white)
int Dilate3Fast(const Image< InputStorageType > &src, const Image< InputStorageType > &orig, Image< OutputStorageType > &dest, bool Neighbor4=false)
Very fast dilate with 3x3 mask, all values, which are not not zero, are treated as foreground...
unsigned int GetWidth() const
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
Does the dilation.
ROI * GetROI()
Returns a pointer to the roi object.
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
int Dilate(const Image< InputStorageType > &Source, Image< OutputStorageType > &Destination, int KernelSize=3)
dilate with square kernel filled with 255
unsigned int GetHeight() const
void FillImageWithConstValue(StorageType Value)
fill grey images
bool SamePixelAndChannelCount(const ImageBase &Image) const
checks if data area has same "size" as Image of other type
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
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
virtual void GetBordersValid_(int &border_x, int &border_y) const
enum EStorageType GetStorageType() const
int Paste2ROI(const ImageBase &Image)
paste Image to current ROI
unsigned long int GetPixelCount() const
returns number of pixels in image
void RedirectImageDataPointer(void *data)
This method takes data and set the internal image data pointer to this.
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase