Image-processing Library in C

++
Chen Lujie July 2, 2012

Contents
1 Introduction 1.1 Features . . . . . 1.2 Source files . . . 1.3 Explicit template 1.4 Coding style . . . . . . . . . . . . . . . . . . . instantiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 5 5 6 7 8 8 9 9 11 12 14 15 16 17 18 19 20 21 21 22 22 22 23 23 24 24 25 25 25 26 26 26 27 27 27 28 28 29 30

2 2D geometry classes and functions 2.1 CPt2D: 2D point class . . . . . . . . 2.2 CSize2D: 2D size class . . . . . . . . 2.3 CLine2D: 2D line segment class . . . 2.4 CRect: rectangle class . . . . . . . . 2.5 CRectRot: rotating rectangle class . 2.6 CFan: fan shape class . . . . . . . . 2.7 CCircle: circle class . . . . . . . . . . 2.8 CEllipse: ellipse class . . . . . . . . . 2.9 CPoly2D: 2D polygon class . . . . . 2.10 CLCSpl: a linear spline class . . . . 2.11 CNCSpl: a natural cubic spline class 2.12 Distance . . . . . . . . . . . . . . . . 2.13 Area2 . . . . . . . . . . . . . . . . . 2.14 Angle . . . . . . . . . . . . . . . . . 2.15 MidPoint . . . . . . . . . . . . . . . 2.16 Centroid . . . . . . . . . . . . . . . . 2.17 Intersect . . . . . . . . . . . . . . . . 2.18 CutLineInRect . . . . . . . . . . . . 2.19 BoundingRect . . . . . . . . . . . . . 2.20 PointInPolygon . . . . . . . . . . . . 2.21 ConvexHull . . . . . . . . . . . . . . 2.22 BoundingBox . . . . . . . . . . . . . 2.23 MinBoundingBox . . . . . . . . . . . 2.24 MinBoundingCircle . . . . . . . . . . 2.25 DelaunayTriangulation . . . . . . . . 2.26 FitLine . . . . . . . . . . . . . . . . 2.27 FitCircle . . . . . . . . . . . . . . . . 2.28 FitEllipse . . . . . . . . . . . . . . . 2.29 FitPolynomialCurve . . . . . . . . . 2.30 FitGauss . . . . . . . . . . . . . . . . 2.31 HoughLine . . . . . . . . . . . . . . 2.32 HoughCircle . . . . . . . . . . . . . . 2.33 GetLinePoints . . . . . . . . . . . . . 2.34 GetCirclePoints . . . . . . . . . . . .

1

3 2D image processing functions 3.1 ImgAssign . . . . . . . . . . . 3.2 ImgAssignBorder . . . . . . . 3.3 ImgCopy . . . . . . . . . . . . 3.4 ImgCopySubpixel . . . . . . . 3.5 ImgBlend . . . . . . . . . . . 3.6 ImgGradientX . . . . . . . . 3.7 ImgGradientY . . . . . . . . 3.8 ImgClamp . . . . . . . . . . . 3.9 ImgLinear . . . . . . . . . . . 3.10 ImgGamma . . . . . . . . . . 3.11 ImgMin . . . . . . . . . . . . 3.12 ImgMax . . . . . . . . . . . . 3.13 ImgMinMax . . . . . . . . . . 3.14 ImgMean . . . . . . . . . . . 3.15 ImgMedian . . . . . . . . . . 3.16 ImgVariance . . . . . . . . . . 3.17 ImgStdDev . . . . . . . . . . 3.18 ImgStatistics . . . . . . . . . 3.19 ImgFltMean . . . . . . . . . . 3.20 ImgFltMedian . . . . . . . . . 3.21 ImgFltVariance . . . . . . . . 3.22 ImgFltISEF . . . . . . . . . . 3.23 ImgConvX . . . . . . . . . . . 3.24 ImgConvY . . . . . . . . . . . 3.25 ImgConv . . . . . . . . . . . . 3.26 ImgResize . . . . . . . . . . . 3.27 ImgRotate . . . . . . . . . . . 3.28 ImgFlip . . . . . . . . . . . . 3.29 ImgFan . . . . . . . . . . . . 3.30 ImgRadial . . . . . . . . . . . 3.31 ImgMosaic . . . . . . . . . . . 3.32 ImgMatch . . . . . . . . . . . 3.33 ImgMatchSubpixel . . . . . . 3.34 ImgMotion . . . . . . . . . . 3.35 ImgDIC . . . . . . . . . . . . 3.36 ImgHistogram . . . . . . . . . 3.37 ImgHistoEqu . . . . . . . . . 3.38 ImgClampExtreme . . . . . . 3.39 ImgThre TwoPeak . . . . . . 3.40 ImgThre IterSel . . . . . . . . 3.41 ImgDilation . . . . . . . . . . 3.42 ImgErosion . . . . . . . . . . 3.43 ImgProjX . . . . . . . . . . . 3.44 ImgProjY . . . . . . . . . . . 3.45 ImgProjAny . . . . . . . . . . 3.46 ImgRadon . . . . . . . . . . . 3.47 ImgRadonVH . . . . . . . . . 3.48 ImgBackprojVH . . . . . . . 3.49 ImgIntegral . . . . . . . . . . 3.50 ImgLabeling . . . . . . . . . . 3.51 ImgFilling . . . . . . . . . . . 3.52 ImgThinning . . . . . . . . . 3.53 ImgCentroid . . . . . . . . . . 3.54 ImgBoundaryOrdered . . . . 3.55 ImgBoundaryUnordered . . . 3.56 ImgOuterCorners . . . . . . . 3.57 ImgConvexHull . . . . . . . . 3.58 ImgBoundingBox . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

31 31 31 32 32 32 32 33 33 33 34 34 35 35 35 35 35 35 35 36 36 37 37 37 38 38 39 39 40 40 41 42 42 43 43 44 45 46 46 46 47 47 47 48 48 48 49 49 50 50 51 51 52 52 53 53 53 54 54

2

3.59 3.60 3.61 3.62 3.63 3.64 3.65 3.66 3.67 3.68 3.69 3.70 3.71 3.72 3.73 3.74 3.75 3.76 3.77 3.78 3.79 3.80 3.81 3.82 3.83 3.84 3.85 3.86 3.87 3.88 3.89 3.90 3.91 3.92 3.93 3.94

ImgMinBoundingBox . . . ImgMinBoundingCircle . ImgMinBoundingPolygon ImgDistTrans . . . . . . . ImgWatershed . . . . . . ImgEdgeX . . . . . . . . . ImgEdgeY . . . . . . . . . ImgEdgeXSubpixel . . . . ImgEdgeYSubpixel . . . . ImgEdgeAny . . . . . . . ImgEdgeOnLine . . . . . ImgCannyEdge . . . . . . ImgShenCastanEdge . . . ImgFitPlane . . . . . . . . ImgFitPolynomialSurf . . ImgFitGauss . . . . . . . ImgFitImg . . . . . . . . . ImgLineData . . . . . . . ImgLineSum . . . . . . . ImgContour . . . . . . . . ImgMask . . . . . . . . . ImgMaskPolygon . . . . . ImgMandelbrot . . . . . . ImgPhaseShifting . . . . . ImgPhaseShifting Carre . ImgPhaseShifting 5Frame ImgPhaseUnw LToR . . . ImgPhaseUnw QualGui . ImgPhaseGradVar . . . . ImgFaceDetection . . . . . ImgSquareDetection . . . ImgBlackSquareGrid . . . ImgReadASCII . . . . . . ImgSaveASCII . . . . . . ImgReadRaw . . . . . . . ImgSaveRaw . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

54 55 55 55 55 56 57 57 57 57 58 59 59 59 60 60 61 61 61 61 62 62 63 63 64 64 65 65 65 66 66 66 67 68 68 68 69 69 69 70 71 72 73 73 74 74 74 75 75 75 75 75 75 76 76 77

4 3D geometry classes and functions 4.1 CPt3D: 3D point class . . . . . . . 4.2 CSize3D: 3D size class . . . . . . . 4.3 CLine3D: 3D line segment class . . 4.4 CCube: cube class . . . . . . . . . 4.5 CTri3D: 3D triangle class . . . . . 4.6 CPoly3D: 3D polygon class . . . . 4.7 CCylinder: cylinder class . . . . . 4.8 Distance . . . . . . . . . . . . . . . 4.9 Area . . . . . . . . . . . . . . . . . 4.10 Angle . . . . . . . . . . . . . . . . 4.11 MidPoint . . . . . . . . . . . . . . 4.12 Centroid . . . . . . . . . . . . . . . 4.13 Collinear . . . . . . . . . . . . . . . 4.14 NormalVector . . . . . . . . . . . . 4.15 Volume . . . . . . . . . . . . . . . 4.16 ConvexHull3D . . . . . . . . . . . 4.17 FitPlane . . . . . . . . . . . . . . . 4.18 FitPolynomialSurf . . . . . . . . . 4.19 FitGauss . . . . . . . . . . . . . . .

3

5 3D image processing functions 5.1 ImgAssign3D . . . . . . . . . 5.2 ImgCopy3D . . . . . . . . . . 5.3 ImgCopyXY 2D . . . . . . . 5.4 ImgCopyXZ 2D . . . . . . . . 5.5 ImgCopyYZ 2D . . . . . . . . 5.6 ImgCopy2D XY . . . . . . . 5.7 ImgCopy2D XZ . . . . . . . . 5.8 ImgCopy2D YZ . . . . . . . . 5.9 ImgLinear3D . . . . . . . . . 5.10 ImgMin3D . . . . . . . . . . . 5.11 ImgMax3D . . . . . . . . . . 5.12 ImgMinMax3D . . . . . . . . 5.13 ImgMean3D . . . . . . . . . . 5.14 ImgFltMean3D . . . . . . . . 5.15 ImgFltVariance3D . . . . . . 5.16 ImgConv3DZ . . . . . . . . . 5.17 ImgResize3D . . . . . . . . . 5.18 ImgRotate3D . . . . . . . . . 5.19 ImgFlip3D . . . . . . . . . . . 5.20 ImgMatch3D . . . . . . . . . 5.21 ImgMotion3D . . . . . . . . . 5.22 ImgLabeling3D . . . . . . . . 5.23 ImgFilling3D . . . . . . . . . 5.24 ImgDistTrans3D . . . . . . . 5.25 ImgWatershed3D . . . . . . . 5.26 ImgIsoSurface . . . . . . . . . 5.27 ImgReadRaw3D . . . . . . . 5.28 ImgSaveRaw3D . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

78 78 78 78 78 79 79 79 79 79 80 80 80 80 80 80 81 81 81 82 82 82 83 84 84 84 85 85 86

4

w. The following code shows an example.h and *.f). such as Visual Studio C++ and g++. To use the library. Most of the image processing functions in the library are relatively independent.\n".h" #if !USE_PRECOMPILED_HEADER #include <iostream> #include <vector> using namespace std.h-20)).cpp files (ImgProc2D. all you need to do is to generate two explicit template instantiations of a library function.cpp and svdcmp.0. you will be familiar with what to supply to a function and what can be expected from the output. CRect<int>(0.h. for example. h = 512. w.) Flexibility.h).cpp) should be compiled.3. 1. Based on C++ template mechanism.cpp. cout<<"ImgCopy done. 100. standard template library (STL).f). Util.cpp. h.1 Features There are a variety of image processing libraries available from the internet. you should write “using namespace CLJ. #endif #include "ImgProc2D. Shape3D. (Many image processing libraries define their specific image class and data structure conversion is required.h and / or ImgProc3D. Documentation is also attached in the source code. vI2D2(w*h). 1. Independency. CRect<int>(20. CRect<int>(0. h. &vI2D2[0]. w. w. h. lubksb. It is important to know that the library classes and functions are defined in a CLJ namespace. Input and output of all functions are systemically organized.h.cpp. and ImgProc3D. Simplicity.h). ImgAssign(&vI2D1[0]. ImgCopy(&vI2D1[0]. Readability. however.”.h should be included in whichever file that uses the library.1 Introduction C++. all . above each function’s definition. #include "PreCompiled. and therefore after including ImgProc2D.0. The library does not rely on any particular image class so that you can keep your data structure unchanged.w.cpp.10. code reading is not required for using the library.20. 50. pythag. The library is written in ANSI C++. Combination of some functions may achieve sophisticated processing tasks. cout<<"ImgAssign done. Shape2D. A complete package of the library files (*. and image processing: each of the areas is a big topic by itself.cpp. The highlight of this library lies in the following features.cpp. This note aims to explore the interrelationship and document an image processing library in C++. ludcmp.h. w.com. It can be compiled by many compilers. the library accepts all C++ build-in types as the image data. computer graphics. ImgProc3D. while they are indeed interrelated.\n". Readers are encouraged to exam the source code where brief comments can be found explaining the implementation. and ImgProc3D. Following a few examples.cpp) may be requested from iiuufigtt@gmail. CRect<int>(10. which may induce considerable processing overhead. If you have integer and float image data to process.cpp. h. The note focuses on the input and output parameters of the library functions with some concise background information. Two header files ImgProc2D.h. vector<float> vI2D1(w*h).h-10). although certain functions are only valid to a subset of build-in types. It is a standard C++ technique and will be discussed in detail in Section 1. The rest of the header files are included automatically in ImgProc2D. Portability. int main() { int w = 256. 5 .w-10.w-20.2 Source files The source files of the library are listed in Table 1. ImgAssign(&vI2D2[0].h" using namespace CLJ.

some C++ library headers are conditionally included by #define USE_PRECOMPILED_HEADER 1 (use precompilation) or #define USE_PRECOMPILED_HEADER 0 (not use precompilation). template class CRect<float>.cpp pythag...h Util. int w.cpp and . const CRect<int> &rcROI.cpp and . If you use the precompilation feature of your C++ compiler.cpp files. you may simply #define USE_PRECOMPILED_HEADER 0 1. The library’s “explicit template instantiation” is put at the end of each cpp file.. int h2. where you can find some code like: // Code in Shape2D. There is a header file.). ASSERT(.) macro is the same as the C++ library function assert(. This procedure is standard to making use of precompilation. int h1. it does nothing.cpp template class CPt2D<int>.cpp files.cpp.cpp as the precompiled source file of your project. (Include PreCompiled. Basically.h nr.3 Explicit template instantiation An issue associated with using template functions and template classes is “explicit template instantiation”. PreCompiled. float> (const char *pSrc. then make PreCompiled. However. float *pDst.. #include "PreCompiled. template class CPt2D<float>.return 0.) Create a new file called PreCompiled.cpp and .h Shape2D. if you want to use a template function or a template class in a particular data type (for example: float).h as the precompiled header of all your . const CRect<int> &rcROI1.cpp and .cpp Description 2D image processing functions 3D image processing functions 2D geometry classes and functions 3D geometry classes and functions Description precompiled header file utility functions source and header file header file of all ”Numerical Recipes” functions data types defined in ”Numerical Recipes” utilities of ”Numerical Recipes” a ”Numerical Recipes” function a ”Numerical Recipes” function a ”Numerical Recipes” function a ”Numerical Recipes” function Table 1: Source files of the library. int h. If DEBUG is defined.) macro used by the library for error reporting.h.cpp template void ImgAssign<unsigned char> (unsigned char *pImg. included at the first line of all . In PreCompiled. which should be obvious to people who are familiar with compiler settings.cpp and . which contains just one line of code. template void ImgCopy<unsigned char. template void ImgCopy<char.h ImgPro3D. const CRect<int> &rcROI2).h lubksb. if you are confused..h nrutil nr.h Shape3D. float> 6 . unsigned char value). // Code in ImgProc2D. otherwise. It defines the ASSERT(.h.h" Make PreCompiled. there should be an explicit template function or class instantiation of that type (float).cpp ludcmp.h Support files PreCompiled. template class CRect<int>.h at the first line of all your . } Main files ImgPro2D.. int w2.cpp svdcmp. int w1.h nrtypes nr.cpp files.

