40 const long lineLength = lineBuf.size();
42 for (
long pos = 0; pos < lineLength; pos++)
47 unsigned offset = lineLength - pos;
48 left = leftend - magnitude * (pos + 1) * (pos + 1);
49 right = rightend - magnitude * offset * offset;
53 lineBuf[pos] = std::min(std::min(left, right), sigma);
60 LineBufferType & tmpLineBuf,
61 LabLineBufferType & labBuf,
62 LabLineBufferType & NewLabBuf,
66 const long lineLength = lineBuf.size();
70 for (
long pos = 0; pos < lineLength; pos++)
74 RealType thisval = lastval - magnitude * krange * krange;
76 if (lineBuf[pos] >= lineBuf[lastcontact])
79 lastval = lineBuf[pos];
81 tmpLineBuf[pos] = std::max(lineBuf[pos], thisval);
82 if (thisval > lineBuf[pos])
84 NewLabBuf[pos] = labBuf[lastcontact];
88 NewLabBuf[pos] = labBuf[pos];
92 lastcontact = lineLength - 1;
93 lastval = tmpLineBuf[lastcontact];
94 for (
long pos = lineLength - 1; pos >= 0; pos--)
98 RealType thisval = lastval - magnitude * krange * krange;
100 if (tmpLineBuf[pos] >= tmpLineBuf[lastcontact])
103 lastval = tmpLineBuf[pos];
105 lineBuf[pos] = std::max(tmpLineBuf[pos], thisval);
106 if (thisval > tmpLineBuf[pos])
108 NewLabBuf[pos] = labBuf[lastcontact];
124 long koffset = 0, newcontact = 0;
126 const long lineLength = lineBuf.size();
129 for (
long pos = 0; pos < lineLength; pos++)
132 for (
long krange = koffset; krange <= 0; krange++)
135 RealType T = lineBuf[pos + krange] - magnitude * krange * krange;
137 if (doDilate ? (T >= baseVal) : (T <= baseVal))
143 tmpLineBuf[pos] = baseVal;
144 koffset = newcontact - 1;
147 koffset = newcontact = 0;
148 for (
long pos = lineLength - 1; pos >= 0; pos--)
151 for (
long krange = koffset; krange >= 0; krange--)
153 RealType T = tmpLineBuf[pos + krange] - magnitude * krange * krange;
154 if (doDilate ? (T >= baseVal) : (T <= baseVal))
160 lineBuf[pos] = baseVal;
161 koffset = newcontact + 1;
168 LineBufferType & tmpLineBuf,
169 LabBufferType & labelBuf,
170 LabBufferType & tmpLabelBuf,
175 long koffset = 0, newcontact = 0;
177 using LabelType =
typename LabBufferType::ValueType;
179 const long lineLength = lineBuf.size();
181 for (
long pos = 0; pos < lineLength; pos++)
184 LabelType baseLab = labelBuf[pos];
185 for (
long krange = koffset; krange <= 0; krange++)
188 RealType T = lineBuf[pos + krange] - magnitude * krange * krange;
190 if (doDilate ? (T >= baseVal) : (T <= baseVal))
194 baseLab = labelBuf[pos + krange];
197 tmpLineBuf[pos] = baseVal;
198 tmpLabelBuf[pos] = baseLab;
199 koffset = newcontact - 1;
202 koffset = newcontact = 0;
204 for (
long pos = lineLength - 1; pos >= 0; pos--)
208 LabelType baseLab = tmpLabelBuf[pos];
209 for (
long krange = koffset; krange >= 0; krange--)
211 RealType T = tmpLineBuf[pos + krange] - magnitude * krange * krange;
212 if (doDilate ? (T >= baseVal) : (T <= baseVal))
216 baseLab = tmpLabelBuf[pos + krange];
219 lineBuf[pos] = baseVal;
220 labelBuf[pos] = baseLab;
221 koffset = newcontact + 1;
224 for (
long pos = lineLength - 1; pos >= 0; pos--)
226 lineBuf[pos] = tmpLineBuf[pos];
227 labelBuf[pos] = tmpLabelBuf[pos];
236 TOutDistIter & outputIterator,
237 TOutLabIter & outputLabIterator,
239 const unsigned lineLength,
240 const unsigned direction,
241 const int magnitudeSign,
242 const bool useImageSpacing,
259 const RealType magnitude = (magnitudeSign * iscale * iscale) / (2.0);
260 LineBufferType lineBuf(lineLength, 0.0);
261 LabelBufferType labBuf(lineLength, 0.0);
263 inputIterator.SetDirection(direction);
264 outputIterator.SetDirection(direction);
265 outputLabIterator.SetDirection(direction);
267 inputIterator.GoToBegin();
268 outputIterator.GoToBegin();
269 outputLabIterator.GoToBegin();
271 while (!inputIterator.IsAtEnd() && !outputIterator.IsAtEnd())
279 while (!inputIterator.IsAtEndOfLine())
281 labBuf[i] = (inputIterator.Get());
291 using EndType = std::vector<unsigned>;
295 for (
unsigned idx = 0; idx < lineLength; idx++)
301 firsts.push_back(idx);
302 unsigned idxend = idx;
303 for (; idxend < lineLength; idxend++)
305 if (val != labBuf[idxend])
310 lasts.push_back(idxend - 1);
315 for (
unsigned R = 0; R < firsts.size(); R++)
317 unsigned first = firsts[R];
318 unsigned last = lasts[R];
319 unsigned SLL = last - first + 1;
320 LineBufferType ShortLineBuf(SLL);
328 if (last == lineLength - 1)
335 std::copy(ShortLineBuf.begin(), ShortLineBuf.end(), &(lineBuf[first]));
339 while (!outputIterator.IsAtEndOfLine())
341 outputIterator.Set(
static_cast<typename TOutDistIter::PixelType
>(lineBuf[j++]));
350 while (!outputLabIterator.IsAtEndOfLine())
352 typename TInIter::PixelType val = 0;
353 if (lineBuf[j2] == sigma)
357 outputLabIterator.Set(val);
361 outputLabIterator.NextLine();
365 inputIterator.NextLine();
366 outputIterator.NextLine();
374 TOutDistIter & outputIterator,
375 TOutLabIter & outputLabIterator,
377 const unsigned lineLength,
378 const unsigned direction,
379 const int magnitudeSign,
380 const bool useImageSpacing,
396 const RealType magnitude = (magnitudeSign * iscale * iscale) / (2.0);
398 const typename TInIter::PixelType initPixelValue = 0.0;
399 LineBufferType lineBuf(lineLength, initRealValue);
400 LabelBufferType labBuf(lineLength, initPixelValue);
401 LineBufferType tmpLineBuf(lineLength, initRealValue);
402 LabelBufferType newLabBuf(lineLength, initPixelValue);
404 inputIterator.SetDirection(direction);
405 outputIterator.SetDirection(direction);
406 outputLabIterator.SetDirection(direction);
408 inputIterator.GoToBegin();
409 outputIterator.GoToBegin();
410 outputLabIterator.GoToBegin();
412 while (!inputIterator.IsAtEnd() && !outputIterator.IsAtEnd())
420 while (!inputIterator.IsAtEndOfLine())
422 labBuf[i] = (inputIterator.Get());
438 while (!outputIterator.IsAtEndOfLine())
440 outputIterator.Set(
static_cast<typename TOutDistIter::PixelType
>(lineBuf[j]));
441 outputLabIterator.Set(newLabBuf[j]);
448 inputIterator.NextLine();
449 outputIterator.NextLine();
450 outputLabIterator.NextLine();
458 TDistIter & inputDistIterator,
459 TOutDistIter & outputDistIterator,
460 TOutLabIter & outputLabIterator,
462 const unsigned lineLength,
463 const unsigned direction,
464 const int magnitudeSign,
465 const bool useImageSpacing,
480 const RealType magnitude = (magnitudeSign * iscale * iscale) / (2.0 * sigma);
481 LineBufferType lineBuf(lineLength, 0.0);
482 LabelBufferType labBuf(lineLength, 0.0);
484 inputIterator.SetDirection(direction);
485 outputDistIterator.SetDirection(direction);
486 inputDistIterator.SetDirection(direction);
487 outputLabIterator.SetDirection(direction);
489 inputIterator.GoToBegin();
490 outputDistIterator.GoToBegin();
491 inputDistIterator.GoToBegin();
492 outputLabIterator.GoToBegin();
494 while (!inputIterator.IsAtEnd() && !outputDistIterator.IsAtEnd())
502 while (!inputIterator.IsAtEndOfLine())
504 lineBuf[i] =
static_cast<RealType>(inputDistIterator.Get());
505 labBuf[i] = inputIterator.Get();
511 using EndType = std::vector<unsigned>;
514 for (
unsigned idx = 0; idx < lineLength; idx++)
520 firsts.push_back(idx);
521 unsigned idxend = idx;
522 for (; idxend < lineLength; idxend++)
524 if (val != labBuf[idxend])
529 lasts.push_back(idxend - 1);
534 for (
unsigned R = 0; R < firsts.size(); R++)
536 unsigned first = firsts[R];
537 unsigned last = lasts[R];
538 unsigned SLL = last - first + 1;
539 LineBufferType ShortLineBuf(SLL + 2);
540 LineBufferType tmpShortLineBuf(SLL + 2);
549 if (last == lineLength - 1)
551 rightend = BaseSigma;
554 ShortLineBuf[0] = leftend;
555 ShortLineBuf[SLL + 1] = rightend;
557 std::copy(&(lineBuf[first]), &(lineBuf[last + 1]), &(ShortLineBuf[1]));
561 std::copy(&(ShortLineBuf[1]), &(ShortLineBuf[SLL + 1]), &(lineBuf[first]));
566 while (!outputDistIterator.IsAtEndOfLine())
568 outputDistIterator.Set(
static_cast<typename TOutDistIter::PixelType
>(lineBuf[j++]));
569 ++outputDistIterator;
575 while (!outputLabIterator.IsAtEndOfLine())
577 typename TInIter::PixelType val = 0;
578 if (lineBuf[j2] == BaseSigma)
582 outputLabIterator.Set(val);
586 outputLabIterator.NextLine();
589 inputIterator.NextLine();
590 inputDistIterator.NextLine();
591 outputDistIterator.NextLine();
599 TDistIter & inputDistIterator,
600 TOutDistIter & outputDistIterator,
601 TOutLabIter & outputLabIterator,
603 const unsigned lineLength,
604 const unsigned direction,
605 const int magnitudeSign,
606 const bool useImageSpacing,
621 const RealType magnitude = (magnitudeSign * iscale * iscale) / (2.0 * sigma);
624 const typename TInIter::PixelType initPixelValue = 0.0;
625 LineBufferType lineBuf(lineLength, initRealValue);
626 LabelBufferType labBuf(lineLength, initPixelValue);
627 LineBufferType tmpLineBuf(lineLength, initRealValue);
628 LabelBufferType newLabBuf(lineLength, initPixelValue);
629 LabelBufferType tmpLabBuf(lineLength, initPixelValue);
631 inputIterator.SetDirection(direction);
632 inputDistIterator.SetDirection(direction);
633 outputDistIterator.SetDirection(direction);
634 outputLabIterator.SetDirection(direction);
636 inputIterator.GoToBegin();
637 inputDistIterator.GoToBegin();
638 outputDistIterator.GoToBegin();
639 outputLabIterator.GoToBegin();
641 while (!inputDistIterator.IsAtEnd() && !outputLabIterator.IsAtEnd())
649 while (!inputDistIterator.IsAtEndOfLine())
651 lineBuf[i] = inputDistIterator.Get();
652 labBuf[i] = inputIterator.Get();
659 lineBuf, tmpLineBuf, labBuf, tmpLabBuf, magnitude, extreme);
662 while (!outputDistIterator.IsAtEndOfLine())
664 outputDistIterator.Set(
static_cast<typename TOutDistIter::PixelType
>(lineBuf[j]));
665 outputLabIterator.Set(labBuf[j]);
666 ++outputDistIterator;
672 inputIterator.NextLine();
673 outputLabIterator.NextLine();
674 inputDistIterator.NextLine();
675 outputDistIterator.NextLine();