| 223 | } |
| 224 | |
| 225 | cv::Mat susan(const cv::Mat& image, int radius, int tolerance) |
| 226 | { |
| 227 | assert(image.type() == CV_8UC1); // only handles gray image |
| 228 | const int cols = image.cols, rows = image.rows; |
| 229 | Mat result(rows, cols, CV_8UC1); |
| 230 | |
| 231 | const int rr = radius * radius; |
| 232 | for(int r = 0; r < rows; ++r) |
| 233 | for(int c = 0; c < cols; ++c) |
| 234 | { |
| 235 | int sum = 0, hit = 0; |
| 236 | uint8_t center = image.at<uint8_t>(r, c); |
| 237 | for(int dy = -radius; dy < radius; ++dy) |
| 238 | { |
| 239 | int y = r + dy; |
| 240 | for(int dx = -radius; dx < radius; ++dx) |
| 241 | { |
| 242 | int x = c + dx; |
| 243 | if(0 <= x && x < cols && 0 <= y && y < rows) |
| 244 | if(dx*dx + dy*dy <= rr) // comment this line if you want to detect squared region. |
| 245 | { |
| 246 | ++sum; |
| 247 | if(std::abs(image.at<uint8_t>(y, x) - center) <= tolerance) |
| 248 | ++hit; |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | float g = static_cast<float>(sum - hit)/sum; |
| 254 | // if(g < 0.4f || g > 0.5f) |
| 255 | // g = 0.0f; |
| 256 | result.at<uint8_t>(r, c) = cvRound(g*255); |
| 257 | } |
| 258 | return result; |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | here are some useful links about hypot, I tried to use std::hypot(x, y), later changed to std::sqrt(a*a + b*b); |
nothing calls this directly
no outgoing calls
no test coverage detected