30 #ifndef _D_HOUGH_TRANSFORM_HPP
31 #define _D_HOUGH_TRANSFORM_HPP
33 #include "Core/include/private/DImage.hxx"
34 #include "Base/include/DBase.h"
55 template <
class T1,
class T2>
62 double rhoMax =
std::sqrt(wIn * wIn + hIn * hIn);
64 size_t wOut = thetaRes * 180;
65 size_t hOut = rhoRes * rhoMax;
68 imOut.setSize(wOut, hOut);
75 double thetaStep = PI / wOut;
76 double rhoStep = rhoMax / hOut;
78 for (off_t j = 0; j < (off_t) hIn; j++) {
81 double coef = 1. / rhoStep;
82 for (off_t i = 0; i < (off_t) wIn; i++) {
87 for (off_t t = 0; t < (off_t) wOut; t++) {
88 double theta = t * thetaStep;
89 double rho = coef * (i * cos(theta) + j * sin(theta));
91 if (rho >= 0 && rho < hOut) {
92 off_t irho = int(fabs(rho));
93 linesOut[irho][t] += 1;
111 template <
class T1,
class T2>
118 double rhoMax =
std::sqrt(wIn * wIn + hIn * hIn);
120 size_t wOut = xyResol * wIn;
121 size_t hOut = xyResol * hIn;
122 off_t dOut = rhoResol * rhoMax;
125 imOut.setSize(wOut, hOut, dOut);
133 double coef = 1 / (xyResol * rhoResol);
135 for (off_t j = 0; j < (off_t) hIn; j++) {
137 for (off_t i = 0; i < (off_t) wIn; i++) {
138 if (lIn[i] != T1(0)) {
142 for (off_t j2 = 0; j2 < (off_t) hOut; j2++) {
143 for (off_t i2 = 0; i2 < (off_t) wOut; i2++) {
144 if (i != i2 && j != j2) {
145 rho = coef *
std::sqrt((i * xyResol - i2) * (i * xyResol - i2) +
146 (j * xyResol - j2) * (j * xyResol - j2));
147 if (rho >= 0 && rho < dOut)
148 slicesOut[rho][j2][i2] += 1;
162 template <
class T1,
class T2>
172 size_t wOut = resol * wIn;
173 size_t hOut = resol * hIn;
178 imRadiiOut.
setSize(wOut, hOut);
180 fill(imCentersOut, 0.);
181 fill(imRadiiOut, T2(0));
185 typename Image<double>::sliceType linesOut1 = imCentersOut.
getSlices()[0];
189 size_t nonZeroPts = 0;
191 for (off_t j = 0; j < (off_t) imIn.
getHeight(); j++) {
193 for (off_t i = 0; i < (off_t) imIn.
getWidth(); i++) {
194 if (lIn[i] != T1(0)) {
196 for (off_t j2 = 0; j2 < (off_t) hOut; j2++) {
197 for (off_t i2 = 0; i2 < (off_t) wOut; i2++) {
198 if (i != i2 && j != j2) {
199 rho =
std::sqrt(
double((i * resol - i2) * (i * resol - i2) +
200 (j * resol - j2) * (j * resol - j2)));
202 if (rho > 100 && rho < 500) {
203 linesOut1[j2][i2] += 1;
204 if (linesOut1[j2][i2] > nonZeroPts &&
205 linesOut2[j2][i2] < T2(rho))
206 linesOut2[j2][i2] = T2(rho);
size_t getWidth() const
Get image width.
Definition: DBaseImage.h:80
size_t getHeight() const
Get image height.
Definition: DBaseImage.h:85
Definition: DBaseImage.h:386
volType getSlices() const
Get an array containing the start offset of each slice.
Definition: DImage.hpp:117
sliceType getLines() const
Get an array containing the start offset of each line.
Definition: DImage.hpp:111
virtual RES_T setSize(size_t w, size_t h, size_t d=1, bool doAllocate=true)
Set the size of image.
RES_T sqrt(const Image< T1 > &imIn, Image< T2 > &imOut)
sqrt() - square root of an image
Definition: DImageArith.hpp:926
RES_T fill(Image< T > &imOut, const T &value)
fill() - Fill an image with a given value.
Definition: DImageArith.hpp:1456
RES_T stretchHist(const Image< T1 > &imIn, T1 inMinVal, T1 inMaxVal, Image< T2 > &imOut, T2 outMinVal=numeric_limits< T2 >::min(), T2 outMaxVal=numeric_limits< T2 >::max())
stretchHist() - Stretch histogram
Definition: DImageHistogram.hpp:373