| 26 | // degrees, with 0 being due east, and anticlockwise increasing. |
| 27 | |
| 28 | static void InitGradMagAndOrientMats( |
| 29 | MAT& magmat, // out: grad mag mat |
| 30 | MAT& orientmat, // out: grad ori mat |
| 31 | const Image& img) // in: ROI scaled to current pyramid level |
| 32 | { |
| 33 | const int nrows = img.rows, nrows1 = img.rows-1; |
| 34 | const int ncols = img.cols, ncols1 = img.cols-1; |
| 35 | const double bins_per_degree = BINS_PER_HIST / 360.; |
| 36 | |
| 37 | magmat.create(nrows, ncols); |
| 38 | orientmat.create(nrows, ncols); |
| 39 | |
| 40 | for (int y = 0; y < nrows1; y++) |
| 41 | { |
| 42 | const byte* const buf = (byte*)(img.data) + y * ncols; |
| 43 | const byte* const buf_x1 = (byte*)(img.data) + y * ncols + 1; |
| 44 | const byte* const buf_y1 = (byte*)(img.data) + (y+1) * ncols; |
| 45 | |
| 46 | double* const magbuf = Buf(magmat) + y * ncols; |
| 47 | double* const orientbuf = Buf(orientmat) + y * ncols; |
| 48 | |
| 49 | for (int x = 0; x < ncols1; x++) |
| 50 | { |
| 51 | const byte pixel = buf[x]; |
| 52 | const double xdelta = buf_x1[x] - pixel; |
| 53 | const double ydelta = buf_y1[x] - pixel; |
| 54 | |
| 55 | magbuf[x] = sqrt(SQ(xdelta) + SQ(ydelta)); |
| 56 | |
| 57 | double orient = |
| 58 | RadsToDegrees(atan2(ydelta, xdelta)); // -180 <= orient < 180 |
| 59 | if (orient < 0) |
| 60 | orient += 360; // 0 <= orient < 360 |
| 61 | orientbuf[x] = orient * bins_per_degree; // 0 <= orient < BINS_PER_HIST |
| 62 | } |
| 63 | } |
| 64 | // fill bottom and right edges |
| 65 | magmat.row(nrows1) = 0; |
| 66 | magmat.col(ncols1) = 0; |
| 67 | orientmat.row(nrows1) = 0; |
| 68 | orientmat.col(ncols1) = 0; |
| 69 | } |
| 70 | |
| 71 | // Init the indices which map a patch row,col to the corresponding |
| 72 | // histogram grid row,col. The mapping depends only on the image |
no test coverage detected