40 #ifndef _D_MORPHOEUCLIDEAN_HPP
41 #define _D_MORPHOEUCLIDEAN_HPP
52 template <
class T1,
class T2>
54 const StrElt &se = DEFAULT_SE)
56 return _distance(imIn, imOut, se);
67 return sqr(p1.x - p2.x) + sqr(p1.y - p2.y) + sqr(p1.z - p2.z);
70 template <
class T1,
class T2>
72 const StrElt &se = DEFAULT_SE)
74 ASSERT_ALLOCATED(&imIn, &imOut);
75 ASSERT_SAME_SIZE(&imIn, &imOut);
80 typedef typename imageInType::lineType lineInType;
82 typedef typename imageOutType::lineType lineOutType;
85 lineOutType pixelsOut = imOut.getPixels();
90 vector<off_t> pixelsOffset(pixelCount, 0);
92 StrElt seLoc = se.noCenter();
94 off_t maxOffset = pixelCount;
106 for (
auto i = 0; i < pixelCount; i++) {
107 pixelsOffset[i] = maxOffset + 1;
108 if (pixelsIn[i] == T1(0))
111 IntPoint pt = imIn.getPointFromOffset(i);
113 bool oddLine = seLoc.odd && (pt.y % 2 != 0);
115 for (
auto it = seLoc.
points.begin(); it != seLoc.
points.end(); it++) {
120 if (oddLine && (ptNb.y + 1) % 2 != 0)
128 if (pixelsIn[ofNb] == 0) {
130 pixelsOffset[i] = ofNb;
148 while (!hq.isEmpty()) {
149 off_t pCurr = hq.pop();
150 if (pixelsOffset[pCurr] > maxOffset) {
151 std::cout <<
"BAD PLACE, BAD TIME." << int(pCurr)
152 <<
"goes out without pixelFrom\n";
156 IntPoint ptCurr = imIn.getPointFromOffset(pCurr);
158 bool oddLine = seLoc.odd && (ptCurr.y % 2 != 0);
159 for (
auto it1 = seLoc.
points.begin(); it1 != seLoc.
points.end();
164 if (oddLine && ((pt1.y + 1) % 2) != 0)
174 if ((pixelsIn[p1] == 0) || (pixelsOffset[p1] <= maxOffset))
180 for (
auto it2 = seLoc.
points.begin(); it2 != seLoc.
points.end();
185 bool oddLine2 = seLoc.odd && (pt1.y % 2 != 0);
186 if (oddLine2 && (((pt2.y + 1) % 2) != 0))
194 if (pixelsOffset[p2] <= maxOffset) {
196 off_t p3 = pixelsOffset[p2];
197 IntPoint pt3 = imIn.getPointFromOffset(p3);
199 int wd = sqModule(pt1, pt3);
200 if (wd < current_dist) {
214 pixelsOffset[p1] = pixelsOffset[oo];
222 template <
class T1,
class T2>
228 return func._exec(imIn, imOut, se);
size_t getPixelCount() const
Get the number of pixels.
Definition: DBaseImage.h:160
size_t getOffsetFromPoint(IntPoint &p) const
Get an offset for given x,y(,z) coordinates.
Definition: DBaseImage.h:276
bool isPointInImage(const IntPoint &p) const
isPointInImage() - checks if a Point is in inside the image bounds.
Definition: DBaseImage.h:224
Definition: DMorphoEuclidean.hpp:46
Definition: DMorphoHierarQ.hpp:143
Definition: DBaseImage.h:386
lineType getPixels() const
Get the pixels as a 1D array.
Definition: DImage.hpp:105
Base structuring element.
Definition: DStructuringElement.h:70
vector< IntPoint > points
List of neighbor points.
Definition: DStructuringElement.h:203
RES_T sqrt(const Image< T1 > &imIn, Image< T2 > &imOut)
sqrt() - square root of an image
Definition: DImageArith.hpp:926
RES_T distanceEuclidean(const Image< T1 > &imIn, Image< T2 > &imOut, const StrElt &se=DEFAULT_SE)
distanceEuclidean() - Euclidean distance function.
Definition: DMorphoEuclidean.hpp:223
Definition: DTypes.hpp:88