y<h. int h1. for(y=0. and ’d’. 7 . float fRatio = 1.f.4 Coding style Clear and easy-to-follow coding styles and naming conventions are used in the library. ++x) pfImg[y*w+x] = 3. const CRect<int> &rcROI2). ’i’. A one. ++y) for(x=0. A pointer variable is prefixed by ’p’. Example 2 (loop through an image) int x. otherwise you will get compiler errors. const CRect<int> &rcROI1. int nCount. ’j’ et al. Example 1 (naming conventions) char *pcName = ”Mary”. float *pfImg = new float[w*h]. w = 100. ’y’. indicates the data type. int w1. x<w. unsigned char ucRed = 24. 1. ’z’. double dRadius = 30. int w2. 3. int h2.f.or two-letter prefix. such as ’uc’. you can add an instantiation following the above coding style. 2. General purpose integer variables are usually defined as ’x’. If you need a build-in data type of a specific class or function that has not been instantiated.(const unsigned char *pSrc. ’c’. ’n’. y. 1. h = 50. float *pDst.

0) is located at the left-top corner of an image (or a window. }. The positive X axis extends horizontally to the right and the positive Y axis extends vertically downward. CPt2D<T> &pt).2 2D geometry classes and functions The coordinate system of the library (see Fig. Variable x y Function operator = operator + = operator − = operator + operator − operator == operator != Function SetPoint Rotate Description x coordinate of the point y coordinate of the point Description Assignment operator *this = *this + pt *this = *this − pt Return *this + pt Return *this − pt Check if *this is equal to pt Check if *this is not equal to pt Description Set the x and y coordinates of the point Rotate the point with respect to a point 8 . CPt2D<T> &pt) const. y(0) { } CPt2D<T>(const CPt2D<T> &pt) CPt2D<T>(T tx. CPt2D<T> &pt) const. y. 0 100 200 Y 0 100 200 X Figure 1: Coordinate system of the image processing library. y(pt. CPt2D<T> &pt) const. or the computer screen). CPt2D<T>() : x(0).(const bool operator == (const bool operator != (const : x(pt. T ty) CPt2D<T>& operator = (const CPt2D<T>& operator += (const CPt2D<T>& operator -= (const CPt2D<T> operator + (const CPt2D<T> operator .y) { } : x(tx). y(ty) { } CPt2D<T> &pt). T ty) { x = tx.1 CPt2D: 2D point class template <class T> class CPt2D { public: T x. The origin (0. CPt2D<T> &pt) const. CPt2D<T> &pt). 2. An anticlockwise angle with respect to the X axis is defined as positive.x). } void Rotate(const CPt2D<T> &ptRot. double dAngle). void SetPoint(T tx. y = ty. 1) follows the most widely used convention in computer graphics.

const CPt2D<T> &ptEnd).cy) { } CSize2D<T>(T tcx.0) { } CLine2D<T>(const CLine2D<T> &line). Variable cx cy Function operator = operator + = operator − = operator + operator − operator == operator != Description size in x direction size in y direction Description Assignment operator *this = *this + size *this = *this − size Return *this + size Return *this − size Check if *this is equal to size Check if *this is not equal to size 2. CLine2D<T>& operator = (const CLine2D<T> &line). bool operator != (const CSize2D<T> &size) const.2. CSize2D<T>& operator += (const CSize2D<T> &size). CSize2D<T> operator . T y2). T y1. CSize2D<T> operator + (const CSize2D<T> &size) const. BoundingRect() const.cx). T x2. 9 . SetStart (const CPt2D<T> &pt). SetEnd (T x. Length() const. cy(0) { } CSize2D<T>(const CSize2D<T> &size) : cx(size.2 CSize2D: 2D size class template <class T> class CSize2D { public: T cx. T y). SetLine (T x1. End() const. cy(size. SetLine (const CPt2D<T> &ptStart. T y2). T tcy) : cx(tcx). CLine2D<T>(const CPt2D<T> &ptStart. m_ptEnd(0. void SetSize(T tcx. T tcy) { cx = tcx. Center() const. T x2. cy = tcy. CSize2D<T>() : cx(0).0). SetStart (T x. T y). SetCenter (const CPt2D<T> &pt). T y1.(const CSize2D<T> &size) const.3 CLine2D: 2D line segment class template <class T> class CLine2D { public: CLine2D<T>() : m_ptStart(0. SetEnd (const CPt2D<T> &pt). bool operator == (const CSize2D<T> &size) const. } }. bool operator != (const CLine2D<T> &line) const. CLine2D<T>(T x1. CPt2D<T> CPt2D<T> CPt2D<T> CRect<T> double double void void void void void void void Start() const. const CPt2D<T> &ptEnd). cy(tcy) { } CSize2D<T>& operator = (const CSize2D<T> &size). Angle() const. cy. bool operator == (const CLine2D<T> &line) const. CSize2D<T>& operator -= (const CSize2D<T> &size).

or the center. Offset (const CPt2D<T> &ptOffset). double y) const. GetPointAt(double dDist. Given a point’s x coordinate on the line. one can fix the start point. CPt2D<T> *ppt) const. m_ptEnd. DistToPt (double x. DistToPt (const CPt2D<T> &pt) const. GetY (T x. the new length of the line. To modify the line length. Set the length of the line. Function operator = operator == operator != Function Start End Center BoundingRect Angle Length SetLine SetStart SetEnd SetCenter SetAngle Description Assignment operator Check if *this is equal to line Check if *this is not equal to line Description Get the start point of the line Get the end point of the line Get the center of the line Get the bounding box of the line Get the angle formed by the line and the positive X axis Get the length of the line Set the start and the end points of the line Set the start point of the line Set the end point of the line Set the center of the line Set the angle of the line The line is rotated with respect to ptRot to the specified angle. 0: the start point of the line is fixed. Offset Rotate DistToPt SetLength dLength nFix GetY x pY Return 10 . double dAngle). 2: the end point of the line is fixed. get its corresponding y coordinate. If the line segment’s start and end points are different. return the distance from an input point to the line’s end point. private: CPt2D<T> m_ptStart. double *pdC) const. SetLength (double dLength. input x coordinate output y coordinate true: y coordinate found. the line will be extended in the x direction only. // start and end point }. Rotate (const CPt2D<T> &ptRot. which is derived from the line segment. int nFix). Offset (T x. which should be >= 0. formed by the line and the positive X axis. If the start point and the end point are the same. double dAngle). return the distance from an input point to the line.void void void void void double double bool bool bool SetAngle (const CPt2D<T> &ptRot. the end point. LineEqu (double *pdA. Offset the position of the line Rotate the line with respect to a point Get the distance from a point to the line If the line segment is a point (the start and end points are the same). 1: the center of the line is fixed. nFix specifies which point to fix. The angle of the line is always fixed. double *pdB. false: cannot find y coordinate. T *pY) const. T y).

T r. Based on the line segment. CRect<T> operator & (const CRect<T>& rect) const. CRect<T>(const CPt2D<T> &ptLeftTop. right. parameter A of the line equation parameter B of the line equation parameter C of the line equation true: line function found. Take the start point as a reference. However. Another choice is: cos(angle)*x + sin(angle)*y = R. CPt2D<T> RightBottom(). CRect<T> operator | (const CRect<T>& rect) const. const CSize2D<T> &size). 2. CPt2D<T> RightTop(). bottom. the point found true: point found. CRect<T>& operator &= (const CRect<T>& rect). it involves relatively slow trigonometric computation. CPt2D<T> LeftTop(). bool IsEmpty(). bottom(0) { } CRect<T>(const CRect<T> &rect). CPt2D<T> LeftBottom(). CRect<T>& operator |= (const CRect<T>& rect). so it is not used. T r.GetPointAt dDist ppt Return LineEqu Get a point on the line that has a specified distance from the star point. retrieve a line equation in the form: A*x + B*y = C. CRect<T>& operator = (const CRect<T>& rect). bool operator != (const CRect<T>& rect) const. const CPt2D<T> &ptRightBottom). T Height(). bool operator == (const CRect<T>& rect) const. the distance of the point from the start point.4 CRect: rectangle class template <class T> class CRect { public: T left. CSize2D<T> Size(). 11 . pdA pdB pdC Return 0 100 200 Y 0 100 200 X start point angle end point Figure 2: An example of a 2D line segment. T b). CRect<T>() : left(0). top. false: line function not exist. right(0). T t. T b). CRect<T>(T l. dDist > 0 indicates the point is at the same side as the end point. CRect<T>(const CPt2D<T> &ptLeftTop. top(0). T t. CPt2D<T> Center(). This line equation encompasses all possible situations. false: cannot find such a point. T Width(). void SetRect(T l. while dDist < 0 indicates the point is at the opposite side of the end point.

swap left and right. T b). right. Check if a rectangle is completely inside or on *this. &rc) const.5 CRectRot: rotating rectangle class template <class T> class CRectRot { 12 . Inflate(T x. t. Variable left top right bottom Function operator = operator &= operator |= operator & operator | operator == operator != Function IsEmpty Width Height Size Center LeftTop RightTop LeftBottom RightBottom Function SetRect Inflate Description left bound of the rectangle top bound of the rectangle right bound of the rectangle bottom bound of the rectangle Description Assignment operator *this = Intersect of two rectangles *this = Union of two rectangles Return intersect of two rectangles Return union of two rectangles Check if *this is equal to rect Check if *this is not equal to rect Description Check if it is an empty rectangle. If lef t > right.void void void void void void bool bool bool void }. b on the left. Get the width (right − lef t) of the rectangle Get the height (bottom − top) of the rectangle Get the size of the rectangle Return the center of the rectangle Return the left-top point of the rectangle Return the right-top point of the rectangle Return the left-bottom point of the rectangle Return the right-bottom point of the rectangle Description Set the left. T y). T t. &pt). swap top and bottom. top. Deflate Offset PtIn RectIn Normalize 2. A point is side a rectangle. T y). Inflate(T l. T y). right and bottom value of the rectangle Inflate the rectangle by l.y ∈ [top. T r. if pt. b on the left. Make sure the rectangle has positive width and height. Deflate(T x.x ∈ [lef t. r. Offset (const CPt2D<T> PtIn (T x. A rectangle is empty if its width or height is <= 0. Deflate the rectangle by x on the left and right sides and by y on the top and bottom sides respectively. const. T b). T y) PtIn (const CPt2D<T> RectIn (const CRect<T> Normalize(). T r. Deflate the rectangle by l. Offset (T x. If top > bottom. r. Deflate(T l. top. Offset the position of the rectangle Check if a point is inside the rectangle. Inflate the rectangle by x on the left and right sides and by y on the top and bottom sides respectively. and bottom sides respectively. &pt) const. right. T t. right) AND pt. top. bottom). and bottom sides respectively. t.

PtIn (const CPt2D<T> &pt) const. anticlockwise in radius Set the width of the rectangle Set the height of the rectangle Set the center of the rectangle Set the angle of the rectangle. CRectRot<T>(const CPt2D<T> &ptCenter. SetAngle (double dAngle). Height() const. double dAngle = 0). double dAngle = 0). double dAngle). CRectRot<T>(const CPt2D<T> &ptCenter. Width() const. CRectRot<T>(T x. // // // // center of the width of the height of the anticlockwise rectangle rectangle rectangle angle (radius) of the rectangle Function operator = Width Height Center Angle SetWidth SetHeight SetCenter SetAngle Corner Description Assignment operator Get the width of the rectangle Get the height of the rectangle Get the center of the rectangle Get the angle of the rectangle. T height. m_height(0). m_ptCenter. T y). Center() const. T width.0). anticlockwise in radius Get 4 corner points of the rectangle continued on next page 13 . Deflate(T w. public: CRectRot<T>() : m_ptCenter(0. m_width. T height. m_height. m_dAngle(0) { } CRectRot<T>(const CRectRot &rectRot). double dAngle = 0). Offset (T x. BoundingRect() const. T width. Corner(CPt2D<T> ppt[4]) const. double dAngle = 0). m_dAngle. CSize2D<T> size. SetHeight(T height). SetCenter(const CPt2D<T> &ptCenter).0 100 0 100 200 top X left 200 Y bottom right Figure 3: An example of a rectangle. T y). CRectRot<T>& operator = (const CRectRot &rectRot). PtIn (T x. T h). Offset (const CPt2D<T> &ptOffset). T h). T y. CRectRot<T>(const CRect<T> &rect. Rotate (const CPt2D<T> &ptRot. const. Inflate(T w. m_width(0). T T CPt2D<T> double void void void void void CRect<T> void void void void int int void private: CPt2D<T> T T double }. Angle() const. SetWidth (T width).

Decreasing the width and height by w and h respectively. const.6 CFan: fan shape class template <class T> class CFan { public: CFan<T>() : m_ptCenter(0. // // // // center of the radius of the anticlockwise anticlockwise fan fan angle (radius) of the fan start angle (radius) 14 . m_Radius(0). SetStartPoint(const CPt2D<T> &pt). double dAngle). SetStartAngle(double dAngle). Rotate(const CPt2D<T> &ptRot. Offset the position of the rectangle Check if a point is inside the rectangle Rotate the rectangle with respect to a point 0 100 200 Y 0 100 200 wi dth X angle Figure 4: An example of a rotating rectangle.BoundingRect Inflate Deflate Offset PtIn Rotate Get the bounding box of the rectangle Increasing the width and height by w and h respectively. FanAngle() const. CFan<T>(const CPt2D<T> &ptCenter. T radius. m_dFanAngle(0). CFan<T>& operator = (const CFan &fan). Radius() const. SetRadius(T radius). SetCenter(const CPt2D<T> &ptCenter). SetEndPoint (const CPt2D<T> &pt).0). T y). Offset(const CPt2D<T> &ptOffset). m_Radius. BoundingRect() const. PtIn (const CPt2D<T> &pt) const. EndPoint() const. CPt2D<T> T double double CPt2D<T> CPt2D<T> void void void void void void CRect<T> void void int int void private: CPt2D<T> T double double }. PtIn (T x. m_dStartAngle. Offset(T x. CFan<T>(T x. StartAngle() const. double dFanAngle. m_dFanAngle. t igh he center 2. T radius. m_ptCenter. double dStartAngle). SetFanAngle (double dAngle). T y). m_dStartAngle(0) { } CFan<T>(const CFan &fan). double dStartAngle). StartPoint() const. Center() const. T y. double dFanAngle.

which is the center of the full circle. anticlockwise in radius Set the start angle of the fan. T y). CPt2D<T> T void void CRect<T> void void int int void Center() const Radius() const SetCenter(const CPt2D<T> &pt) SetRadius(T radius) BoundingRect() const. PtIn (const CPt2D<T> &pt) const.Function operator = Center Radius FanAngle StartAngle StartPoint EndPoint SetCenter SetRadius SetFanAngle SetStartAngle SetStartPoint SetEndPoint BoundingRect Offset PtIn Rotate Description Assignment operator Get the center of the fan. Get the radius of the fan Get the angle of the fan. Rotate(const CPt2D<T> &ptRot. private: CPt2D<T> m_ptCenter. CCircle<T>(const CPt2D<T> &ptCenter. // radius of the circle }. Offset(T x. // center of the circle T m_Radius. 2. Offset(const CPt2D<T> &ptOffset). anticlockwise in radius Get the start angle of the fan. PtIn (T x. T radius) CCircle<T>& operator = (const CCircle<T> &circle). T y) const.7 CCircle: circle class template <class T> class CCircle { public: CCircle<T>() : m_ptCenter(0. T y. double dAngle). 15 .0). T radius) CCircle<T>(T x. anticlockwise in radius Set the start point of the fan Set the end point of the fan Get the bounding box of the fan Offset the position of the fan Check if a point is inside the fan Rotate the fan with respect to a point 0 100 end point ra 0 100 200 X start point fan angle start angle di us 200 Y center Figure 5: An example of a fan. anticlockwise in radius Get the start point of the fan Get the end point of the fan Set the center of the fan Set the radius of the fan Set the angle of the fan. m_Radius(0) { } CCircle<T>(const CCircle<T> &circle).

Function operator = Center Radius SetCenter SetRadius BoundingRect Offset PtIn Rotate Description Assignment operator Get the center of the circle Get the radius of the circle Set the center of the circle Set the radius of the circle Get the bounding box of the circle Offset the position of the circle Check if a point is inside the circle Rotate the circle with respect to a point 0 100 200 X 0 100 200 Y radius center Figure 6: An example of a circle. m_height. CSize2D<T> size. SetHeight(T height). CEllipse<T>& operator = (const CEllipse &ellipse). T width. Offset(const CPt2D<T> &ptOffset). SetEqu(const double pdCoe[5]). CEllipse<T>(const CPt2D<T> &ptCenter. T T CPt2D<T> double void void void void double CRect<T> void void int int void bool private: CPt2D<T> T T double }. double dAngle = 0). T y). const. T height. m_dAngle(0) { } CEllipse<T>(const CEllipse &ellipse). CEllipse<T>(const CPt2D<T> &ptCenter. PtIn (const CPt2D<T> &pt) const. Center() const. T y). Rotate(const CPt2D<T> &ptRot. Height() const. T height. m_width(0). BoundingRect() const.8 CEllipse: ellipse class template <class T> class CEllipse { public: CEllipse<T>() : m_ptCenter(0. T width. m_width. Offset(T x. CEllipse<T>(T x. double dAngle = 0). double dAngle = 0). m_ptCenter. T y. SetWidth (T width). SetAngle (double dAngle). m_dAngle. // // // // center of the width of the height of the anticlockwise ellipse ellipse ellipse angle (radius) of the ellipse 16 . m_height(0). 2. SetCenter(const CPt2D<T> &ptCenter). DistToFoci(const CPt2D<T> &pt) const. double dAngle). PtIn (T x.0). Width() const. Angle() const.

InsertVertex(int idx. Offset(T x. 0 100 200 Y 0 100 200 wi dth X angle Figure 7: An example of an ellipse. int int const CPt2D<T>& void void void void void void CPt2D<T> CRect<T> void Assign(const vector<CPt2D<T> > &vpt). RemoveNearbyVertices(double dDist). AddVertex ( const CPt2D<T> &pt). RemoveVertex(int idx). false: the input equation is not an ellipse equation and no change is made. of the ellipse equation true: succeeded. Vertex(int idx) const. T y). 17 . CPoly2D<T>(const CPt2D<T> *ppt. BoundingRect() const. A. anticlockwise in radius Set the width of the ellipse Set the height of the ellipse Set the center of the ellipse Set the angle of the ellipse. const CPt2D<T> &pt). const CPt2D<T> &pt). Center() const.9 CPoly2D: 2D polygon class template <class T> class CPoly2D { public: CPoly2D<T>() { } CPoly2D<T>(const CPoly2D<T> &poly). SetVertex (int idx. int nCount) CPoly2D<T>& operator = (const CPoly2D<T> &poly). B. Clear(). he igh t center 2. C. CPoly2D<T>(const vector<CPt2D<T> > &vpt) CPoly2D<T>(int nCount. D and E. const CPt2D<T> &pt). anticlockwise in radius Get the distance of a point to the two foci of the ellipse Get the bounding box of the ellipse Offset the position of the ellipse Check if a point is inside the ellipse Rotate the ellipse with respect to a point Set the ellipse based on an equation Ellipse equation: Ax2 + Bxy + Cy 2 + Dx + Ey = 1 parameters. Count() const.Function operator = Width Height Center Angle SetWidth SetHeight SetCenter SetAngle DistToFoci BoundingRect Offset PtIn Rotate SetEqu pdCoe Return Description Assignment operator Get the width of the ellipse Get the height of the ellipse Get the center of the ellipse Get the angle of the ellipse.

18 . AddKnot ( const CPt2D<T> &pt). CLSpl<T>& operator = (const CLSpl<T> &lspl). InsertKnot(int idx. RemoveKnot(int idx). int nCount). which makes sure that the length of each edge is >= dDist. // vertices of the polygon }. BoundingRect() const. T y). Knot(int idx) const. SetKnot (int idx. Remove all vertices of the polygon Get the centroid of the polygon Get the bounding box of the polygon Offset the position of the polygon Check if a point is inside the polygon Rotate the polygon with respect to a point 0 100 v1 v6 200 Y v2 v3 v5 v4 200 v0 X 0 100 Figure 8: An example of a polygon. 2. Rotate(const CPt2D<T> &ptRot. T y) const. Center() const. const CPt2D<T> &pt). double dAngle). int const CPt2D<T>& void void void void void CPt2D<T> CPt2D<T> void Count() const.void int int void Offset(const CPt2D<T> &ptOffset). const CPt2D<T> &pt).10 CLCSpl: a linear spline class template <class T> class CLSpl { public: CLSpl<T>() { } CLSpl<T>(const CLSpl<T> &lspl). Clear(). CLSpl<T>(const CPt2D<T> *ppt. CLSpl<T>(const vector<CPt2D<T> > &vpt). Function operator = Count Vertex AddVertex SetVertex InsertVertex RemoveVertex RemoveNearbyVertices Clear Center BoundingRect Offset PtIn Rotate Description Assignment operator Get the number of vertices of the polygon Get the idx-th vertex of the polygon Add a vertex at the end of the vertex list Set the idx-th vertex value Insert a vertex at idx position of the vertex list Remove the idx-th vertex from the vertex list Remove vertices too close together. PtIn (const CPt2D<T> &pt) const. Offset(T x. PtIn (T x. private: vector<CPt2D<T> > m_vpt.

Offset(T x. Rotate(const CPt2D<T> &ptRot. CPt2D<T> *ppt) const. 2. Center() const. SetKnot (int idx. private: vector<CPt2D<T> > m_vpt. RemoveKnot(int idx). double dFra. const CPt2D<T> &pt).11 CNCSpl: a natural cubic spline class template <class T> class CNCSpl { public: CNCSpl<T>() { } CNCSpl<T>(const CNCSpl<T> &ncspl). double dAngle). Offset(const CPt2D<T> &ptOffset).void void Offset(const CPt2D<T> &ptOffset). Clear(). Rotate(const CPt2D<T> &ptRot. Description Assignment operator Get the number of knots of the spline continued on next page Function operator = Count 19 . double dAngle). const CPt2D<T> &pt). InsertKnot(int idx. AddKnot ( const CPt2D<T> &pt). Function operator = Count Knot AddKnot SetKnot RemoveKnot Clear Center Offset Rotate Description Assignment operator Get the number of knots of the spline Get the idx-th knot of the spline Add a knot to the knot list Set the idx-th knot value Remove the idx-th knot from the knot list Remove all knots of the spline Get the centroid of all knots Offset the position of all knots Rotate the spline with respect to a point 0 100 200 Y 0 100 k0 k4 200 k1 k5 k2 k3 X Figure 9: An example of a linear spline. int CPt2D<T> void void void void void CPt2D<T> void void void bool }. Knot(int idx) const. Count() const. CNCSpl<T>& operator = (const CNCSpl<T> &ncspl). // knots of the spline }. GetPointAt(int nSec. T y).

y[i]). in that case ppt is unchanged. 0 k0 100 k1 k5 200 Y k4 k3 200 k6 k7 k2 X ppt Return 0 100 Figure 10: An example of a natural cubic spline. dFra can also be set < 0 or > 1. returns the start point (x[i]. y). y[i+1]). Description pt1 pt2 Return Get the distance between two points 1st input point 2nd input point the distance between the two points 0 100 200 X 0 100 200 Y distan pt1 ce pt2 Figure 11: An example of the Distance function. double dB. double dA.7*x[i]+0. double dC). 20 . returns the point (0. y is calculated from the spline. fFraction = 0. fFraction = 0. returns the end point (x[i+1].3*x[i+1]. fFraction = 1.12 Distance template <class T> double Distance (const CPt2D<T> &pt1. Distance between two points.Knot AddKnot SetKnot RemoveKnot Clear Center Offset Rotate GetPointAt nSec dFra Get the idx-th knot of the spline Add a knot to the knot list Set the idx-th knot value Remove the idx-th knot from the knot list Remove all knots of the spline Get the centroid of all knots Offset the position of all knots Rotate the spline with respect to a point Get a point at a specified place on the spline the index of the section of the spline For example: i is the section between knot i and knot i+1. fractional distance [0.3. template <class T> double Distance (const CPt2D<T> &pt. const CPt2D<T> &pt2). 1] from the point to the start point of the section in x direction. stores output point if found true: point found. the point’s x coordinate is < x[i] or > x[i+1]. In these cases. false: spline is not valid or nSec out of range. 2. For example: assume i-th section is chosen.

(a) Positive area. pt3 are clockwise. const CPt2D<T> &pt2.13 Area2 template <class T> double Area2 (const CPt2D<T> &pt1. pt3 angle > 0 indicates pt1. 2.Description pt dA. pt1. angle = 0 or π indicates three points are on the same line. area = 0 indicates three points are on the same line. area > 0 indicates pt1. pt2. angle < 0 indicates pt1. const CPt2D<T> &pt2. area < 0 indicates pt1. pt3 are clockwise. formed by pt2. π]. const CPt2D<T> &pt3). pt3 1st input point (vertex of the angle) 2nd input point 3rd input point the angle formed by pt2. 21 . dC Return Get the distance between a point and a line The line equation is A*x + B*y = C. pt3 are anticlockwise. pt1. (b) Negative area. pt2. dB. input point parameters of the line the distance between the point and the line 0 0 line pt 200 Y dista nce 100 200 X 100 Figure 12: An example of the Distance function. Description pt1 pt2 pt3 Return Get twice the area enclosed by three points 1st input point 2nd input point 3rd input point twice the area enclosed by three points Use double type to prevent overflow. const CPt2D<T> &pt3). pt3 are anticlockwise. pt2. 0 100 200 pt2 100 pt3 200 Y pt1 200 Y pt3 100 pt1 X 0 100 200 pt2 X 0 0 (a) (b) Figure 13: An example of the Area2 function. Distance between a point and a line. pt2. 2. Description pt1 pt2 pt3 Return Get the angle in (−π.14 Angle template <class T> double Angle (const CPt2D<T> &pt1.

true: intersect found. double dB1.15 MidPoint template <class T> CPt2D<T> MidPoint (const CPt2D<T> &pt1. Description dA1. (b) Negative angle. if found. double dC2. otherwise. CPt2D<double> *ppt). 2. double dC1. dC1 dA2. double dB2. const CPt2D<T> &pt2). CPt2D<double> *ppt). its value is unchanged. double dC2. (a) Positive angle.16 Centroid template <class T> CPt2D<T> Centroid (const CPt2D<T> *ppt. double dA2. otherwise. Description ppt nCount Return Get the centroid of a set of points an array of points the number of points the centroid of the input points 2. double dB2.17 Intersect template <class T> bool Intersect (const CLine2D<T> &line1. dC2 ppt Return Get the intersect of two lines Line equation: A*x + B*y = C parameters of the 1st input line parameters of the 2nd input line store point of intersection. if found. (double dA2. const CLine2D<T> &line2. false: no intersect. false: no intersect. dB1. CPt2D<double> *ppt). Description pt1 pt2 Return Get the midpoint of two points 1st input point 2nd input point the midpoint 2. int nCount). dB2. its value is unchanged. 22 . bool Intersect (double dA1.0 100 0 100 200 pt3 X 0 100 pt1 0 100 200 pt2 X pt1 200 Y pt3 200 Y pt2 (a) (b) Figure 14: An example of the Angle function. true: intersect found. template <class T> bool Intersect (const CLine2D<T> &line1. Description line1 line2 ppt Return Get the intersect of two line segments 1st input line segment 2nd input line segment store point of intersection.

false: the line does not intersect with the rect. right) and y within [top. (a) Two line segments intersect. otherwise its value is unchanged. double dC. true: the line is cut in the rect. right] and y within [top. Description Cut a line within a rectangle A line is cut to fit inside a rect. rect dA. false: no intersect. which means a point’s x is within [left. which means a point’s x is within [left. you may use the integer version of the function. CLine2D<int> *pLine). dC pLine Return bool CutLineInRect(const CRect<int> &rect. Note that the right and bottom border are not “inside”. 100 200 X 0 100 200 X 0 100 200 Y 0 100 200 Y (a) (b) Figure 15: An example of the Intersect function. otherwise its value is unchanged. double dB.19 BoundingRect template <class T> CRect<T> BoundingRect (const CPt2D<T> *pptVtx. If return true. If you do not want to include the right and bottom borders. dB. true: the line segment is cut or is already in the rect. if found. rectangle to intersect with the line line equation: A*x + B*y = C return the cut line if it exists. the point is also on the line segment. rectangle to intersect with the line segment the line segment to be cut. rect pLine Return 2. false: the line segment is outside the rect and no intersect. double dA. Description Cut a line segment within a rectangle A line segment is cut to fit inside a rect. CLine2D<T> *pLine).18 CutLineInRect template <class T> bool CutLineInRect (const CRect<T> &rect. bottom). It also returns the cut line if it exists. bottom].Description line1 dA2. int nCount). 23 . dC2 ppt Return 0 Get the intersect of a line segment with a line Line equation: A*x + B*y = C the line segment parameters of the line store point of intersection of two lines. 2. One of the line is derived from the line segment. (b) Two line segments do not intersect. dB2. true: intersect found.

and top and bottom equal to the min and max y coordinates of the points. int nCount. vector<int> *pvIdx). pt2 is strictly inside. 0 100 pt1 100 pt2 200 Y pt3 200 X pt4 ppt nCount x.21 ConvexHull template <class T> int ConvexHull (const vector<CPt2D<T> > &vPos. whose left and right equal to the min and max x coordinates of the points.). Description ppt nCount Return Note Get the bounding rectangle of a set of points an array of points the number of points The bounding rectangle. 3: on one of the vertices. Right and bottom of bounding rect is equal but not larger than the max of x or y coordinates. 24 .) polygon vertices the number of vertices point to be tested 0: outside.. pt4 is on one of the vertices. Ray-crossing algorithm. (Winding number algo is slower.. 2. 2: on one of the edges but not on a vertex. (b) After applying CutLineInRect(. Description Check if a point is inside. T y). Joseph O’Rourke. or outside a polygon. pt1 is outside the polygon. 1: strictly inside.20 PointInPolygon template <class T> int PointInPolygon (const CPt2D<T> *ppt. (a) Before applying CutLineInRect(. Reference: ”Computational geometry in C” 7..).4. 2. y Return 0 Figure 17: An example of the PointInPolygon function.. pt3 is on one of the edges but not on a vertex. on. T x.0 100 200 Y 0 100 200 X 0 100 200 Y 0 100 200 X (a) (b) Figure 16: An example of the CutLineInRect function.

Description Precondition vPos pvIdx Return

Get convex hull points’ index see ConvexHull(vector<CPt2D<T> >*, vector<CPt2D<T> >*) input point set indices of convex hull points in vPos (clockwise order) the number of convex hull points

template <class T> int ConvexHull (vector<CPt2D<T> > *pvPos, vector<CPt2D<T> > *pvCH); Description Get the convex hull points in clockwise order Reference ”Computational geometry in C” by Joseph O’Rourke. The first point of vPos must be the topmost of all points, meaning that it has the smallest y coordinate. If there are more than one topmost points, the first point should be the leftmost of them, with the smallest x coordinate. input points (the array will be modified) a vector pointer that stores the found convex hull points the number of convex hull points

pvPos pvCH Return

2.22

BoundingBox

template <class T> bool BoundingBox (const vector<CPt2D<T> > &vPos, double dAngle, CPt2D<double> *pptCenter, CSize2D<double> *pSize); Description vPos dAngle pptCenter pSize Return Get the fixed-angle bounding box of a set of points input object points angle of the bounding box (radius, anticlockwise) center of the box size of the box true: succeeded; false: failed.

2.23

MinBoundingBox

template <class T> bool MinBoundingBox (const vector<CPt2D<T> > *pvPos, CPt2D<double> *pptCenter, CSize2D<double> *pSize, double *pdAngle); Description Get the min bounding box of a set of points MinBoundingBox function is based on the ”rotating caliper” algorithm. The output angle is anticlockwise; while some internal angles are clockwise. Since ConvexHull(...) outputs points in clockwise order, it is convenient to use clockwise angle internally. see ConvexHull(vector<CPt2D<T> >*, vector<CPt2D<T> >*) input points (the array will be modified) center of the box size of the box angle of the box (radius, anticlockwise) true: succeeded; false: failed.

Precondition pvPos pptCenter pSize pdAngle Return

2.24

MinBoundingCircle

template <class T> bool MinBoundingCircle (const vector<CPt2D<T> > *pvPos, CPt2D<double> *pptCenter, double *pdRadius); Description 1 2 Get the min bounding circle of a set of points Call the convex hull of the set of points H. Pick any side of H, say S. For each vertex of H other than those of S, compute the angle subtended by S. The minimum such angle, α, occurs at vertex v. If α ≥ 90 deg, done! (The circle is the diametric circle of S.) If α < 90 deg, check the remaining vertices of the triangle formed by S and v. continued on next page

25

3

Precondition pvPos pptCenter pdRadius Return

If no vertices are obtuse, done! (The circle is determined by the vertices of S and the vertex v.) If one of the other angles of the triangle formed by S and v is obtuse, then set S to be the side opposite the obtuse angle and go to step 2. (The new S may not be a side on the convex hull.) see ConvexHull(vector<CPt2D<T> >*, vector<CPt2D<T> >*) input points (the array will be modified) center of the circle radius of the circle true: succeeded; false: failed.

2.25

DelaunayTriangulation

template <class T> int DelaunayTriangulation (const vector<CPt2D<T> > &vPos, vector<CLine2D<T> > *pvLine, vector<CPoly2D<T> > *pvPoly); Description Get the Delaunay triangulation of a set of points Reference ”Computational geometry in C” by Joseph O’Rourke. Delaunay triangulation in 2D is based on convex hull in 3D. input point set edges of Delaunay triangles (input 0 to ignore) Delaunay triangles (input 0 to ignore). Each polygon contains only 3 vertices. the number of triangles

vPos pvLine pvPoly Return

(a)

(b)

(c)

(d)

(e)

Figure 18: Examples of the ConvexHull, BoundingBox, MinBoundingBox, MinBoundingCircle and DelaunayTriangulation functions. (a) Convex hull. (b) Bounding box at a fixed angle of 15 deg. (c) Minimum-area bounding box. (d) Minimum-area bounding circle. (e) Delaunay triangulation.

2.26

FitLine

template <class T> bool FitLine (const CPt2D<T> *ppt, int nCount, double *pdKx, double *pdY0); Description Least squares fitting of a line Line equation: y = kx x + y0 . Fitting is based on the y-direction error, not the perpendicular distance error. points to be fitted (size must be nCount) size of ppt array parameter kx of the line equation parameter y0 of the line equation true: succeeded; false: failed.

ppt nCount pdKx pdY0 Return

2.27

FitCircle

template <class T> bool FitCircle (const CPt2D<T> *ppt, int nCount, CPt2D<double> *pptCenter, double *pdRadius);

26

Description

ppt nCount pptCenter pdRadius Return

Least squares fitting of a circle Circle equation: (x − a)2 + (y − b)2 = R2 Internally fit the modified equation: Ax + By + C = x2 + y 2 If a fitted circle is found, circle parameters are stored in pptCenter, pdRadius; otherwise they are unchanged. points to be fitted (size must be nCount) size of ppt array pointer to the center of the circle pointer to the radius of the circle true: succeeded; false: failed.

2.28

FitEllipse

template <class T> bool FitEllipse (const CPt2D<T> *ppt, int nCount, double pdCoe[5]); Description ppt nCount pdCoe Return Least squares fitting of an ellipse Ellipse equation: Ax2 + Bxy + Cy 2 + Dx + Ey = 1 points to be fitted (size must be nCount) size of ppt array coefficients, A, B, C, D and E, of the ellipse equation true: succeeded; false: failed.

2.29

FitPolynomialCurve

template <class T> bool FitPolynomialCurve (const CPt2D<T> *ppt, int nCount, vector<double> *pvCoe, int N); Description Least squares fitting of a polynomial curve Polynomial curve equation: y = C[0] + coe[1] ∗ x + C[2] ∗ x2 + ... + C[N ] ∗ xN points to be fitted (size must be nCount) size of ppt array stored coefficients. If succeed, its size is N+1. the order of the curve equation (should be >= 0) true: succeeded; false: failed.
400

ppt nCount pvCoe N Return

200

0

Input points 2nd order curve 3rd order curve 4th order curve 5th order curve

Y
-200 0 10 20 30 40 50 60 70 80 90 100

X

Figure 19: An example of the FitPolynomialCurve function.

2.30

FitGauss

template <class T> bool FitGuass (const CPt2D<T> *ppt, int nCount, double *pdA, double *pdB, double *pdC);

27

Description

ppt nCount pdA pdB pdC Return

Least squares fitting of a Gaussian function 2 Gaussian function: y = Ae−(x−B) /(2C) . Fitting is based on a linear least squares method: the y coordinate of all points is converted to ln(y), which requires that y > 0. points to be fitted (size must be nCount) size of ppt array parameter A of the Gaussian equation parameter B of the Gaussian equation parameter C of the Gaussian equation true: succeeded; false: failed.

40

Input points FitGauss

Y
20 0

0

20

40

60

80

100

X

Figure 20: An example of the FitGauss function.

2.31

HoughLine

template <class T> int HoughLine (const CPt2D<T> *ppt, int nCount, double dRMin, double dRMax, int nRSec, double dAngleMin, double dAngleMax, int nAngleSec, double *pdR, double *pdAngle); Description Hough transform line detection Detect one line with maximum hough parameter. Line equation: R = x*cos(angle) + y*sin(angle) Resolution of R is (dRMax-dRMin)/nRSec. Resolution of angle is (dAngleMax-dAngleMin)/nAngleSec. points to be analyzed (size must be nCount) size of ppt array minimum boundary of R [dRMin, dRMax) maximum boundary of R [dRMin, dRMax) the number of sections in [dRMin, dRMax) minimum boundary of angle [dAngleMin, dAngleMax) maximum boundary of angle [dAngleMin, dAngleMax) the number of sections in [dAngleMin, dAngleMax) found R of the line equation found angle (in radius) of the line equation 0: line not found; >0 line found (return the number of points on the line).

ppt nCount dRMin dRMax nRSec dAngleMin dAngleMax nAngleSec pdR pdAngle Return

2.32

HoughCircle

template <class T> int HoughCircle (const CPt2D<T> *ppt, int nCount, double dXMin, double dXMax, int nXSec, double dYMin, double dYMax, int nYSec, double dRMin, double dRMax, int nRSec, CPt2D<double> *pptCenter, double *pdR); 28

>0 circle found (return the number of points on the circle). 60 50 40 Input points FitCircle HoughCircle Y 0 0 Input points FitLine HoughLine 20 40 60 80 100 Y 20 0 20 40 60 80 100 X X (a) (b) Figure 21: Examples of the FitLine. const CPt2D<int> &ptStart. (b) FitCircle and HoughCircle. Resolution of center y is (dYMax-dYMin)/nYSec. FitCircle and HoughCircle functions. dRMax) maximum boundary of R [dRMin. vector<CPt2D<int> > *pvPos). Description rcROI ptStart ptEnd pvPos Return Get points on a line within a bounding rect bounding rect (only get points inside the rect) start point of the line end point of the line store points on the line the number of pixels on the line int GetLinePoints (const CPt2D<int> &ptStart. dYMax) the number of sections in [dRMin. const CPt2D<int> &ptEnd. HoughLine. points to be analyzed (size must be nCount) size of ppt array minimum boundary of the circle center x coordinate maximum boundary of the circle center x coordinate minimum boundary of the circle center y coordinate maximum boundary of the circle center y coordinate minimum boundary of R [dRMin. dXMax) the number of sections in [dYMin. dRMax) the number of sections in [dXMin. Resolution of radius is (dRMax-dRMin)/nRSec. Description ptStart ptEnd pvPos Return Bresenham’s line algorithm start point of the line end point of the line store points on the line the number of pixels on the line 29 . vector<CPt2D<int> > *pvPos).Description ppt nCount dXMin dXMax dYMin dYMax dRMin dRMax nXSec nYSec nRSec pptCenter pdR Return Hough transform circle detection Detect one circle with maximum hough parameter. dRMax) found circle center found circle radius 0: circle not found. 2. const CPt2D<int> &ptEnd. Circle equation: R = (x − x0)2 + (y − y0)2 Resolution of center x is (dXMax-dXMin)/nXSec. (a) FitLine and HoughLine.33 GetLinePoints int GetLinePoints (const CRect<int> &rcROI.

Description ptCenter nRadius pvPos Return Bresenham’s circle algorithm center of the circle radius of the circle store points on the circle the number of pixels on the circle 30 .34 GetCirclePoints int GetCirclePoints (const CPt2D<int> &ptCenter. int nRadius. vector<CPt2D<int> > *pvPos).2.

3 2D image processing functions Type T* Name pImg Description Pointer to a continuous memory space which must be equal to or larger than w*h*sizeof(T) bytes. T* T* int CRect<int>& T pSrc pDst w.2 ImgAssignBorder template <class T> void ImgAssignBorder (T *pImg. 31 . right: 5 pixels. (a) Original image. const CRect<int> &rcROI. const CRect<int> &rcROI. int nLeft. int nRight. The modified region is a rectangular ring. int h. int nBottom). (b) The ROI is assigned with value 220. Left border: 7 pixels. (c) The border of the ROI is assigned with value 220. top: 10 pixels. Some parameters are common to most functions. 3. int w.1 ImgAssign template <class T> void ImgAssign (T *pImg. h rcROI ObjID Table 2: Common parameters of 2D image processing functions. bottom: 3 pixels. int w. See Table 2 for common parameters distance toward the center on the left border distance toward the center on the top border distance toward the center on the right border distance toward the center on the bottom border Parameters nLeft nTop nRight nBottom ROI ROI (a) (b) (c) Figure 22: Examples of the ImgAssign and ImgAssignBorder functions. T value. Pointer to the source image Pointer to the destination image Image width and height Region of interest. otherwise background. They are listed in Table 2. T value). Description Assign image data on the border of an ROI to the input value Pixels within the distance are assigned to the input value. int nTop. Pixels whose value==ObjID are treated as object points. The y-th row. Only image data within the ROI will be used or modified. int h. Description Parameters value Assign image data in an ROI to the input value See Table 2 for common parameters the value to be assigned to the image data 3. x-th column element can be retrieved by *(pImg+y*w+x) or pImg[y*w+x].

const CRect<int> &rcROI2. class T2> void ImgCopy (const T1 *pSrc. T2 *pDst. (c) Resultant image after ImgCopy. int w1. class T2> void ImgGradientX (const T1 *pSrc. const CRect<int> &rcROI1. Each subpixel in ROI1 is linearly interpolated from interger pixels. Description Parameters Copy image data from source image ROI1 to destination image ROI2 Width and height of ROI1 and ROI2 must be the same. const CRect<int> &rcROI2. double dCoe2). int h2. (a) Source image ROI1 is copied to (b) destination image ROI2.6 ImgGradientX template <class T1. T2 *pDst. const CRect<int> &rcROI1. int nGradLen). int w1. int h2. T2 *pImg2. int w2. const CRect<int> &rcROI2. const CRect<int> &rcROI1. 3. Width and height of ROI1 and ROI2 must be the same. double dCoe1. int h1. int w1. 32 . const CRect<int> &rcROI2). class T2> void ImgCopySubpixel (const T1 *pSrc. int h1.4 ImgCopySubpixel template <class T1. int h1. See Table 2 for common parameters ROI1 ROI2 (a) (b) (c) Figure 23: An example of the ImgCopy function.3 ImgCopy template <class T1. int h2. const CRect<int> &rcROI1. class T2> void ImgBlend (const T1 *pImg1. int w1. int w2. T2 *pDst. int h1. Description Parameters dCoe1 dCoe2 Blend img1 into img2 Blending equation: img2 = dCoe1*img1 + dCoe2*img2. Description Copy image data at subpixel accuracy Copy image ROI1 offset by ptOffset to ROI2. const CPt2D<float> &ptOffset).5 ImgBlend template <class T1. See Table 2 for common parameters subpixel offset of ROI1 Parameters ptOffset 3. int w2. int w2.3. int h2. See Table 2 for common parameters coefficient multiplied to each pixel in ROI1 coefficient multiplied to each pixel in ROI2 3.

toMax] See Table 2 for common parameters minimum bound to clamp the image data maximum bound to clamp the image data 3. the x gradient pDst[x] = pSrc[x+1] . T2 toMin. const CRect<int> &rcROI1. T toMin. T1 fromMin. int w2. T2 *pDst.pSrc[(y-1)*w+x]. T2 toMax). meaning the gap between the two pixels used to calculate a gradient point is 2. the y gradient pDst[y*w+x] = pSrc[(y+1)*w+x] . const CRect<int> &rcROI2.7 ImgGradientY template <class T1. toMax]. fromMax] to Dst data to the range [toMin. See Table 2 for common parameters length of the gradient operator 3. If the gradient length is 2. See Table 2 for common parameters length of the gradient operator Parameters nGradLen 3. (b) Image 2. int w. const CRect<int> &rcROI2. T toMax). const CRect<int> &rcROI1. class T2> void ImgGradientY (const T1 *pSrc. (c) The resultant image of blending image 1 into image 2. T2 *pDst. Description Parameters toMin toMax Clamp image data to the range [toMin. Description Linear translate Src data in the range [fromMin. T1 fromMax. int w1.9 ImgLinear template <class T1. int h1. (a) Image 1. continued on next page 33 . const CRect<int> &rcROI.8 ImgClamp template <class T> void ImgClamp (T *pImg. Description 1D gradient in the y direction Take the image data gradient in the y direction.pSrc[x-1]. class T2> void ImgLinear (const T1 *pSrc. int h2. If the gradient length is 2. int h2. int w1.am S (a) Description le p (b) (c) Figure 24: An example of the ImgBlend function. Linear translation parameters a and b is determined by: a * fromMin + b = toMin. a * fromMax + b = toMax. int h. Parameters nGradLen 1D gradient in the x direction Take the image data gradient in the x direction. int w2. meaning the gap between the two pixels used to calculate a gradient point is 2. int h1. int nGradLen).

pSrc and pDst may point to the same image buffer. 1]. max]. const CRect<int> &rcROI). (a) Source image.Parameters fromMin fromMax toMin toMax Data points in Src that are < fromMin or > fromMax will be translate to toMin and toMax.10 ImgGamma template <class T1.5. const CRect<int> &rcROI2.11 ImgMin template <class T> T ImgMin (const T *pImg. (a) Source image. where x ∈ [0. 3. int h2. double dGamma). T2 *pDst. int w2. int h1. Description Apply gamma transform Gamma transform equation: y = xgamma . (b) Image data are clamped to [50. pSrc and pDst may point to the same image buffer. and finally maps the data back to [min.7. int h. See Table 2 for common parameters source minimum bound source maximum bound destination minimum bound destination maximum bound (a) (b) (c) Figure 25: Examples of the ImgClamp and ImgLinear functions. max] to [0. int w. const CRect<int> &rcROI1. if ROI1 and ROI2 are the same. 200]. (c) The image after transformed by gamma = 1. See Table 2 for common parameters gamma value Parameters dGamma (a) (b) (c) Figure 26: Examples of the ImgGamma function. Description Parameters Return Get the minimum value of an ROI See Table 2 for common parameters the minimum value of an ROI 34 . if ROI1 and ROI2 are the same. This function first maps all data from [min. 3. then applies gamma transform. (c) Image data are linearly translated to [50. class T2> void ImgGamma (const T1 *pSrc. int w1. 200]. 1]. (b) The image after transformed by gamma = 0.

int h. double *pdStdDev). Description Parameters pMin pMax Get the minimum and maximum value of an ROI See Table 2 for common parameters return the minimum value of an ROI return the maximum value of an ROI 3.17 ImgStdDev template <class T> double ImgStdDev (const T *pImg. int w. const CRect<int> &rcROI). int w. T *pMax). int h.13 ImgMinMax template <class T> void ImgMinMax (const T *pImg. int h. const CRect<int> &rcROI). int h. const CRect<int> &rcROI).18 ImgStatistics template <class T> void ImgStatistics (const T *pImg. Description Parameters Return Get the variance of an ROI See Table 2 for common parameters the variance of an ROI 3. T *pMin. int w. const CRect<int> &rcROI).12 ImgMax template <class T> T ImgMax (const T *pImg. const CRect<int> &rcROI. Description Parameters Return Get the median value of an ROI See Table 2 for common parameters the median value of an ROI 3. int h. T *pMean. T *pMax.14 ImgMean template <class T> T ImgMean (const T *pImg. int w. int w. const CRect<int> &rcROI). Description Parameters Return Get the mean value of an ROI See Table 2 for common parameters the mean value of an ROI 3. int h.15 ImgMedian template <class T> T ImgMedian (const T *pImg.16 ImgVariance template <class T> double Variance (const T *pImg. Description Parameters Return Get the standard deviation of an ROI See Table 2 for common parameters the standard deviation of an ROI 3.3. int w. int h. const CRect<int> &rcROI). int w. T *pMin. Description Parameters Return Get the maximum value of an ROI See Table 2 for common parameters the maximum value of an ROI 3. 35 .

int nKerW. int h2. int Description Parameters nKerW nKerH Example (a) (b) (c) Figure 27: Examples of the ImgFltMean and ImgFltMedian functions. int w2. int nKerW. class T2. T *pDst. int h3. See Table 2 for common parameters filter kernel width filter kernel height nKerW*nKerH = 3*3 or 7*5 template <class (const T *pSrc. const CRect<int> &rcROI1. int h1. int Description Parameters nKerW nKerH Example template <class T1. const CRect<int> &rcROI3. (rcROI1. rcROI2 and rcROI3 must be the same size) 3. kernel certer equal to kernel median Half-filter-length data at the ROI boundary are filtered with reduced sized kernel. class T3> void ImgFltMean (const T1 *pImg. int w3. (b) The image after filtered by ImgFltMean (3 by 3 kernel). const CRect<int> &rcROI1. int h2.20 ImgFltMedian T> void ImgFltMedian int w1. nKerH). Mean filter. int w2.Description Parameters pMin pMax pMean pdStdDev Get statistics of an ROI See Table 2 for common parameters return the minimum value of an ROI return the maximum value of an ROI return the mean value of an ROI return the standard deviation of an ROI 3. int h1. int w2. const CRect<int> &rcROI2. int w1. (a) Source image. const CRect<int> &rcROI2. nKerH). See Table 2 for common parameters filter kernel width filter kernel height nKerW*nKerH = 3*3 or 7*5 template <class (const T *pSrc. int nKerW. const CRect<int> &rcROI2. T *pDst. 36 . const CRect<int> &rcROI1.19 ImgFltMean T> void ImgFltMean int w1. T3 *pDst. const T2 *pWei. Median filter. kernel certer equal to kernel mean Half-filter-length data at the ROI boundary are filtered with reduced sized kernel. int nKerH). int h2. (c) The image after filtered by ImgFltMedian (3 by 3 kernel). Description Parameters pWei Weighted mean filter See Table 2 for common parameters weighting. int h1.

37 . See Table 2 for common parameters filter kernel width filter kernel height nKerW*nKerH = 3*3 or 7*5 Parameters nKerW nKerH Example (a) (b) Figure 28: An example of the ImgFltVariance function.5 filter strength. kernel certer equal to kernel variance Half-filter-length data at the ROI boundary are filtered with reduced sized kernel. Description Variance filter. class T2> void ImgConvX (T1 *pImg. int w1. 1) (larger. int nKerH). int w.21 ImgFltVariance template <class T1. int h. smoother) (a) (b) (c) Figure 29: Examples of the ImgFltISEF function. (a) Source image. class T2> void ImgFltVariance (const T1 *pSrc.22 ImgFltISEF template <class T> void ImgFltISEF (T *pImg. const CRect<int> &rcROI1. const CRect<int> &rcROI. T2 *pDst. (c) The image after filtered by 0. (b) The image after filtered by ImgFltVariance (3 by 3 kernel).8 filter strength. double dStrength). 3. (b) The image after filtered by 0. Description Parameters dStrength Infinite symmetric exponential filter See Table 2 for common parameters ISEF filter strength [0. int nKerW. const CRect<int> &rcROI2.23 ImgConvX template <class T1. int nLen). int h1. Dark pixels indicate high variance. int w. int w2. 3. bright pixels indicate low variance. const CRect<int> &rcROI.3. (a) Source image. int h2. int h. const T2 *pMask.

int h.Description Parameters pMask nLen 1D convolution in x direction Convolution is applied on each row (x direction). pMask[2] = -0. const CRect<int> &rcROI.2. Description 1D convolution in y direction Convolution is applied on each column (y direction).5 continued on next page Example 2 38 . 0. 0. pMask[4] = 0. int w. Description Parameters pMask nKerW nKerH Example 1 2D convolution Half-filter-length data at the ROI boundary are unchanged. 0.24 ImgConvY template <class T1. int w1.25 ImgConv template <class T1. class T2> void ImgConv (const T1 *pSrc. The mask data array size must satisfy nLen+(nLen-1)/2 ≤ ROI. pMask[8] = 1 Sharpening convolution mask pMask[0] = -0.5.2}. 0.5. pMask[7] = 0. See Table 2 for common parameters pointer to the convolution mask data array mask array size 3. int nLen). Half-filter-length data at the ROI boundary are unchanged. pMask[2] = 1 pMask[3] = -2. (a) Source image. See Table 2 for common parameters pointer to the convolution mask data array mask array size Parameters pMask nLen (a) (b) (c) Figure 30: Examples of the ImgConvX and ImgConvY functions. otherwise nothing is done. The mask data array size must satisfy nLen+(nLen-1)/2 ≤ ROI.2. Half-filter-length data at the ROI boundary are unchanged. pMask[1] = -0. const CRect<int> &rcROI1. int h2. pMask[1] = 0. int nKerW.2. const T2 *pMask. (b) The resultant image processed by ImgConvX. See Table 2 for common parameters pointer to the convolution mask image mask image width mask image height Sobel convolution mask pMask[0] = -1.2 pMask[3] = -0. T1 *pDst. pMask[5] = -0. otherwise nothing is done.2.Width(). int nKerH). const T2 *pMask. pMask[5] = 2 pMask[6] = -1. 3. pMask[4] = +3. class T2> void ImgConvY (T1 *pImg.2.Height(). int w2. const CRect<int> &rcROI2. The convolution mask image is pMask[5] = {0.8. (c) The resultant image processed by ImgConvY. int h1.

int h1. (b) Image produced by Sobel convolution mask. Description Resize ROI1 of Src and copy to ROI2 of Dst If linear (nAlgo: 1) or spline (nAlgo: 2–4) is used. Dark pixels indicate high values. (a) Source image.26 ImgResize template <class T1. int h1. 39 . const CRect<int> &rcROI2. int w1. Magnification is done by the specified method. const CRect<int> &rcROI2.pMask[6] = -0. const CRect<int> &rcROI1. (c) Image produced by the sharpening convolution mask. 3: Catmull-Rom spline interpolation. 1: linear interpolation. If nearest neighbour (nAlgo: 0) is used. (a) Source image. See Table 2 for common parameters interpolation algorithm 0: nearest neighbour interpolation. T2 *pDst. int w1. T2 *pDst. bool bLinear). pMask[1] = -0.2 (a) (b) (c) Figure 31: Examples of the ImgConv function. int w2. Parameters nAlgo ROI1 ROI2 (a) (b) (c) Figure 32: An example of the ImgResize function. 2: cubic B-spline interpolation. class T2> void ImgRotate (const T1 *pSrc. bright pixels indicate low values. 4: natural cubic spline interpolation.27 ImgRotate template <class T1. minification is always a downsampling process based on averaging. int nAlgo). const CRect<int> &rcROI1.2.5. int h2. (c) Resized ROI1 is copied to ROI2. (b) Destination image. 3. class T2> void ImgResize (const T1 *pSrc. both minification and magnification are based on nearest neighbour. pMask[2] = -0. 3. int w2. int h2. int nAngle.

ROI2 ROI1 (a) (b) (c) Figure 34: An example of the ImgRotate function.200 100 Source pixels Nearest neighbour Linear interpolation Cubic B-spline Catmull-Rom spline Natural cubic spline 10 20 30 Pixel 40 50 60 70 Intensity 0 Figure 33: An example of different algorithms of the ImgResize function. the size of ROI1 and ROI2 must be related accordingly. The rotated points in ROI1 that do not fall in ROI2 are ignored. int h1. Hence.29 ImgFan template <class T1.01 degree true for linear interpolation. 40 . int w1. class T2> void ImgFan (const T1 *pSrc. If nAngle is a multiple of 9000 (90 deg). false for nearest neighbour interpolation. the size of ROI1 and ROI2 must be the same. the width and height of ROI1 and ROI2 must be exchanged. 3. bool bLeftRight). (a) Source image. See Table 2 for common parameters anti-clock wise angle of rotation in 0. const CRect<int> &rcROI. Description Parameters bLeftRight Flip the image data in an ROI See Table 2 for common parameters true: left-right flip. the rotation center is matched with the center of ROI2. Description 1 2 3 Parameters nAngle bLinear Rotate ROI1 of Src and copy to ROI2 of Dst Rotation center is the center of ROI1. int h. Those points in ROI2 that do not have counterpart in ROI1 are unchanged. When copied to ROI2. false: top-bottom flip. int w. (b) Destination image. there is no prerequisite on the size of ROI1 and ROI2. (c) Rotated ROI1 is copied to ROI2. 3. If the rotation angle is 0 or 180 deg. If the rotation angle is 90 or 270 deg.28 ImgFlip template <class T> void ImgFlip (T *pImg. const CRect<int> &rcROI1. If nAngle is not a multiple of 9000 (90 deg).

0. int h2.x)2 + (y1 − ptCen. const CRect<int> &rcROI2.x + (1 + KR1 )(x1 − ptCen. double dK).y). (a) (b) Figure 36: An example of the ImgFan function. (b) Image is flipped left to right. 2 R1 = (x1 − ptCen. bool bLinear). int w1. TWOPI] radius of the top line in the source ROI radius of the bottom line in the source ROI true for linear interpolation. y1 ) and (x2 .y + (1 + KR1 )(y1 − ptCen. class T2> void ImgRadial (const T1 *pSrc. const CRect<int> &rcROI1. (a) Source image. Linear interpolation is used. const CPt2D<double> &ptCen. T2 *pDst. int h1. 3. (b) Fan-shaped image. false for nearest neighbour interpolation.w1. (c) Image is flipped top to bottom.30 ImgRadial template <class T1. y2 ) is a pixel in ROI1 and ROI2 respectively. int w2.(a) (b) (c) Figure 35: An example of the ImgFlip function. where (x1 . int w2.y)2 . double dTopRadius. Description Parameters dAngle dTopRadius dBottomRadius bLinear Create a fan-shaped image Empty region around the fan shape is unchanged. int h2. Description Create a radially distorted image ROI1 is radially distorted around ptCen based on equation 2 x2 = ptCen. See Table 2 for common parameters angle in radius of the fan shape (0. Pixels in ROI2 that do not have a counterpart in ROI1 are set to 0. See Table 2 for common parameters center of radial distortion in CRect(0.x) 2 y2 = ptCen. const CRect<int> &rcROI2.h1) coordinate radial distortion coefficient Parameters ptCen dK 41 . The distorted data are copied to ROI2. double dAngle. (a) Source image. T2 *pDst. double dBottomRadius.

int w1. (b) Barrel distortion. int w.Width() ROI1. Then ROI2 is matched to 9 windows.Height() must be >= ROI2. nDSX and nDSY are further halved.(a) (b) (c) Figure 37: An example of the ImgRadial function. See Table 2 for common parameters initial downsampling gap in x direction continued on next page 1 2 3 Parameters nDSX 42 . const CRect<int> &rcROI2. int h1. Description Parameters nKerW nKerH Create mosaic effect See Table 2 for common parameters mosaic kernel width mosaic kernel height ROI (a) (b) Figure 38: An example of the ImgMosaic function. int w2.Width() must be >= ROI2. (a) Source image. const CRect<int> &rcROI. 3.32 ImgMatch template <class T> void ImgMatch (const T *pMother. int nKerW. int h2. 3. After the best-match window is found. int h. Go back to 2 until both nDSX and nDSY equal to 1 pixel. (a) Source image. const CRect<int> &rcROI1. ROI2 is matched to windows in ROI1 separated by nDSX and nDSY in the x and y directions.31 ImgMosaic template <class T> void ImgMosaic (T *pImg. (b) The image data in the ROI are mosaicked. double *pdCorr). Description Search for ROI2 of pChild in ROI1 of pMother ROI1. int nDSY.Height() Initially. The windows are separated by nDSX and nDSY. (c) Pincushion distortion. a 3 by 3 grid centered on the bestmatch window. After a new best-match window is found. CPt2D<int> *pptMatch. nDSX and nDSY are halved. int nDSX. int nKerH). const T *pChild.

const T *pImg2. int &nWinX. etc) At input. normalized correlation coefficient. (a) Mother image. See Table 2 for common parameters subpixel level (1: 0. int nFineX. double *pdCorr). int nFineDSX. int &nWinY. 3 by 3 windows are searched. ROI1 specifies the limit of the search region. const T *pChild. int nFineDSY. the best-match point in ROI1 coordinate (left-top corner of the matched rect) normalized correlation coefficient. continued on next page 1 43 . vector<double> *pvCorr).1] pptMatch ROI1 ROI2 (a) (b) Figure 39: An example of the ImgMatch function. int nFineW. Description Pixel flow or motion estimation Estimate the pixel motion from ROI1 in pImg1 to ROI2 in pImg2. vector<CPt2D<int> > *pvptDisp. int nCoarW. int nLevel. int nFineH. int nCoarX. const CRect<int> &rcROI1. The matching window is given by ROI2. Data matching is performed at several levels of increasing subpixel accruacy. int h1. (c) Matched position of the child image in the mother image. CPt2D<float> *pptMatch. int h2. 3. Description Image matching at subpixel accuracy Subpixel search for ROI2 of pChild in ROI1 of pMother. int h2. int nCoarDSY. ROI1 and ROI2 must be the same size.nDSY pptMatch pdCorr initial downsampling gap in y direction The downsampling gaps are used in shifting ROI1 across ROI2 and in accessing the pixels in ROI1 and ROI2. matching point at pixel accuracy). int h1. int w1. const CRect<int> &rcROI1.33 ImgMatchSubpixel template <class T> void ImgMatchSubpixel (const T *pMother. in [-1. At each level. Results of the coarse search are used as the initial guess for the fine search. int w2.34 ImgMotion template <class T> void ImgMotion (const T *pImg1. int nCoarH. vector<CPt2D<int> > *pvptCenter. The best match is used as the center window of the next level search. 2: 0. in [-1. it represents the initial offset (eg. (b) Child image. int nCoarY. int nFineY. At output. const CRect<int> &rcROI2.1] Parameters nLevel pptMatch pdCorr 3. There are two levels of search: a coarse search based on a few coarse windows and a quality-guided fine search on all fine windows. it is the best match (left-top corner) of ROI2 in ROI1 at subpixel accuracy. int nCoarDSX. const CRect<int> &rcROI2.5 pixel. int w2. int w1.25 pixel.

int w1. which are arrays of the same size: nWinX * nWinY (at output).35 ImgDIC template <class T> void ImgDIC (const T *pImg1. int h2.. const CRect<int> &rcROI1. See Table 2 for common parameters coarse search window width coarse search window height coarse search distance in x direction coarse search distance in y direction coarse search downsampling gap in x direction coarse search downsampling gap in y direction fine search window width fine search window height fine search distance in x direction fine search distance in y direction fine search downsampling gap in x direction fine search downsampling gap in y direction input desired number of fine search windows in x direction output actual number of fine search windows in x direction input desired number of fine search windows in y direction output actual number of fine search windows in y direction center of fine search windows in pImg1 displacement of fine windows from pImg1 to pImg2 This includes the global shift from ROI1 to ROI2. pvptDisp. int w2. vector<float> *pvCorr). int &nWinX. const CRect<int> &rcROI2. Results are stored in pvptCenter. See ImgMatch(. vector<float> *pvDispX.) for details of the downsampling gap. correlation coefficient of each fine window Coarse window Fine window Pixel Figure 40: Illustration of the dual level search of the ImgMotion function. int nSpeckleSize. 3. pvCorr. vector<CPt2D<int> > *pvptCenter. The downsampling gap at each level is set independently. vector<float> *pvDispY. 44 . and a small fine search window and search distance to obtain a high resolution. int &nWinY. int h1.2 3 Parameters nCoarW nCoarH nCoarX nCoarY nCoarDSX nCoarDSY nFineW nFineH nFineX nFineY nFineDSX nFineDSY nWinX nWinY pvptCenter pvptDisp pvCorr A large coarse search window and search distance may be used to obtain robust initial estimates. const T *pImg2..

) to calculate integer pixel displacement and then applies linear interpolation to obtain subpixel accuracy. It relies on ImgMotion(. (b) Image 2. Pixles < tMin contribute to pnHisto[0]. T tMax. See Table 2 for common parameters average speckle size.5 0 0 20 40 60 80 100 120 140 160 180 200 220 Intensity (a) (b) Figure 42: An example of the ImgHistogram function. Search parameters of ImgMotion(. the finer is the resolution of the histogram. (a) Source image. Its size must be nLevel. It is used to estimate the search window size. const CRect<int> &rcROI. level of histogram. store histogram in nLevel entries. (c) Local motion vectors from image 1 to image 2. 45 . int h.(a) (b) Figure 41: An example of the ImgMotion function. Pixels > tMax contribute to pnHisto[nLevel-1]. Description Parameters nSpeckleSize nWinX nWinY pvptCenter pvDispX pvDispY pvCorr Digital image correlation Calculate subpixel displacement from ROI1 to ROI2. T tMin.) are estimated by the ROI size. Description Parameters tMin tMax pnHisto nLevel Get histogram of the image data in an ROI See Table 2 for common parameters minimum bound.. 1. int nLevel).36 ImgHistogram template <class T> void ImgHistogram (const T *pImg. The larger the nLevel. maximum bound..5 Percentage % 1 ROI 0. (a) Image 1. input desired number of fine search windows in x direction output actual number of fine search windows in x direction input desired number of fine search windows in y direction output actual number of fine search windows in y direction center of fine search windows in pImg1 displacement in the x direction displacement in the y direction the correlation coefficient of each window 3. Each entry records the number of pixels falling into a specific range. int *pnHisto. int w. (b) Histogram of the ROI.

the minimum value of the ROI after processing (input 0 to ignore) the maximum value of the ROI after processing (input 0 to ignore) Parameters dPerMin dPerMax pMin pMax 3.3.2 0 0 50 100 150 200 250 Intensity (c) (d) Figure 43: An example of the ImgHistoEqu function. (a) Source image ROI. 1. int h. respectively.4 1. const CRect<int> &rcROI.38 ImgClampExtreme template <class T> void ImgClampExtreme (T *pImg. int w. See Table 2 for common parameters percentage of minimum to be clamped.6 0. int w. T *pMax = 0). 3. Should be in [0. 46 . percentage of maximum to be clamped.8 0.37 ImgHistoEqu template <class T> void ImgHistoEqu (T *pImg.6 0. Image data that fall below the minimum bound or above the maximum are clamped to the bounds. int h. const CRect<int> &rcROI). T tMin.4 0. int w. const CRect<int> &rcROI.39 ImgThre TwoPeak template <class T> T ImgThre_TwoPeak (const T *pImg. Description Parameters tMin tMax nLevel Equalize histogram of the image data in an ROI See Table 2 for common parameters minimum bound. The smallest value of the top “perMax” percent is set as the maximum bound.2 Percentage % 1 0. (b) Histogram of the source image ROI. Pixles < tMin contribute to pnHisto[0]. 1].8 0.4 1. Pixels > tMax contribute to pnHisto[nLevel-1].2 (b) Percentage % 1 0. int nLevel). T *pMin = 0. T tMax.2 0 ROI 0 50 100 150 200 250 Intensity (a) 1. Description Clamp extreme values in an ROI The biggest value of the bottom “perMin” percent data is set as the minimum bound. (c) Histogram-equalized ROI. double dPerMax. int h. (d) Histogram of the equalized ROI. The larger the nLevel. the finer is the resolution of the histogram equalization. maximum bound. 1].4 0. Should be in [0. double dPerMin. level of histogram.

Description Parameters Return Get threshold of an ROI based on the two peaks method First. . The new threshold is (Tb+Ta)/2. int h2. int h2. int w1. (c) Threshold obtained by the iterative selection method. (b) Threshold obtained by the two-peak method. const CRect<int> &rcROI1. 3. it is set to the source region’s global min (in ImgDilation) or max (in ImgErosion) value. See Table 2 for common parameters threshold of an ROI Parameters Return (a) (b) (c) Figure 44: Examples of the ImgThre TwoPeak and ImgThre IterSel functions. int nCount). See Table 2 for common parameters threshold of an ROI 3. int w. T *pDst. Continue this process until there is no change in the threshold value. const CPt2D<int> *ppt. const CRect<int> &rcROI2. const CPt2D<int> *ppt. Description Get threshold of an ROI based on the iterative selection method Take an initial guess of the threshold. The input relative position array is used as structuring elements. int w1. The 2nd peak is the max multiplication of the histogram values by the square of the distance from the first peak.-1).42 ImgErosion ImgErosion int h1. [1]=(1. 3. Locate the max peak is straightforward. 47 template <class T> void (const T *pSrc. const CRect<int> &rcROI2. int nCount). int h. If a destnation pixel’s all relative positions are outside the source region. Compute mean of all pixels below the threshold and the mean of all pixels above the threshold. See Table 2 for common parameters relative position array (size must be nCount) the size of ppt Dilate in 135 deg: ppt[0]=(-1. This helps not to choose a pseudo-peak near the max (1st) peak. const CRect<int> &rcROI1. const CRect<int> &rcROI). (a) Source image.1).41 ImgDilation ImgDilation int h1. template <class T> void (const T *pSrc. T *pDst. int w2. int w2.40 ImgThre IterSel template <class T> T ImgThre_IterSel (const T *pImg. Then two peaks are located. A destination pixel is set to the max value (in ImgDilation) or min value (in ImgErosion) of the source pixels located by the relative positions. Description Parameters ppt nCount Example Morphology dilation Dilation is applied to intensity data rather than binary data. The threshold is the mid value of the two peak values. histogram of the ROI is computed.

1). 5. 32 -----------------------pvDst: 22/3. T *pProj). 3. const CRect<int> &rcROI.43 ImgProjX template <class T> void ImgProjX (const T *pImg. 151/3 3. 29 12. 277/3. 21. Its size must be >= ROI. int w. A destination pixel is set to the max value (in ImgDilation) or min value (in ImgErosion) of the source pixels located by the relative positions. 90 7. const CRect<int> &rcROI. 3. (a) (b) (c) Figure 45: Examples of the ImgDilation and ImgErosion functions. (a) Source image. 29 | 93/4 12. 23. 234. 9. Its index increases with y.Height(). [1]=(1. If a destnation pixel’s all relative positions are outside the source region. 34. Description Parameters pProj Example Get x direction projection of an ROI See Table 2 for common parameters average of values along x direction. int h. 9. 234. it is set to the source region’s global min (in ImgDilation) or max (in ImgErosion) value.-1). The input relative position array is used as structuring elements. 48 . const CRect<int> &rcROI. 49/3. T *pProj).45 ImgProjAny template <class T> void ImgProjAny (const T *pImg. int w. int h. See Table 2 for common parameters relative position array (size must be nCount) the size of ppt Dilate in 135 deg: ppt[0]=(-1. 5. (c) Image erosion. 23. (b) Image dilation.Description Parameters ppt nCount Example Morphology erosion Erosion is applied to intensity data rather than binary data. Its index increases with x. int w. 34. 32 | 74/4 3. 3. 21.Width(). int h.44 ImgProjY template <class T> void ImgProjY (const T *pImg. 90 | pvDst: 336/4 7. Its size must be >= ROI. Description Parameters pProj Example Get y direction projection of an ROI See Table 2 for common parameters average of values along y direction.

int w1. See Table 2 for common parameters the start angle of projection the angular increase at each step Parameters dStartAngle dStepInc 3. (a) Source image. If a line is outside the ROI. Its size must be nLine. 3. the number of projection lines 180 160 Parameters lnStart lnEnd pProj nLine tart ptE 140 ptS Intensity nd 120 100 80 60 40 0 20 40 60 80 100 Pixel (a) (b) Figure 47: An example of the ImgProjAny function. int w2. Description Get the projection of an arbitrary-shaped region The arbitrary-shaped region is specified by 2 lines.46 ImgRadon template <class T1.Height(). T *pProj. const CRect<int> &rcROI1. (c) Intensity projection of the ROI in the y direction. The projection at each angle is stored in a line in ROI2. int h2. const CLine2D<int> &lnStart. Description Radon transform Radon transform is the integral of an image over straight lines.47 ImgRadonVH template <class T1. (b) Intensity projection of the ROI. int h1. its projection value will be set to 0. int w1. 49 .170 150 130 Intensity 110 ROI 90 70 0 200 400 600 800 1000 1200 Intensity 120 70 20 0 200 400 600 800 1000 1200 1400 1600 Pixel Pixel (a) (b) (c) Figure 46: Examples of the ImgProjX and ImgProjY functions. (a) Source image with start and end projection lines. The projection width is ROI2. The projection sweeps from lnStart to lnEnd with “nLine” projection lines. int h1. int nLine). Parallel geometry is assumed. double dStepInc). const CRect<int> &rcROI2.Width() and the number of angles is ROI2. class T2> void ImgRadon (const T1 *pSrc. double dStartAngle. const CRect<int> &rcROI1. const CLine2D<int> &lnEnd. See Table 2 for common parameters the start projection line the end projection line (lnStart and lnEnd may intersect) store average value of each projection line. T2 *pDst. class T2. class Pred> void ImgRadonVH (const T1 *pSrc. (b) Intensity projection of the ROI in the x direction.

int w2. A background projection datum sets the pixels in the backprojected line to be background while an object datum does not change the backprojected field. 50 .48 ImgBackprojVH template <class T1. Pred pred. int h2. See Table 2 for common parameters Pixels == 0 are definitely background. class Pred> void ImgBackprojVH (const T1 *pSrc. T2 *pSum.. == tObj are definitely objects. const CRect<int> &rcROI2. int w1.49 ImgIntegral template <class T1. angle of each projection line value in pDst to indicate object pixels Parameters pDst pred pdAngle tObj 3. const CRect<int> &rcROI1. The projection at each angle is stored in a line in ROI2.Height(). int w2.). int w1. int h2. Description Backprojection for visual hull Backprojection for visual hull (VH) is an erosive process in contrast to the accumulative process in the filtered backprojection for computed tomography (CT). double dStepInc. T2 tObj). The projection width is ROI2.Height(). const CRect<int> &rcROI1. Pred pred. modeled in ImgRadon(. if pred(pSrc[y*w+x]) is true. int h1. double dStartAngle. point (x. int h2. double *pdAngle.y) is considered an object point. T2 tObj). const CRect<int> &rcROI2. int w1. const CRect<int> &rcROI2). the start angle of projection the angular increase at each step value in pDst to indicate object pixels Parameters pDst pred dStartAngle dStepInc tObj 3. The size of pdAngle should be the same as ROI1.Width() and the number of angles is ROI2. int h1. T2 *pDst. point (x. Each line of ROI1 is the CP Radon transform projection at an angle (given by pdAngle).(a) (b) (c) Figure 48: An example of the ImgRadon function. class T2. (a) Source image. Parallel geometry is assumed. (b) Radon transformed image. class T2> void ImgIntegral (const T1 *pSrc. int w2. class T2> void ImgIntegral (const T1 *pSrc. See Table 2 for common parameters Pixels == 0 are definitely background. in between are edge points. in between are edge points. == tObj are definitely objects. if pred(pSrc[y*w+x]) is true. It is different from X-ray penetration of objects. Description Radon transform for visual hull This function mimics non-penetrating light projection on objects. template <class T1. int h1. (c) Inverse Radon trasformed image by filtered backprojection.y) is considered an object point. T2 *pDst. all pixels in the backprojected field are set as objects. const CRect<int> &rcROI1. At the start.

See Table 2 for common parameters Parameters 3. Euclidean connectivity of an object. T2 *pSum2. The 1st object’s bounding rect is (*pvRect)[0]. const CRect<int> &rcROI2. int h. nMinArea nMaxArea pvRect pvArea Return Example (a) (b) (c) Figure 49: An example of the ImgLabeling function. int w2.50 ImgLabeling template <class T1. 51 . const CRect<int> &rcROI3). int nMaxArea = 0. Object larger than nMaxArea pixels are discarded. vector<CRect<int> > *pvRect = 0. each rect should be offset r1. class T2. (c) Labeled image with nMinArea = 150. int nConnectivity. Description Calculate two integral images The first version calculates the summation and the second version calculates both the summation and the summation of square. Each color represents an object and the background is white. int nMinArea = 0. (a) Source image. >1: pixels within this distance are one object. bounding rectangle of each object (input 0 to ignore) It is with respect to ROI2. To obtain a bounding rect with respect to ROI1. Pred pred.LeftTop().T2 *pSum. class Pred> void ImgFilling (T *pImg. int nConnectivity). class Pred> int ImgLabeling (const T1 *pSrc. The 3rd object’s number of points is (*pvArea)[2]. vector<int> *pvArea = 0). T value.51 ImgFilling template <class T. 0: 4-neighbour labeling algorithm. int w. Object fewer than nMinArea pixels are discarded. 1: 8-neighbour labeling algorithm. Pred pred. const CRect<int> &rcROI1.y) is considered an object point. number of points of each object (input 0 to ignore) the number of objects found The 1st object can be found by checking if(pDst[y*w+x]==1). Description Parameters pred nConnectivity Connectivity labeling algorithm See Table 2 for common parameters if pred(pSrc[y*w+x]) is true. int w2. int h2. int h3. const CRect<int> &rcROI2. 3. const CRect<int> &rcROI. int w1. the point (x. int h1. int h2. CPt2D<int> ptSeed. Dark pixels are to be labeled. T2 *pDst.LeftTop()-r2. Objects fewer than 150 pixels are discarded. Each pixel in pSum (pSum2) is the summation (summation of square) of all pSrc’s pixels in the left-top region with respect to and including that pixel. int w3. (b) Labeled image.

double *pdXCen. Only three predicates are valid: equal to. int h. int h. greater equal. double *pdYCen). int w.53 ImgCentroid template <class T> bool ImgCentroid (const T *pImg. 1: 8-neighbour filling algorithm. (a) Source image. Other predicates such as greater or less may cause dead loop. 0: 4-neighbour filling algorithm.value) is true. 3.y) is considered boundary. so they should be strictly prohibited. Seed (a) (b) Figure 50: An example of the ImgFilling function. 3.52 ImgThinning template <class T> void ImgThinning (T *pImg. (b) Filled image. The point is the seed of filling. the point (x. 52 . Description Parameters NonObjID Thinning algorithm See Table 2 for common parameters Pixels with value==NonObjID are treated as background. const CRect<int> &rcROI. const CRect<int> &rcROI. (b) Thinned image. Connectivity: 4-neighbour filling algorithm. less equal. int w. >1: pixels within this distance are filled. T ObjID. (a) (b) Figure 51: An example of the ImgThinning function. Filling value: 200. pred (boundary condition): less equal. initial seed point for filling Euclidean connectivity of a filling region. (a) Source image.Description Parameters value pred ptSeed nConnectivity Fill a region bounded by a predicate condition See Table 2 for common parameters value to fill with if pred(pImg[y*w+x]. T ObjID. T NonObjID).

See Table 2 for common parameters a vector pointer that stores the found boundary points the number of boundary points 3. Holes are detected. See Table 2 for common parameters a vector pointer that stores the found boundary points the number of boundary points (a) (b) (c) Figure 52: Examples of the ImgBoundaryOrdered and ImgBoundaryUnordered functions. true: the centroid of an object is found. (a) Source image. const CRect<int> &rcROI. Description Parameters pvPos Return Get unordered boundary points. vector<CPt2D<int> > *pvPos). Description Parameters pvPos Return Get clockwise ordered boundary points. in clockwise order. false. Holes are not detected as boundary. Description Parameters pvPos Return Get the outer corner points of an object Outer corner points are used to calculate the convex hull. int w. if found. int w. if found. (b) Ordered boundary. the number of outer corner points 53 . const CRect<int> &rcROI. const CRect<int> &rcROI. (c) Unordered boundary. int h. 3. otherwise. y coordinate of the center. int h. int h. T ObjID.54 ImgBoundaryOrdered template <class T> int ImgBoundaryOrdered (const T *pImg. See Table 2 for common parameters stores the outer corner points. Holes are detected as boundary. vector<CPt2D<int> > *pvPos). based on 8-neighbour connectivity.Description Parameters pdXCen pdYCen Return Get the centroid of an object See Table 2 for common parameters x coordinate of the center. 3. T ObjID. vector<CPt2D<int> > *pvPos). int w.55 ImgBoundaryUnordered template <class T> int ImgBoundaryUnordered (const T *pImg.56 ImgOuterCorners template <class T> int ImgOuterCorners (const T *pImg. T ObjID. based on 8-neighbour connectivity. Holes are ignored.

T ObjID. (a) Source image. const CRect<int> &rcROI. CSize2D<double> *pSize). int h. T ObjID.58 ImgBoundingBox template <class T> bool ImgBoundingBox (const T *pImg. Note that inner corners of a hole are not treated as corner points. int h. double dAngle. 54 . vector<CPt2D<int> > *pvCH).57 ImgConvexHull template <class T> int ImgConvexHull (const T *pImg. anticlockwise) center of the box size of the box true: succeeded. false: failed (no object points). (b) Convex hulls of each object. T ObjID.59 ImgMinBoundingBox template <class T> bool ImgMinBoundingBox (const T *pImg. 3. Dark pixels are considered as objects for detecting convex hulls. CSize2D<double> *pSize. anticlockwise) true: succeeded. const CRect<int> &rcROI. Dark pixels are considered as objects for detecting corner points. int w. const CRect<int> &rcROI. (b) Corner points of each object. false: failed (no object points). 3. int h.(a) (b) Figure 53: An example of the ImgOuterCorners function. Description Parameters pptCenter pSize pdAngle Return Get the minimum bounding box of an object See Table 2 for common parameters center of the box size of the box angle of the box (radius. Description Parameters pvCH Return Get the convex hull points in clockwise order See Table 2 for common parameters output convex hull points (in clockwise order) the number of convex hull points (a) (b) Figure 54: An example of the ImgConvexHull function. Description Parameters dAngle pptCenter pSize Return Get the fixed-angle bounding box of an object See Table 2 for common parameters angle of the bounding box (radius. CPt2D<double> *pptCenter. int w. CPt2D<double> *pptCenter. (a) Source image. 3. double *pdAngle). int w.

55 . int nDist. int h2. int h1. int h1. T2 *pDst. const CRect<int> &rcROI2. ImgMinBoundingBox. false: failed (no object points). const CRect<int> &rcROI1. const CRect<int> &rcROI.3. unsigned long *pnDst. (b) Minimum area bounding box. int w2. const CRect<int> &rcROI2. the number of polygon vertices Parameters pvPos Return (a) (b) (c) (d) Figure 55: Examples of the ImgBoundingBox. 3. See Table 2 for common parameters a background pixel is set to 0. int nMinPts). T ObjID. (c) Minimum area bounding circle. T ObjID. T threshold). class T2> int ImgWatershed (const T1 *pSrc. int w1. double *pdRadius). (a) Bounding box at a fixed angle of 27 deg. Description Parameters pptCenter pdRadius Return Get the minimum bounding circle of an object See Table 2 for common parameters center of the circle radius of the circle true: succeeded. CPt2D<double> *pptCenter. int h. an object pixel is set to the square of the Euclidean distance to its nearest background pixel. Only end points of a line are kept as the polygon vertices. int h. See Table 2 for common parameters stores the polygon vertices. Description Parameters pnDst threshold Distance transform algorithm Reference ”Euclidean Distance Mapping” by P. vector<CPt2D<int> > *pvPos). 3. ImgMinBoundingCircle.60 ImgMinBoundingCircle template <class T> bool ImgMinBoundingCircle (const T *pImg. const CRect<int> &rcROI. and ImgMinBoundingPolygon functions. pixels >= threshold in pSrc are objects. const CRect<int> &rcROI1. 3. int w.61 ImgMinBoundingPolygon template <class T> bool ImgMinBoundingPolygon (const T *pImg. int w. Description Get the minimum bounding polygon of an object Such polygon differs from a complete list of boundary points in that it removes points on any straight line parallel to X or Y axis. int w1. int w2. Danielsson. in clockwise order.62 ImgDistTrans template <class T> void ImgDistTrans (const T *pSrc. int h2.63 ImgWatershed template <class T1. (d) Minimum area bounding polygon. pixels < threshold in pSrc are background.

etc. Maxima whose number of points are < nMinPts are discarded. -1 means the last. It outputs an object map similar to that produced by ImgLabeling(. The second-pass propagation finishes the segmentation.64 ImgEdgeX template <class T> int ImgEdgeX (T *pImg. 1 means the first edge point. nHalfFltLen-1 pixels boundary of the ROI is not scanned. (c) Watershed segmented image. Description 1D edge detection in x direction (description applicable to y direction) 1D edge detection based on the contrast of image data along x or y direction. The average intensity of the two sections are calculated. 1: 8-neighbour merging. int nHalfFltLen. etc.Description 1 2 3 4 Parameters nDist nMinPts Return Watershed algorithm for segmentation This function assumes the input pSrc a distance map. The first-pass propagation estimates the number of points grown by each maxima within each object. int w. 3. At each point. while a negative edge indicates decreasing. all edge points are output. obtained from ImgDistTrans(. a positive edge indicates the data values are increasing. threshold of the number of points grown by a maximum. In the object map. const CRect<int> &rcROI. previously connected regions are segmented. (a) Source image.. T tThre. One or multiple edge points at each line can be output to vptEdge. (b) Distance transformed image. Local maxima are located for each object. Both parameters are used to reduce over-segmentation. -2: the second last. the scan in y direction is top-to-bottom. for example. If nIndex is 0. 0: 4-neighbour merging. If their difference is >= tThre.. the center point is considered as an edge point. 2: the second... y direction: top-to-bottom). In the direction of scan (x direction: left-to-right. int nIndex. See Table 2 for common parameters the distance for merging local maxima. one edge point is selected. int nEdgeType. 255 128 0 (a) (b) (c) Figure 56: Examples of the ImgDistTrans and ImgWatershed functions. int h. nHalfFltLen specifies how many data to check to the left and right (x direction) or to the top and bottom (y direction) of a point. continued on next page 1 2 3 56 . otherwise -1. The scan of edge point in x direction is left-to-right.). int nDSY. There are two types of edges: positive and negative.). For example. The number of segmented objects. If nIndex is non-zero. vector<CPt2D<int> > *pvptEdge). >1: local maxima within this distance are merged. if succeeded.

) 3. 3.) store output edge points. int w. int nDSY. every other line is scanned. vector<CPt2D<double> > *pvptEdge). int nIndex. See Table 2 for common parameters edge contrast threshold edge type (-1: negative. 1: positive. 0: both) half-filter-length at each side of a point 1-based index of the edge point to be output downsampling gap in y direction (eg. Description 1D edge detection in x direction at subpixel accuracy All the parameters and the return value are the same as those of ImgEdgeX except for pvptEdge. each line. int nHalfFltLen. const CLine2D<int> &lnGuide. int nHalfFltLen. int w. vector<CPt2D<int> > *pvptEdge). int nHalfFltLen. int nEdgeType.66 ImgEdgeXSubpixel template <class T> int ImgEdgeXSubpixel (T *pImg. Some line may not have any edge point. only the one with larger contrast is output because they are likely to be part of a steep edge.Start() → lnGuide. If 1. vector<CLine2D<int> > *pvlnScan = 0). int nDSX. int nIndex. T tThre. const CRect<int> &rcROI. int nIndex. int h.End() → lnScan. whose x coord is at subpixel accuracy and y coord is still in integer pixel. Their direction is determined by lnGuide: lnGuide. int w. Description Parameters nDSX 1D edge detection in y direction (see ImgEdgeX for details) See Table 2 for common parameters downsampling gap in x direction (eg. const CRect<int> &rcROI. int nNumScan. int h. If 1. or if 2. const CRect<int> &rcROI. T tThre. int h.End() → lnScan. every other row is scanned.Start() → lnGuide. int nDSX.68 ImgEdgeAny template <class T> int ImgEdgeAny (T *pImg. int nEdgeType. T tThre. int nEdgeType.End() is clockwise.65 ImgEdgeY template <class T> int ImgEdgeY (T *pImg. vector<CPt2D<double> > *pvptEdge. whose y coord is at subpixel accuracy and x coord is still in integer pixel.4 Parameters tThre nEdgeType nHalfFltLen nIndex nDSY pvptEdge Return If two edge points of the same type are found within 2*nHalfFltLen pixels.Start() is anti-clockwise and lnGuide. int h. int nScanLen. vector<CPt2D<double> > *pvptEdge). each row. T tThre. or if 2. int nHalfFltLen. 3. the number of edge points found 3.67 ImgEdgeYSubpixel template <class T> int ImgEdgeYSubpixel (T *pImg. Description 1 Detect 1D edge based on a guiding line Multiple scan lines are generated perpendicular to the guiding line. int nEdgeType. continued on next page 57 . const CRect<int> &rcROI. int w. Description 1D edge detection in y direction at subpixel accuracy All the parameters and the return value are the same as those of ImgEdgeY except for pvptEdge.

58 . int h. const CLine2D<int> &lnScan. See Table 2 for common parameters a guiding line for searching for edge points edge contrast threshold edge type (-1: negative. Edge contrast is the difference of the average intensity of the nHalfFltLen pixels before and after an edge point. 0: both) scan length for an edge point half-filter-length at each side of a point store output edge points the number of edge points found Parameters lnScan tThre nEdgeType nScanLen nHalfFltLen pvptEdge Return scan lines edge points (a) guiding line edge points (b) scan line Figure 57: Examples of the ImgEdgeAny and ImgEdgeOnLine functions.2 3 4 Parameters lnGuide tThre nEdgeType nScanLen nHalfFltLen nNumScan pvptEdge pvlnScan Return In the direction of lnScan. 1: positive. vector<CPt2D<int> > *pvptEdge).End() for edge points. while a negative edge indicates decreasing data values. T tThre. a positive edge indicates the data values are increasing. All edge points with contrast >= tThre are output to pvptEdge but if two edge points of the same type are found within 2*nHalfFltLen pixels. if its contrast is larger than tThre.69 ImgEdgeOnLine template <class T> int ImgEdgeOnLine (T *pImg. See Table 2 for common parameters scan line for edge points edge contrast threshold edge type (-1: negative. int w. 0: both) scan length for an edge point half-filter-length at each side of a point the number of scan lines on the guiding line store output edge points at subpixel accuracy scan lines (input 0 to ignore) the number of edge points found 3. int nEdgeType. while a negative edge indicates decreasing. Edge contrast is the difference of the average intensity of the nHalfFltLen pixels before and after an edge point. On each scan line. Description Detect 1D edge on a line Scan from lnScan. In the direction of lnScan. (a) ImgEdgeAny and (b) ImgEdgeOnLine function. 1: positive. int nHalfFltLen.Start() to lnScan. const CRect<int> &rcROI. only the one with larger contrast is output because they are likely to be part of a steep edge. a positive edge indicates increasing data values. the maximum contrast (strongest) edge point is output.

y) = Kx*x + Ky*y + Z0 See Table 2 for common parameters Kx of the plane equation. If highThre ≤ lowThre. See Table 2 for common parameters low threshold for hysteresis thresholding high threshold for hysteresis thresholding Gaussian filter length (≥3) If highThre > lowThre. double *pdZ0). pImg stores edge (1) and non-edge (0). Ky of the plane equation. int w. Description Parameters pdKx pdKy pdZ0 Return Fit a plane to image data of an ROI Plane equation z(x. Pixels ≥ lowThre and connected to any pixel ≥ highThre are thresholded as edge (set to 1). (b) Canny edge. Those that are < lowThre or < highThre but not connected to any pixel > highThre are set to 0. if succeed. const CRect<int> &rcROI.72 ImgFitPlane template <class T> bool ImgFitPlane (const T *pImg. true: succeeded. 3. pImg stores edge (1) and non-edge (0). int h. double *pdKx. pImg stores edge magnitude. Description Canny edge detection algorithm The edge magnitude (gradient in the x and y directions) at each pixel is calculated and non-local-maximum pixels are set to 0. false: failed. Parameters lowThre highThre nFltLen 3. 59 . int nWinSize). or undefined. const CRect<int> &rcROI. (a) Source image. or undefined. int w. If highThre ≤ lowThre. T highThre. Then.71 ImgShenCastanEdge template <class T> void ImgShenCastanEdge (T *pImg.3.9] window size for calculating the edge contrast If highThre > lowThre. if succeed. double dStrength. int nFltLen). if succeed. (a) (b) (c) Figure 58: Examples of the ImgCannyEdge and ImgShenCastanEdge functions. Z0 of the plane equation. or undefined. T highThre. a hysteresis thresholding procedure is applied to extract the edge pixels. int h. pImg stores edge magnitude. T lowThre. Description Parameters lowThre highThre dStrength nWinSize Shen and Castan edge detection algorithm See Table 2 for common parameters low threshold for hysteresis thresholding high threshold for hysteresis thresholding ISEF filter strength [0. int h.70 ImgCannyEdge template <class T> void ImgCannyEdge (T *pImg. T lowThre. (c) ShenCastan edge. const CRect<int> &rcROI. 0. int w. double *pdKy.

int w. const T2 *pWei. + . int h. double *pdKy. which requires that the image data > 0..y) = +C0 + C1 x + C3 x2 + C6 x3 + . vector<int> *pvPowOfY).. Parameters threshold pdCoe Return 60 . + C? xN +C2 y + C4 xy + C7 x2 y + . double pdCoe[5]). int w1. Description Parameters pWei Weight version of ImgFitPolynomialSurf See Table 2 for common parameters weighting. or undefined.. parameters of the Gaussian function pdCoe[0]. (rcROI1. Description Fit a polynomial surface to the image data in an ROI Polynomial surface equation: z(x. int h1. int w2. int w. false: failed. Parameters N pvCoe pvPowOfX pvPowOfY Return template <class T1. store power of y of each term. int h2... . pdCoe[4] are A. + . const CRect<int> &rcROI. const CRect<int> &rcROI2. true: succeeded. const CRect<int> &rcROI. double *pdZ0). if succeed. vector<double> *pvCoe. class T2> bool ImgFitPlane (const T1 *pImg. const T2 *pWei. +C(N +1)(N +2)/2−1 y N See Table 2 for common parameters the order of the surface equation (should be >= 0) store coefficients. vector<int> *pvPowOfX. pvPowOfX and pvPowOfY will be (N+1)(N+2)/2 and their elements are ordered according to the index of C in the equation.. const CRect<int> &rcROI1.. or undefined. vector<int> *pvPowOfX.. rcROI2 must be the same size) 3.. const CRect<int> &rcROI2. (rcROI1. See Table 2 for common parameters image data < threshold are not used for fitting. if succeed. int h1. const CRect<int> &rcROI1. false: failed. B. After processing.. store power of x of each term. int N.. Fitting is based on a linear least squares method: the z coord of all points is converted to ln(z). vector<double> *pvCoe. int w1. int N. int h2... rcROI2 must be the same size) 3. the size of pvCoe.74 ImgFitGauss template <class T> bool ImgFitGauss (const T *pImg. int h. vector<int> *pvPowOfY). T threshold. . class T2> bool ImgFitPolynomialSurf (const T1 *pImg. Description Fit a 2D Gaussian function to image data of an ROI 2 2 Gaussian function: z = Ae−(x−B) /(2C)−(y−D) /(2E) . or undefined. true: succeeded.. E respectively. double *pdKx. if succeed.. pdCoe[1].73 ImgFitPolynomialSurf template <class T> bool ImgFitPolynomialSurf (const T *pImg. +C5 y 2 + C8 xy 2 + . +. int w2. The threshold must be > 0 because of logarithm.. Description Parameters pWei Fit a plane to weighted image data See Table 2 for common parameters weighting.template <class T1.

See Table 2 for common parameters start point of the line end point of the line sum of the line’s data the number of pixels on the line Parameters ptStart ptEnd pdSum Return 3. double *pdSum). Description Get the sum of a line’s data A point on the line is kept with subsample accuracy and obtains its datum by bilinear interpolation. value = i represent the ith contour.. then the pixel is a contour point. const CPt2D<int> &ptStart. const CRect<int> &rcROI. int h. if succeed. Parameters N pvCoe Return 3. See Table 2 for common parameters start point of the line end point of the line store image data falling on the line store points on the line (input 0 to ignore) the number of pixels on the line 3. const CPt2D<int> &ptEnd. int nContourLine). See Table 2 for common parameters image of contour object. T2 *pDst. vector<T> *pvDst. The least squares method is applied to each pair of pixels in pImg1 and pImg2 to find the coefficients. check which contour line is the nearest. For each pixel.3. int h. int w. int h2. true: succeeded. See Table 2 for common parameters the order of the polynomial equation (should be >= 0) store coefficients. vector<CPt2D<int> > *pvPos = 0). int w1. const CRect<int> &rcROI.78 ImgContour template <class T1. If the contour line’s value is in between. int w2. size must be w*h.76 ImgLineData template <class T> int ImgLineData (const T *pImg. const CRect<int> &rcROI. const T2 *pImg2. false: failed. const CRect<int> &rcROI1. Compare the pixel’s 4-way neighbours’ value. or undefined. + CN xN . Description Parameters ptStart ptEnd pvDst pvPos Return Get the image data falling on a line A point on the line is round off to integer sample accuracy.75 ImgFitImg template <class T> bool ImgFitImg (const T1 *pImg1. Description Fit a plane to image data of an ROI Let pImg1 and pImg2 be x and y respectively. int h. int h1. vector<double> *pvCoe). the fitting equation is y = C0 + C1 x + C2 x2 + .77 ImgLineSum template <class T> int ImgLineSum (const T *pImg. background is 0.. int w. int N. int w. number of contour lines to extract 61 . const CPt2D<int> &ptEnd. const CPt2D<int> &ptStart. Description 1 2 3 Parameters pDst nContourLine Get contour lines of the image data in an ROI Compute each contour line’s value. const CRect<int> &rcROI2. class T2> void ImgContour (const T1 *pSrc.

See Table 2 for common parameters an array of polygon corners (size must be nCount) the number of polygon corners the value to fill the polygon region indicate if mask inner or outer of the polygon Parameters ppt nCount value bMaskInner (a) (b) Figure 60: An example of the ImgMaskPolygon function. int h2. const CRect<int> &rcROI. int w2. (b) A polygon region is masked with value 255. int w1. const CPt2D<int> *ppt. then uses the mask to remove inner or outer image data. int nCount. It is much faster than explicitly checking if each pixel in the ROI is in or out of the polygon region. only one of these regions will be masked. This strategy only works on simple polygons (no two non-adjacent edges intersect). bool bMaskInner). (a) Source image. T value. T2 *pImg. int h1. If the ROI cuts the polygon into separate regions. const CRect<int> &rcROI1. class T2> void ImgMask (const T1 *pMask.79 ImgMask template <class T1. int h. Description Set image data based on a mask image Pixels of pImg are set to the mask value. Description Mask a polygon region The function first creates an internal image mask by filling. The main advantage of this function is speed. (a) Source image. 62 . (b) Contours of intensity. 3. ROI1 and ROI2 must be the same size.80 ImgMaskPolygon template <class T> void ImgMaskPolygon (T *pImg. if the corresponding pixels in the mask image are <= 0. int w. const CRect<int> &rcROI2. See Table 2 for common parameters the mask value Parameters value 3. Each gray scale represents a level of intensity.(a) (b) Figure 59: An example of the ImgContour function. T2 value).

int nStep). 3. const T2 *pCon. const T2 *pBK. const const T2 *pPS. const T2 *pPhase. const CRect<int> &rcROI. const T2 *pPhase. See Table 2 for common parameters pointer to an array of images (array size = nStep) output wrapped phase image output background image output contrast image phase-shift value at each step (array size = nStep) the number of phase-shifting steps (at least 3) 63 . int w1. int h. dX2 = 0. class T2> void (T1 **ppSrc. int w2. CRect<int> &rcROI2. int h3. int h1. double dY1.81 ImgMandelbrot template <class T> int ImgMandelbrot (T *pImg. All input images share the same ROI. const const T2 *pPS.3. dY2 = 1. T1 can be any integer or float type.7. int w1. T2 must be float or double to store the phase angles [−π. template <class T1. ImgPhaseShifting CRect<int> &rcROI1. class T2> void (T1 **ppSrc. CRect<int> &rcROI3. dY1 = -1. int w3. int h2. minimum bound of the Mandelbrot set in the x direction minimum bound of the Mandelbrot set in the y direction maximum bound of the Mandelbrot set in the x direction maximum bound of the Mandelbrot set in the y direction maximum iterations to be applied the min iterations used among all points to reach a decision that whether a point is in or out of the Mandelbrot set ROI ROI (a) (b) (c) Figure 61: An example of the ImgMandelbrot function. int nMaxIteration). double dX1. dX1 = -2. Description Parameters ppSrc pPhase pBK pCon pPS nStep General phase-shifting algorithm The general phase-shifting algorithm takes an arbitrary number of (≥3) phase-shifted images to compute a wrapped phase image. int nStep). (a) Large scale Mandelbrot image. CRect<int> &rcROI2. Pixel value contains how many iterations used to decide that the point is in or out of the Mandelbrot set. int w. template <class T1. Description Parameters pImg dX1 dY1 dX2 dY2 nMaxIteration Return Create a Mandelbrot pattern See Table 2 for common parameters output Mandelbrot image. The colors of the images are created by applying an intensity-to-color map. int w2.82 ImgPhaseShifting ImgPhaseShifting CRect<int> &rcROI1. int h2. (b) Zoom into the ROI shown in (a). int h1. double dY2. int h4. int w4. (c) Zoom into the ROI shown in (b).3. CRect<int> &rcROI4.05. double dX2. The phase-shift angle of each image may also be arbitrary. π].3.

int w3. const CRect<int> &rcROI1. int h3. int w1. T2 must be float or double to store the phase angles [−π. int w2. const CRect<int> &rcROI1. int h1. int h1. T2 *pCon. Although they look similar. int w2. class T2> void ImgPhaseShifting_5Frame (T1 **ppSrc[5]. int w2. template <class T1. class T2> void ImgPhaseShifting_Carre (T1 **ppSrc[4]. (f) Fringe contrast image. (e) Background intensity image. const CRect<int> &rcROI2). const CRect<int> &rcROI2. const CRect<int> &rcROI3. const CRect<int> &rcROI2. int w4. int h2. See Table 2 for common parameters pointer to an array of images (array size = 4) output wrapped phase image output background image output contrast image the estimated constant phase shift at each step Parameters ppSrc pPhase pBK pCon Return 3.83 ImgPhaseShifting Carre template <class T1. class T2> T2 ImgPhaseShifting_5Frame (T1 *ppSrc[5]. 64 . int w1. T2 *pBK. template <class T1. 3. the fringe pattern in each image shifts a constant phase angle. int h2. const CRect<int> &rcROI3. int w1. int h3. T2 *pPhase. T2 *pPhase. int h1. int h2. int w3. (d) Wrapped phase image. class T2> T2 ImgPhaseShifting_Carre (T1 *ppSrc[4]. Description Carr´ phase-shifting algorithm e Carr´ algorithm takes four images with a constant unknown phase shift. int h4. T2 *pCon. const CRect<int> &rcROI2). int w1. T1 can be any integer or float type. T2 *pBK. int h4.(a) (b) (c) (d) (e) (f) Figure 62: An example of the ImgPhaseShifting function. const CRect<int> &rcROI1. T2 *pPhase. int w2. const CRect<int> &rcROI4). int h1.84 ImgPhaseShifting 5Frame template <class T1. (a) (b) (c) Three phase-shifted images. const CRect<int> &rcROI1. const CRect<int> &rcROI4). All e input images share the same ROI. int h2. T2 *pPhase. int w4. π].

T *pGradVar. int h2. 3. const CRect<int> &rcROI1. const CRect<int> &rcROI2. See Table 2 for common parameters pointer to an array of images (array size = 5) output wrapped phase image output background image output contrast image the estimated constant phase shift at each step 3. int h2. int h2. (a) Unwrapped phase image. int w3. int w1. *pUnw. int h1. const CRect<int> &rcROI1. Wrapped phase image is as shown in Fig. const CRect<int> &rcROI2). const CRect<int> &rcROI3). int w1. T1 can be any integer or float type. (b) A linear carrier phase component is removed from the unwrapped phase image. int h3.86 ImgPhaseUnw QualGui <class T> void ImgPhaseUnw_QualGui *pWph. const CRect<int> &rcROI1. int h1.Description Parameters ppSrc pPhase pBK pCon Return 5-frame phase-shifting algorithm This algorithm takes five images with a constant unknown phase shift.85 ImgPhaseUnw LToR template <class T> void ImgPhaseUnw_LToR (const T *pWph. Description Parameters pWph pUnw Left-to-right phase unwrapping algorithm See Table 2 for common parameters input wrapped phase output unwrapped phase (a) (b) Figure 63: An example of the ImgPhaseUnw LToR function. int w2. Quality-guided phase unwrapping algorithm See Table 2 for common parameters input wrapped phase input quality map output unwrapped phase template (const T T T Description Parameters pWph pQual pUnw 3. All input images share the same ROI. const CRect<int> &rcROI2). int w1.87 ImgPhaseGradVar template <class T> void ImgPhaseGradVar (const T *pPhase. Description Parameters pPhase pGradVar Get phase-gradient-variance image See Table 2 for common parameters input phase output the inverse of phase gradient variance 65 . 62(d). *pQual. π]. T2 must be float or double to store the phase angles [−π. T *pUnw. int h1. int w2. int w2.

T1 tContrast. int h. 3. vector<CRect<int> > *pvRect). const CRect<int> &rcROI. int nMinFaceW. See Table 2 for common parameters min contrast of a valid square region minimum possible square size in pixel maximum possible square size in pixel summation of left-top region pixels. Description Parameters tContrast nMinFaceW nMaxFaceW pvlnEye pvrcFace pvSum pvSum2 Face detection algorithm See Table 2 for common parameters min contrast of a valid face region minimum possible face width in pixel maximum possible face width in pixel line from the left to the right eye ball of each detected face region of each detected face (For debugging purpose.90 ImgBlackSquareGrid template <class T1. vector<CLine2D<int> > *pvlnEye. Its memory space are allocated only if necessary. vector<CRect<int> > *pvrcFace = 0). Their memory space are allocated only if necessary. int nMaxSqu. class T2> void ImgSquareDetection (const T1 *pImg. int nMaxFaceW. T1 tContrast. class T2> bool ImgBlackSquareGrid (const T1 *pImg. int w. int nMinSqu.(a) (b) Figure 64: An example of the ImgPhaseUnw QualGui function. the number of faces detected Return 3. region of each detected square the number of squares detected Parameters tContrast nMinSqu nMaxSqu pvSum pvRect Return 3. int h. const CRect<int> &rcROI. 66 . int *pnCx. vector<CPt2D<double> > *pvptCor. vector<T2> *pvSum.4 is ignored. (b) A linear carrier phase component is removed from the unwrapped phase image. vector<T2> *pvSum. Description Detect black squares in an image Any square smaller than 6 pixels in width or larger than the image width or height/1.) summation of left-top region pixels summation of left-top region pixels’ square pvSum and pvSum2 are used internally. 62(d). int h. (a) Unwrapped phase image.88 ImgFaceDetection template <class T1. int w. vector<T2> *pvSum2. int nMinSqu. vector<T2> *pvSum. int *pnCy. T1 tContrast. int w. pvSum is used internally. int nMaxSqu. class T2> void ImgFaceDetection (const T1 *pImg. input 0 to ignore. const CRect<int> &rcROI.89 ImgSquareDetection template <class T1. Wrapped phase image is as shown in Fig.

otherwise. Refine corner locations of each square by intersecting edge lines. int *pH). Not to char. Detect squares using ImgSquareDetection(. Description Parameters pcFileName pvImg pW pH Return Read image data from ASCII files Applicable to integer. Description Detect a black square grid in an image In camera calibration. float . false: squares are too small or the number of squares is not identical in each row or column. 67 . false. (c) ImgBlackSquareGrid with bRough set to false (retrieve refined corners). See Table 2 for common parameters file name output image container image width image height true: succeeded. unsigned char. vector<CPt2D<int> > *pvptEdge = 0. This function detects the corners of all the squares. which are fitted to a square’s edge points.91 ImgReadASCII template <class T> bool ImgReadASCII (const char *pcFileName.).. vector<CLine2D<int> > *pvlnEdge = 0. (a) ImgSquareDetection. (b) ImgBlackSquareGrid with bRough set to true.vector<CRect<int> > *pvRect = 0. a black-square-grid pattern is often used. vector<T> *pvImg. int *pW. 3. Its memory space are allocated only if necessary. See Table 2 for common parameters min contrast of a valid square region minimum possible square size in pixel maximum possible square size in pixel summation of left-top region pixels. It is twice the number of squares in each row. Estimate corner locations by intersecting lines with outer squares. rough location of each square (input 0 to ignore) edge points on each square (input 0 to ignore) edge lines of each square (input 0 to ignore) indicate if search for rough corners only true: a black square grid is detected. 1 2 3 Parameters tContrast nMinSqu nMaxSqu pvSum pvptCor pnCx pnCy pvRect pvptEdge pvlnEdge bRough Return (a) (b) (c) Figure 65: Examples of the ImgSquareDetection and ImgBlackSquareGrid functions. bool bRough = false). It is twice the number of squares in each column.. the number of square corners in each column.. pvSum is used internally. the corner points of black square grid detected the number of square corners in each row. The lines are derived from the center of the four squares at the grid corner..

94 ImgSaveRaw template <class T> bool ImgSaveRaw (const T *pImg. true: succeeded. false. unsigned char will be saved as characters. const CRect<int> &rcROI. If ’pcFileName’ does not exist. Description Save image data to an ASCII file Int. Parameters pcFileName nOffset Return 3. 68 . if you want to save char value. otherwise.Width()*ROI. const char *pcFileName.92 ImgSaveASCII template <class T> bool ImgSaveASCII (const T *pImg. See Table 2 for common parameters file name true: succeeded. const CRect<int> &rcROI. which may be undesired. const char *pcFileName.3. bool bAppend = false). int h. true: succeeded. Description Read image data from a binary file The raw image data must match the data type T. So. int h.Height(). char. the input buffer are unchanged. The size of the data to be read is ROI. float type will be saved as in numbers. false. const char *pcFileName). See Table 2 for common parameters file name offset in bytes from the beginning of the file. false. int w. Description Parameters pcFileName bAppend Return Save raw image data as a binary file See Table 2 for common parameters file name whether append to the end of the file or create a new file.93 ImgReadRaw template <class T> bool ImgReadRaw (T *pImg. If the file cannot be opened. Parameters pcFileName Return 3. convert it to int first. int w. int nOffset). int h. const CRect<int> &rcROI. int w. otherwise. otherwise. a new file will be created. where raw image data start to be read.

2 CSize3D: 3D size class template <class T> class CSize3D { public: T cx. y(ty). z(tz) { } CPt3D<T>& operator = (const CPt3D<T> &pt). } void Rotate(const CLine3D<T> &lnAxis. Variable x y z Function operator = operator + = operator − = operator + operator − operator == operator != operator * Function SetPoint Rotate Description x coordinate of the point y coordinate of the point z coordinate of the point Description Assignment operator *this = *this + pt *this = *this − pt Return *this + pt Return *this − pt Check if *this is equal to pt Check if *this is not equal to pt Each x. T tz) { x = tx. double dAngle). z(pt. CPt3D<T> operator + (const CPt3D<T> &pt) const.1 3D geometry classes and functions CPt3D: 3D point class template <class T> class CPt3D { public: T x. bool operator != (const CPt3D<T> &pt) const. cz(0) { } CSize3D<T>(const CSize3D<T> &size). CPt3D<T> operator .x). T tcy. T tcz) : cx(tcx). y. 69 . const CPt3D<T> &pt). y(pt. bool operator == (const CPt3D<T> &pt) const. z(0) { } CPt3D<T>(const CPt3D<T> &pt) : x(pt. cz(tcz) { } CSize3D<T>& operator = (const CSize3D<T> &size).z) { } CPt3D<T>(T tx. cz. z coordinate multiples a value Description Set the x. y(0). T ty. z.(const CPt3D<T> &pt) const. CPt3D<T>() : x(0). y. void SetPoint(T tx. y = ty.y). T ty. CPt3D<T>& operator += (const CPt3D<T> &pt). }. T tz) : x(tx). CSize3D<T>() : cx(0). CPt3D<T>& operator -= (const CPt3D<T> &pt). y and z coordinates of the point Rotate the point with respect to an arbitrary line 4. template <class T> CPt3D<T> operator * (const CPt3D<T> &pt. template <class T> CPt3D<T> operator * (T val.4 4. cy(tcy). CSize3D<T>(T tcx. cy. T val). cy(0). z = tz.

0). const CPt3D<T> &ptEnd). &size) const. T y1. cy = tcy. CPt3D<T> *ppt) const. m_ptEnd(0. // Start and end point }. T z). m_ptEnd. bool operator == (const CLine3D<T> &line) const. T y. } }.0. &size) const. cz = tcz. Offset (const CPt3D<T> &ptOffset). T x2. End() const. GetPointAt(double dDist. T y2. const CPt3D<T> &ptArb.CSize3D<T>& CSize3D<T>& CSize3D<T> CSize3D<T> bool bool operator operator operator operator operator operator += -= + == != (const (const (const (const (const (const CSize3D<T> CSize3D<T> CSize3D<T> CSize3D<T> CSize3D<T> CSize3D<T> &size). CLine3D<T>& operator = (const CLine3D<T> &line). SetStart (const CPt3D<T> &pt). SetEnd (const CPt3D<T> &pt). const CPt3D<T> &ptEnd). T tcz) { cx = tcx. CPt3D<T> *ppt). SetLine (const CPt3D<T> &ptStart. SetCenter (const CPt3D<T> &pt). &size) const. CLine3D<T>(const CPt3D<T> &ptStart. IntersectPlane(const CPt3D<T> &ptVec. &size) const. CLine3D<T>(T x1. void SetSize(T tcx. T z1.0. private: CPt3D<T> m_ptStart. Length() const. Center() const.0) { } CLine3D<T>(const CLine3D<T> &line). T tcy. CPt3D<T> CPt3D<T> CPt3D<T> double void void void void void void bool bool Start() const. T z2). Variable cx cy cz Function operator = operator + = operator − = operator + operator − operator == operator != Description size in x direction size in y direction size in z direction Description Assignment operator *this = *this + size *this = *this − size Return *this + size Return *this − size Check if *this is equal to size Check if *this is not equal to size 4.3 CLine3D: 3D line segment class template <class T> class CLine3D { public: CLine3D<T>() : m_ptStart(0. Offset (T x. bool operator != (const CLine3D<T> &line) const. &size). Function operator = operator == operator != Description Assignment operator Check if *this is equal to line Check if *this is not equal to line 70 .

while dDist < 0 indicates the point is at the opposite side of the end point. CCube<T> operator | (const CCube<T> &cube) const. bool T T T CSize3D<T> CPt3D<T> CPt3D<T> void void void void void void void bool IsEmpty() const. bool operator == (const CCube<T> &cube) const. T ft. CCube<T>& operator = (const CCube<T> &cube). PtIn (T x. right. front. Inflate(T x. T z). Center() const. CCube<T> operator & (const CCube<T> &cube) const. CCube<T>() : left(0). T bm. top. T bk). T z) const. T rt. false: no intersect. T ft. Inflate(T lt. T ft. 71 . T y. T ft. T ft. T bm. Offset (const CPt3D<T> &ptOffset). T tp. CCube<T>(const CRect<T>& rect. back. dDist ppt Return IntersectPlane ptVec ptArb ppt Return 4. Offset (T x. the distance of the point from the start point. CCube<T>& operator |= (const CCube<T> &cube). Width() const. Size() const. T z). T bk). Deflate(T x. top(0). T bm. T y. T bm. SetCube(T lt. LeftTopFront() const. bottom. T tp. Depth() const. T rt. T bk). back(0) { } CCube<T>(const CCube<T> &cube). Deflate(T lt. the point found true: point found. CCube<T>& operator &= (const CCube<T> &cube). dDist > 0 indicates the point is at the same side as the end point. CCube<T>(T lt. T bk). T z). Height() const. Get the intersect of the line segment with a plane normal vector of the plane an arbitrary point on the plane store intersection point if found true: intersect found.4 CCube: cube class template <class T> class CCube { public: T left. T tp. Take the start point as a reference. T bk).Function Start End Center Length SetLine SetStart SetEnd SetCenter Offset GetPointAt Description Get the start point of the line Get the end point of the line Get the center of the line Get the length of the line Set the start and the end points of the line Set the start point of the line Set the end point of the line Set the center of the line Offset the position of the line Get a point on the line that has a specified distance from the star point. T y. right(0). bottom(0). false: cannot find such a point. T y. front(0). T rt. bool operator != (const CCube<T> &cube) const. T tp. T rt.

Function operator = operator &= operator |= operator & operator | operator == operator != Function IsEmpty Width Height Depth Size Center LeftTopFront Function SetCube Inflate Deflate Offset PtIn 4. bottom and back sides respectively. bottom and back side respectively. Variable left top front right bottom back PtIn (const CPt3D<T>& pt) const. Description left bound of the cube top bound of the cube front bound of the cube right bound of the cube bottom bound of the cube back bound of the cube Description Assignment operator *this = Intersect of two cubes *this = Union of two cubes Return intersect of two cubes Return union of two cubes Check if *this is equal to cube Check if *this is not equal to cube Description Check if it is an empty cube. bottom) AND pt. top. right) AND pt. ft. rt.z ∈ [f ront. Get the width (right − lef t) of the cube Get the height (bottom − top) of the cube Get the depth (back − f ront) of the cube Get the size of the cube Return the center of the cube Return the left-top-front point of the cube Description Set the left. if pt. CPt3D<T> operator [] (int idx) const { return m_ppt[idx]. Deflate the cube by lt. bottom and back value of the cube Inflate the cube by lt. } const CPt3D<T>& Vertex(int idx) const. bm. right. bm. bk on the left. private: 72 .bool }. and by z on the front and back sides respectively. tp. front. A cube is empty if its width. bk on the left. A point is side a cube. const CPt3D<T> &pt). right. front. void ReverseVertexSequence(). tp. by y on the top and bottom sides. CTri3D<T>& operator = (const CTri3D<T> &triangle). top.x ∈ [lef t. by y on the top and bottom sides. and by z on the front and back sides respectively. rt. Offset the position of the cube Check if a point is inside the cube. ft.y ∈ [top. Deflate the cube by x on the left and right sides. right. back). Inflate the cube by x on the left and right sides. height or depth is <= 0. void SetVertex(int idx. } CPt3D<T>& operator [] (int idx) { return m_ppt[idx].5 CTri3D: 3D triangle class template <class T> class CTri3D { public: CTri3D<T>() { } CTri3D<T>(const CTri3D<T> &triangle). front. top.

Function operator = operator [ ] Description Assignment operator Get vertex operator.size()). and 2. tri[2] = pt1. int Count() const { return int(m_vpt. Valid index is 0. Valid index is 0. tri[1] = pt2. Get a vertex value. 1. const CPt3D<T> &pt). void AddVertex( const CPt3D<T> &pt).7 CCylinder: cylinder class template <class T> class CCylinder { public: CCylinder<T>() : m_Radius(0) { } CCylinder<T>(const CCylinder<T> &cylinder). } Radius() const { return m_Radius. 73 . 1. } const CPt3D<T>& Vertex(int idx) const. private: vector<CPt3D<T> > m_vpt. Reverse vertex sequence.6 CPoly3D: 3D polygon class template <class T> class CPoly3D { public: CPoly3D<T>() { } CPoly3D<T>(const CPoly3D<T> &poly). } void ReverseVertexSequence(). const CPt3D<T> &pt). Set a vertex value. } SetCenterLine(const CLine3D<T> &lnCenter). }. CCylinder<T>(const CLine3D<T> &lnCenter.clear(). void Clear() { m_vpt. The 1st operator [ ] is for retrieving a vertex value. and 2. The 2nd operator [ ] is for setting a vertex value. } SetCylinder(const CLine3D<T> &lnCenter. CLine3D<T> T void void void CenterLine() const { return m_lnCenter. Vertex SetVertex ReverseVertexSequence 4. T radius). SetRadius(T radius) { m_Radius = radius. CPoly3D<T>(int nCount. Example: Old sequence: tri[0] = pt1. tri[2] = pt3. CPoly3D<T>& operator = (const CPoly3D<T> &poly). Function operator = Count Vertex AddVertex SetVertex Clear ReverseVertexSequence Description Assignment operator Get the number of vertices of the polygon Get the idx-th vertex of the polygon Add a vertex at the end of the vertex list Set the idx-th vertex value Remove all vertices of the polygon Reverse vertex sequence 4. Valid index is 0. CCylinder<T>& operator = (const CCylinder<T> &cylinder). 1. T radius). void SetVertex(int idx. tri[1] = pt2. and 2.CPt3D<T> m_ppt[3]. New sequence: tri[0] = pt3. }.

π]. Description pt1. const CPt3D<T> &pt2. pt2.private: CLine3D<T> m_lnCenter.8 Distance template <class T> double Distance (const CPt3D<T> &pt1. const CPt3D<T> &pt2). Description pt1 pt2 pt3 Return Get the angle in [0. 4.10 Angle template <class T> double Angle (const CPt3D<T> &pt1. pt3 74 . Function operator = CenterLine Radius SetCenterLine SetRadius SetCylinder Description Assignment operator Get the center line of the cylinder Get the radius of the cylinder Set the center line of the cylinder Set the radius of the cylinder Set the center line and radius of the cylinder 40 radius 20 Z center line 0 60 40 20 0 0 Y -20 -40 60 40 20 X Figure 66: An example of a cylinder. pt3 Return Get the area enclosed by three points input points the area enclosed by three points 4. pt1. // center line of the cylinder T m_Radius. const CPt3D<T> &pt2. formed by pt2. pt1. const CPt3D<T> &pt3). Description pt1 pt2 Return Get the distance between two points 1st input point 2nd input point the distance between the two points 4. pt3 1st input point (vertex of the angle) 2nd input point 3rd input point the angle formed by pt2. // radius of the cylinder }. const CPt3D<T> &pt3).9 Area template <class T> double Area (const CPt3D<T> &pt1.

Description Get the volume of a tetrahedron The tetrahedron’s four vertices are given by pt0. 4. it is better to determine the volume sign by testing if the volume is > 0. input points true: collinear. otherwise. otherwise. pt3 Return Check collinearity of three points input points true: collinear.5 rather than > 0 or < 0. vector<CPt3D<T> > *pvptOut. const CPt3D<T> &pt3). the volume is positive. const CPt3D<T> &pt1.0. pt0. This helps to prevent float precision errors.16 ConvexHull3D template <class T> bool ConvexHull3D (vector<CPt3D<T> > *pvptIn... vector<CLine3D<T> > *pvLine. const CPt3D<T> &pt2.14 NormalVector template <class T> CPt3D<T> NormalVector (const CPt3D<T> &pt1. . This function returns the normal vector of the plane. pt1. If the input points are collinear. pt2. Description pt1.13 Collinear template <class T> bool Collinear (const CPt3D<T> &pt1. 75 .15 Volume template <class T> double Volume (const CPt3D<T> &pt0. pt2. pt2. pt3 Return Note 4.11 MidPoint template <class T> CPt3D<T> MidPoint (const CPt3D<T> &pt1. therefore. int nCount).0). Description Get normal vector of a plane Three points defines a plane.12 Centroid template <class T> CPt3D<T> Centroid (const CPt3D<T> *ppt. const CPt3D<T> &pt2.4. const CPt3D<T> &pt3). otherwise the volume is negative. vector<CPoly3D<T> > *pvPoly. for integer data type. pt3.. false. Description ppt nCount Return Get the centroid of a set of points an array of points the number of points the centroid of the input points 4. pt3 Return 4. bool bTriFace). const CPt3D<T> &pt3). const CPt3D<T> &pt2. pt3. tetrahedron’s 4 vertices volume of the tetrahedron Internal volume computation is based on double.). the return value is (0. Description pt1 pt2 Return Get the midpoint of two points 1st input point 2nd input point the midpoint 4. and the thumb points to pt0. If right-hand rule applies (Four fingers curve in the order of pt1. false.5 or < -0. const CPt3D<T> &pt2). ..

or undefined. input point set. int nCount. + C? xN +C2 y + C4 xy + C7 x2 y + .18 FitPolynomialSurf template <class T1.. double *pdKx. vector<double> *pvCoe. if succeed. parameter Z0 of the plane equation. I roughly tested that 1024 is a very safe bound. This is used for DelaunayTriangulation. Description Least squares fitting of a polynomial surface Polynomial surface equation: z(x. int nCount. vector<int> *pvPowOfY). if false. int N. if succeed. output triangular faces that may be coplanar.Description pvptIn pvptOut pvLine pvPoly bTriFace Return Get the 3D convex hull of a set of points Reference ”Computational geometry in C” by Joseph O’Rourke. true: succeeded. 40 Z 20 0 100 50 X 0 0 20 40 60 80 100 Y Figure 67: An example of the ConvexHull3D function. false: failed. Description ppt pWei nCount pdKx pdKy pdZ0 Return Least squares fitting of a plane Plane equation z(x. output non-coplanar polygon faces. 4.17 FitPlane template <class T1.. double *pdKy. if succeed. class T2> bool FitPolynomialSurf (const CPt3D<T1> *ppt.. the convex hull is composed of triangles. const T2 *pWei. parameter Ky of the plane equation. You can try higher value but be careful. large input value may render the computation go out of range. I add a postprocessing step to output polygon faces of the hull. class T2> bool FitPlane (const CPt3D<T1> *ppt. (modified during processing) output convex hull vertexes (input 0 to ignore) output convex hull edges (input 0 to ignore) output convex hull polygon faces (must NOT be 0) if true. or undefined. double *pdZ0). or undefined. ConstructPolygon(.y) = +C0 + C1 x + C3 x2 + C6 x3 + .. 4.y) = Kx*x + Ky*y + Z0 points to be fitted (size must be nCount) weighting factor array (input 0 to ignore) size of ppt array and weighting array parameter Kx of the plane equation.) is for this purpose.. vector<int> *pvPowOfX. Due to volume computation required by the function. Based on the book. true: succeeded. const T2 *pWei. false: failed (points are coplanar). continued on next page 76 .

. or undefined.. Description Least squares fitting of a 2D Gaussian function 2 2 Gaussian function: z = Ae−(x−B) /(2C)−(y−D) /(2E) .. +C(N +1)(N +2)/2−1 y N points to be fitted (size must be nCount) weighting factor array (input 0 to ignore) the order of the surface equation (should be >= 0) store coefficients. 4000 100 2000 Z 50 0 0 50 50 100 0 50 Z Y X 100 0 X 100 100 80 60 40 20 0 Y (a) (b) Figure 68: Examples of the (a) FitPlane and the (b) FitPolynomialSurf functions. 4. . pdCoe[1]. +.. store power of x of each term. the size of pvCoe. false: failed.... ppt nCount pdCoe Return 40 Z 20 0 100 50 X 0 0 20 40 60 80 100 Y Figure 69: An example of the 2D FitGauss function.. if succeed. B. store power of y of each term. if succeed. E respectively.. + .. int nCount. or undefined. double pdCoe[5]).. pvPowOfX and pvPowOfY will be (N+1)(N+2)/2 and their elements are ordered according to the index of C in the equation. After processing. or undefined. pdCoe[4] are A. Fitting is based on a linear least squares method: the z coordinate of all points is converted to ln(z).19 FitGauss template <class T> bool FitGauss (const CPt3D<T> *ppt. 77 . false: failed. + .ppt pWei N pvCoe pvPowOfX pvPowOfY Return +C5 y 2 + C8 xy 2 + . if succeed. which requires that z > 0. true: succeeded. points to be fitted (size must be nCount) size of ppt array parameters of the Gaussian function pdCoe[0].. true: succeeded..

int h2. const CCube<int> &cbROI1.4 ImgCopyXZ 2D template <class T1. Description Parameters Copy image data from source image ROI1 to destination image ROI2 Width. int w. const CRect<int> &rcROI1. 5. int h1. const CRect<int> &rcROI1. int w1. T2 *pDst. int d1. int d1. x-th column element can be retrieved by *(pImg+(z*h+y)*w+x) or pImg[(z*h+y)*w+x]. int y. T2 *pDst. Pointer to the source image Pointer to the destination image Image width. int w1. Description Parameters value Assign image data in an ROI to the input value See Table 3 for common parameters the value to be assigned to the image data 5. int h2. y-th row. int z. int h1. h. int h. class T2> void ImgCopyXY_2D (const T1 *pSrc. T value).1 ImgAssign3D template <class T> void ImgAssign3D (T *pImg. int d. See Table 3 for common parameters 5. int d1.2 ImgCopy3D template <class T1. int h1. Description Parameters z Copy ROI1 in a X-Y slice of a 3D image to ROI2 in a 2D image See Tables 2 and 3 for common parameters z-direction index of the X-Y slice in the 3D image 5. int d2. int w2. int w1. int w2. class T2> void ImgCopyXZ_2D (const T1 *pSrc. height and depth Region of interest. d cbROI Table 3: Common parameters of 3D image processing functions. Some parameters are common to most functions. class T2> void ImgCopy3D (const T1 *pSrc. Description Parameters y Copy ROI1 in a X-Z slice of a 3D image to ROI2 in a 2D image See Table 2 and 3 for common parameters y-direction index of the X-Z slice in the 3D image 78 . const CCube<int> &cbROI2).5 3D image processing functions Type T* Name pImg Description Pointer to a continuous memory space which must be equal to or larger than w*h*d*sizeof(T) bytes. T* T* int CCube<int>& pSrc pDst w. T2 *pDst. const CCube<int> &cbROI. int h2. Only image data within the ROI will be used or modified. The z-th frame. const CRect<int> &rcROI2). int w2. const CRect<int> &rcROI2). They are listed in Table 3.3 ImgCopyXY 2D template <class T1. height and depth of ROI1 and ROI2 must be the same.

T2 *pDst. const CRect<int> &rcROI2). int h2. int x. int h1. int w1. int h1. int w1. const CRect<int> &rcROI2.5. fromMax] to Dst data to the range [toMin. Linear translation parameters a and b is determined by: a * fromMin + b = toMin. int h2.8 ImgCopy2D YZ template <class T1. T1 fromMax. int d1. Data points in Src that are < fromMin or > fromMax will be translate to toMin and toMax.5 ImgCopyYZ 2D template <class T1. class T2> void ImgLinear3D (const T1 *pSrc. int x). int h2. int d2. int h2.9 ImgLinear3D template <class T1.7 ImgCopy2D XZ template <class T1. int w2. const CCube<int> &cbROI1.6 ImgCopy2D XY template <class T1. const CRect<int> &rcROI1. T2 *pDst. const CRect<int> &rcROI1. const CRect<int> &rcROI1. int d2. int d2. T2 *pDst. Description Parameters x Copy ROI1 in a Y-Z slice of a 3D image to ROI2 in a 2D image See Table 2 and 3 for common parameters x-direction index of the Y-Z slice in the 3D image 5. Description Parameters y Copy ROI1 in a 2D image to ROI2 in a X-Z slice of a 3D image See Tables 2 and 3 for common parameters y-direction index of the X-Z slice in the 3D image 5. int w2. class T2> void ImgCopy2D_XY (const T1 *pSrc. See Table 3 for common parameters source minimum bound source maximum bound destination minimum bound destination maximum bound Parameters fromMin fromMax toMin toMax 79 . a * fromMax + b = toMax. Description Parameters x Copy ROI1 in a 2D image to ROI2 in a Y-Z slice of a 3D image See Tables 2 and 3 for common parameters x-direction index of the Y-Z slice in the 3D image 5. int w2. int y). int h1. Description Linear translate Src data in the range [fromMin. class T2> void ImgCopy2D_YZ (const T1 *pSrc. pSrc and pDst may point to the same image buffer. int d2. Description Parameters z Copy ROI1 in a 2D image to ROI2 in a X-Y slice of a 3D image See Tables 2 and 3 for common parameters z-direction index of the X-Y slice in the 3D image 5. int h1. T2 toMin. int d1. int w2. int w1. toMax]. class T2> void ImgCopyYZ_2D (const T1 *pSrc. int z). const CCube<int> &cbROI2. int w1. T2 *pDst. int w1. if ROI1 and ROI2 are the same. const CRect<int> &rcROI1. T2 *pDst. int h2. class T2> void ImgCopy2D_XZ (const T1 *pSrc. int h1. T2 toMax). T1 fromMin. int w2. const CRect<int> &rcROI2. const CRect<int> &rcROI2.

int d1. const CCube<int> &cbROI1. int h1. int h1. int h. int h. Mean filter. int h. int nKerD). int w2. const CCube<int> &cbROI). T *pDst. const CCube<int> &cbROI2. const CCube<int> &cbROI. const CCube<int> &cbROI1. int w. int w2. int d. int d. int w. class T2> void ImgFltVariance3D (const T1 *pSrc.11 ImgMax3D template <class T> T ImgMax3D (const T *pImg. Description Parameters pMin pMax Get the minimum and maximum value of an ROI See Table 3 for common parameters return the minimum value of an ROI return the maximum value of an ROI 5. T *pMax).13 ImgMean3D template <class T> T ImgMean3D (const T *pImg. int d. int d. const CCube<int> &cbROI).14 ImgFltMean3D T> void ImgFltMean3D int w1. Description Parameters Return Get the minimum value of an ROI See Table 3 for common parameters the minimum value of an ROI 5. const CCube<int> &cbROI2. int h2. nKerH.12 ImgMinMax3D template <class T> void ImgMinMax3D (const T *pImg. int nKerW. int w. int Description Parameters nKerW nKerH nKerD Example 5. int d2. int h. See Table 3 for common parameters filter kernel width filter kernel height filter kernel depth nKerW*nKerH*nKerD = 3*3*3 or 7*5*3 template <class (const T *pSrc. int d2. int d1. int w. Description Parameters Return Get the mean value of an ROI See Table 3 for common parameters the mean value of an ROI 5. const CCube<int> &cbROI). 80 . int nKerD). int nKerW. kernel certer equal to kernel mean Half-filter-length data at the ROI boundary are filtered with reduced sized kernel.5.10 ImgMin3D template <class T> T ImgMin3D (const T *pImg. int nKerH. int h2.15 ImgFltVariance3D template <class T1. int w1. Description Parameters Return Get the maximum value of an ROI See Table 3 for common parameters the maximum value of an ROI 5. T2 *pDst. T *pMin.

int nLen). See Table 3 for common parameters pointer to the convolution mask data array mask array size Parameters pMask nLen 5. int h1. minification is always a downsampling process based on averaging. Description 1D convolution in z direction Convolution is applied on each trace (z direction). 0: X axis (points to the right). const CCube<int> &cbROI1. int d2. int w. int nAlgo).17 ImgResize3D template <class T1. int d. Half-filter-length data at the ROI boundary are unchanged. int nAngle). int h. otherwise nothing is done.16 ImgConv3DZ template <class T1. T2 *pDst. Parameters nAlgo 5. class T2> void ImgConv3DZ (T1 *pImg. const T2 *pMask.18 ImgRotate3D template <class T1. int h2. 1: Y axis (points to the bottom). both minification and magnification are based on nearest neighbour. class T2> void ImgResize3D (const T1 *pSrc. const CCube<int> &cbROI. 4: natural cubic spline interpolation. Parameters nAxis nAngle 81 . 1: linear interpolation. int w2. int d2. Description Rotate ROI1 of Src and copy to ROI2 of Dst The size of ROI1 and ROI2 must satisfy certain relationship based on the angle of rotation. 3: Catmull-Rom spline interpolation. int h1. int w1. anti-clock wise angle (right-hand rule) of rotation in degree. If nearest neighbour (nAlgo: 0) is used.Depth(). T2 *pDst. kernel certer equal to kernel variance Half-filter-length data at the ROI boundary are filtered with reduced sized kernel. int d1. int w2. const CCube<int> &cbROI2. int h2. Only multiples of 90-degree are accepted. int d1. See Table 3 for common parameters with respect to which axis to rotate. const CCube<int> &cbROI2. 2: cubic B-spline interpolation. Description Resize ROI1 of Src and copy to ROI2 of Dst If linear (nAlgo: 1) or spline (nAlgo: 2–4) is used. See Table 3 for common parameters interpolation algorithm 0: nearest neighbour interpolation. const CCube<int> &cbROI1. Magnification is done by the specified method. See Table 2 for common parameters filter kernel width filter kernel height filter kernel depth nKerW*nKerH = 3*3 or 7*5 5. class T2> void ImgRotate3D (const T1 *pSrc. 2: Z axis (points outside the screen). The mask data array size must satisfy nLen+(nLen-1)/2 ≤ ROI.Description Parameters nKerW nKerH nKerD Example Variance filter. int w1. int nAxis.

int nCoarH. const T *pImg2.19 ImgFlip3D template <class T> void ImgFlip3D (T *pImg. nDSX. Description Search for ROI2 of pChild in ROI1 of pMother ROI1. const CCube<int> &cbROI2. const CCube<int> &cbROI1. Go back to 2 until nDSX. 1: top-bottom flipped. y and z directions. int w. After a new best-match window is found. ROI2 is matched to windows in ROI1 separated by nDSX. int &nWinZ. const T *pChild. int h.Depth() Initially.5. ROI1 and ROI2 must be the same size. int nCoarDSX. int nCoarX. nDSY and nDSZ are halved. 2: front-back flipped. int d1. int w1. vector<CPt3D<int> > *pvptDisp.Depth() must be >= ROI2. vector<double> *pvCorr). int nCoarZ. int nFineX. int nFineDSX.Height() must be >= ROI2. the best-match point in ROI1 coordinate (left-top-front corner of the matched cube) normalized correlation coefficient. int nFineDSZ. const CCube<int> &cbROI1. int nCoarDSZ. a 3*3*3 grid centered on the bestmatch window. The windows are separated by nDSX. int nCoarY.1] 1 2 3 Parameters nDSX nDSY nDSZ pptMatch pdCorr 5. nDSY and nDSZ. int nCoarW. vector<CPt3D<int> > *pvptCenter.Height() ROI1. int w1. int nFineD. double *pdCorr). in [-1. int d. nDSY and nDSZ are further halved. nDSY and nDSZ in the x. int h2. int nFineY. CPt3D<int> *pptMatch. Description Parameters nDirection Flip the image data in an ROI See Table 3 for common parameters 0: left-right flipped. Then ROI2 is matched to 27 windows. int nCoarD. int nCoarDSY.20 ImgMatch3D template <class T> void ImgMatch3D (const T *pMother. Description Pixel flow or motion estimation Estimate the pixel motion from ROI1 in pImg1 to ROI2 in pImg2. continued on next page 82 . int nFineDSY. int nDirection). int w2. int h1. int nDSX. int d1. const CCube<int> &cbROI2. nDSY and nDSZ equal to 1 pixel. int &nWinY.Width() ROI1. int nFineZ. 5. int nDSY. int nFineH. int nFineW.21 ImgMotion3D template <class T> void ImgMotion3D (const T *pImg1. After the best-match window is found. int d2. int nDSZ.Width() must be >= ROI2. See Table 3 for common parameters initial downsampling gap in x direction initial downsampling gap in y direction initial downsampling gap in z direction The downsampling gaps are used in shifting ROI1 across ROI2 and in accessing the pixels in ROI1 and ROI2. int w2. int &nWinX. int h1. int h2. int d2. nDSX. const CCube<int> &cbROI.

class Pred> int ImgLabeling3D (const T1 *pSrc. 0: 6-neighbour labeling algorithm. Results are stored in pvptCenter. continued on next page nMinVol nMaxVol 83 . int nMaxVol = 0. which are arrays of the same size: nWinX * nWinY * nWinZ (at output). int d1. const CCube<int> &cbROI2. See Table 3 for common parameters coarse search window width coarse search window height coarse search window depth coarse search distance in x direction coarse search distance in y direction coarse search distance in z direction coarse search downsampling gap in x direction coarse search downsampling gap in y direction coarse search downsampling gap in z direction fine search window width fine search window height fine search window depth fine search distance in x direction fine search distance in y direction fine search distance in z direction fine search downsampling gap in x direction fine search downsampling gap in y direction fine search downsampling gap in z direction input desired number of fine search windows in x direction output actual number of fine search windows in x direction input desired number of fine search windows in y direction output actual number of fine search windows in y direction input desired number of fine search windows in z direction output actual number of fine search windows in z direction center of fine search windows in pImg1 displacement of fine windows from pImg1 to pImg2. int w2. Pred pred. int d2. int w1. vector<CCube<int> > *pvCube = 0. int nMinVol = 0. and a small fine search window and search distance to obtain a high resolution. T2 *pDst. This includes the global shift from ROI1 to ROI2 correlation coefficient of each fine window 5. int h2. pvptDisp. Description Parameters pred nConnectivity Connectivity labeling algorithm See Table 3 for common parameters if pred(pSrc[(z*h+y)*w+x]) is true. int nConnectivity. int h1. Euclidean connectivity of an object. A large coarse search window and search distance may be used to obtain robust initial estimates.y. Object fewer than nMinVol pixels are discarded. The downsampling gap at each level is set independently.. 1: 26-neighbour labeling algorithm. See ImgMatch3D(.) for details of the downsampling gap. Results of the coarse search are used as the initial guess for the fine search. Object larger than nMaxVol pixels are discarded. const CCube<int> &cbROI1. class T2. the point (x.z) is considered an object point.1 2 3 Parameters nCoarW nCoarH nCoarD nCoarX nCoarY nCoarZ nCoarDSX nCoarDSY nCoarDSZ nFineW nFineH nFineD nFineX nFineY nFineZ nFineDSX nFineDSY nFineDSZ nWinX nWinY nWinZ pvptCenter pvptDisp pvCorr There are two levels of search: a coarse search based on a few coarse windows and a quality-guided fine search on all fine windows. >1: pixels within this distance are one object. pvCorr.22 ImgLabeling3D template <class T1. vector<int> *pvVol = 0)..

int w2. Description Watershed algorithm for segmentation This function assumes the input pSrc a distance map. int h1. const CCube<int> &cbROI1. int w1.value) is true. Description Parameters pnDst dZSpacing threshold Distance transform algorithm Reference ”Euclidean Distance Mapping” by P. See Table 3 for common parameters a background pixel is set to 0. pixels >= threshold in pSrc are objects. int h2. int nMinPts). int d1. >1: pixels within this distance are filled. each cube should be offset cb1. The pixel spacing in the x and y directions is assumed to be 1. It outputs an object map similar to that produced by ImgLabeling3D(. int d2. T2 *pDst. const CCube<int> &cbROI2. class T2> int ImgWatershed3D (const T1 *pSrc. the point (x.LeftTopFront()-cb2. T value. so they should be strictly prohibited. const CCube<int> &cbROI. int h2. int d1. T threshold). ptSeed nConnectivity 5..). less equal. const CCube<int> &cbROI2. The 3rd object’s number of points is (*pvVol)[2]. Other predicates such as greater or less may cause dead loop. int d2. frame spacing in z direction. int h. unsigned long *pnDst.y. Description Parameters value pred Fill a region bounded by a predicate condition See Table 3 for common parameters value to fill with if pred(pImg[(z*h+y)*w+x]. number of points of each object (input 0 to ignore) the number of objects found The 1st object can be found by checking if(pDst[(z*h+y)*w+x]==1). int h1.pvCube pvVol Return Example bounding cube of each object (input 0 to ignore) It is with respect to ROI2.. int d. int w2. int w1. 5.. In the object map. int w. The 1st object’s bounding cube is (*pvCube)[0].. double dZSpacing.LeftTopFront(). int nConnectivity).). const CCube<int> &cbROI1.25 ImgWatershed3D template <class T1. CPt3D<int> ptSeed. 0: 6-neighbour filling algorithm. obtained from ImgDistTrans3D(. an object pixel is set to the square of the Euclidean distance to its nearest background pixel. Pred pred. pixels < threshold in pSrc are background. Danielsson. To obtain a bounding cube with respect to ROI1. initial seed point for filling Euclidean connectivity of a filling region.z) is considered boundary.23 ImgFilling3D template <class T.24 ImgDistTrans3D template <class T> void ImgDistTrans3D (const T *pSrc. 1: 26-neighbour filling algorithm. int nDist. connected regions are segmented. class Pred> void ImgFilling3D (T *pImg. Only three predicates are valid: equal to. 5. continued on next page 84 . for example. greater equal.

27 ImgReadRaw3D template <class T> bool ImgReadRaw3D (T *pImg. Description Extract isosurface from 3D data Reference “Regularised marching tetrahedra: improved iso-surface extraction” by Graham Treece et al. threshold of the number of points grown by a maximum. Diagonal: 31. Refer to the paper ”Distance transformations in arbitrary dimensions” by Gunilla Borgefors for basic ideas. >1: local maxima within this distance are merged. int h. int d. Binarize the 3D data based on the input threshold. Double diagonal: 38. which represents the distance of each voxel to the object boundary. The first-pass propagation estimates the number of points grown by each maxima within each object. A distance code 22-31-38 is used. class T2> int IsoSurface (const T *pImg. Isosurface of a sphere. int w. See Table 3 for common parameters threshold for the object region filter kernel size (ignored if <= 1) output triangles of the isosurface the number of triangles on the isosurface 1 2 3 4 Parameters threshold nFltSize pvTri3D Return 180 160 140 Z 120 100 80 100 150 100 150 X Y Figure 70: An example of the ImgIsoSurface function. Use body-centered cube layout (partitioned by tetrahedra) to extract isosurface. int nFltSize. 0: 6-neighbour merging. const char *pcFileName. int w. The second-pass propagation finishes the segmentation. The number of segmented objects. int d. 5. 85 . y and z directions but it is not a requirement.) Voxels inside the object are > 0 and those outside are < 0.26 ImgIsoSurface template <class T1. vector<CTri3D<float> > *pvTri). if nFltSize is > 1. Smooth the distance map. T threshold. if succeeded. const CCube<int> &cbROI. Maxima whose number of points are < nMinPts are discarded. 5. 1: 26-neighbour merging.1 2 3 4 Parameters nDist nMinPts Return Local maxima are located for each object. int h. See Table 3 for common parameters the distance for merging local maxima. Compute a distance map. (Voxel width: 22. const CCube<int> &cbROI. otherwise -1. The 3D data are best to have the same pixel spacing in x. Both parameters are used to reduce over-segmentation. int nOffset).

Depth(). Description Parameters pcFileName bAppend Return Save raw image data as a binary file See Table 3 for common parameters file name whether append to the end of the file or create a new file. false. otherwise. See Table 3 for common parameters file name offset in bytes from the beginning of the file. where raw image data start to be read. true: succeeded.28 ImgSaveRaw3D template <class T> bool ImgSaveRaw3D (const T *pImg. false.Width()*ROI. int h. int d. If ’pcFileName’ does not exist. 86 . bool bAppend = false). the input buffer are unchanged. If the file cannot be opened. The size of the data to be read is ROI.Height()*ROI. const char *pcFileName. 5. otherwise. true: succeeded. const CCube<int> &cbROI. a new file will be created. int w.Description Parameters pcFileName nOffset Return Read image data from a binary file The raw image data must match the data type T.

Sign up to vote on this title
UsefulNot useful