Loading...
Searching...
No Matches
lwir_detection.c
Go to the documentation of this file.
172bool lwir_detect_hotspots(const uint8_t *temperature, size_t bytes, unsigned width, unsigned height,
178 /* Frame median over valid codes only: robust against hotspots occupying a minority of pixels. */
220 if (bit_is_set(workspace, seed) || seed_raw == UINT16_MAX || seed_raw < threshold_raw) continue;
248 if (!bit_is_set(workspace, neighbor) && neighbor_raw != UINT16_MAX && neighbor_raw >= threshold_raw) {
262 const size_t box_min_x = candidate.min_x > lwir_hotspot_radius ? candidate.min_x - lwir_hotspot_radius : 0;
263 const size_t box_min_y = candidate.min_y > lwir_hotspot_radius ? candidate.min_y - lwir_hotspot_radius : 0;
264 const size_t box_max_x = candidate.max_x + lwir_hotspot_radius < width ? candidate.max_x + lwir_hotspot_radius : width - 1;
265 const size_t box_max_y = candidate.max_y + lwir_hotspot_radius < height ? candidate.max_y + lwir_hotspot_radius : height - 1;
268 for (size_t y = box_min_y; y <= box_max_y; ++y) for (size_t x = box_min_x; x <= box_max_x; ++x) {
270 if (valid_code(raw) && raw < threshold_raw) { ++workspace->histogram[raw]; ++background_count; }
272 const double local_background_raw = background_count ? histogram_median(workspace, background_count) : background_raw;
279 const double weight = fmax(0, (double)read_u16_le(temperature + pixel * 2) - local_background_raw);
297 candidate.touches_edge = candidate.min_x == 0 || candidate.min_y == 0 || candidate.max_x + 1 == width || candidate.max_y + 1 == height;
306 candidate.tray_like = !candidate.touches_edge && candidate.pixels >= 4 && span_x >= 2 && span_y >= 2
static void mark_bit(struct lwir_detection_workspace *workspace, size_t pixel)
Set a pixel's visited bit.
Definition lwir_detection.c:81
static bool bit_is_set(const struct lwir_detection_workspace *workspace, size_t pixel)
Test a pixel's visited bit.
Definition lwir_detection.c:70
static bool candidate_better(const struct lwir_hotspot *candidate, const struct lwir_hotspot *current, bool tray_order)
Ranking predicate for retained candidates.
Definition lwir_detection.c:130
static uint16_t read_u16_le(const uint8_t *bytes)
Decode one unsigned 16-bit little-endian value.
Definition lwir_detection.c:46
static double histogram_median(const struct lwir_detection_workspace *workspace, uint64_t count)
Exact median of the values counted in the histogram.
Definition lwir_detection.c:104
bool lwir_detect_hotspots(const uint8_t *temperature, size_t bytes, unsigned width, unsigned height, struct lwir_detection_workspace *workspace, struct lwir_hotspot_set *result)
Detect and rank hot connected components in a native temperature plane.
Definition lwir_detection.c:172
static void histogram_clear(struct lwir_detection_workspace *workspace)
Zero all 65536 histogram bins.
Definition lwir_detection.c:90
static void retain_candidate(struct lwir_hotspot candidates[2], size_t *count, const struct lwir_hotspot *candidate, bool tray_order)
Insert a candidate into a sorted top-two list.
Definition lwir_detection.c:150
static bool valid_code(uint16_t raw)
Whether a raw code is a real measurement rather than a sensor endpoint code.
Definition lwir_detection.c:59
Optional thermal candidate detection, independent of pose and image files.
static uint16_t temperature(const uint8_t *frame, size_t pixels, size_t pixel)
Read one little-endian thermal code.
Definition lwir_render.c:63
Caller-owned scratch storage; never reserved by an imagery-only build.
Definition lwir_detection.h:127
Bounded ranking, retaining the existing two-candidate mission policy.
Definition lwir_detection.h:93
A thermal component expressed only in native sensor coordinates.
Definition lwir_detection.h:39
size_t min_x
Inclusive native bounding box; likewise min_y, max_x and max_y.
Definition lwir_detection.h:41
size_t peak_x
Column of the first pixel (breadth-first order) holding the peak code; peak_y is its row.
Definition lwir_detection.h:42
double excess_celsius_pixels
Sum of per-pixel excess over local background, an integrated heat score.
Definition lwir_detection.h:45
double local_background_celsius
Median of sub-threshold pixels within a 5-pixel margin around the box.
Definition lwir_detection.h:45
double center_x
Subpixel centroid column weighted by excess over local background; center_y likewise.
Definition lwir_detection.h:43
double aspect_ratio
Longer bounding-box side divided by the shorter side (at least 1).
Definition lwir_detection.h:47
double contrast_celsius
Peak minus local background; components below 15 C are discarded.
Definition lwir_detection.h:45
bool touches_edge
Bounding box reaches a frame border, so the object may be truncated.
Definition lwir_detection.h:46
bool tray_like
Passed the compact, hot, high-contrast fire-tray heuristic.
Definition lwir_detection.h:46