/* Background/vehicle segmentation. */ /* Last edited on 2016-04-09 20:11:27 by stolfilocal */ #ifndef dsm_segment2_H #define dsm_segment2_H #include /* Version of Abril/2016 */ typedef struct dsm_segment2_state_t { /* Dimensions of input frames (or region of interest): */ int nx; /* Columns. */ int ny; /* Rows. */ /* All images below have {ny} rows and {nx} columns. */ /* Current state of the segmenter: */ dsm_image_t bg; /* Current background estimate. */ double mu; /* Camera gain. */ dsm_image_t sh; /* Last shadow factor, encoded {[0_2] --> {0..255}}. */ dsm_image_t wt; /* Last background probability mask. */ /* Previous masks: */ dsm_image_t wt_prev; /* Background indicator image of previous frame. */ dsm_image_t up_prev; /* Background update mask of previous frame. */ dsm_image_t sh_prev; /* Previous shadow mask. */ /* Classifier paramters: */ double lambda; /* Standard deviation of noise in background pixels. */ int rhigh; /* Blur radius for high-pass filtering. */ int rshblur; /* Blur radius for shadow mask. */ int rwterode1; /* Structuring element radius to close holes in vehicles. */ int rwtdilate; /* Structuring element radius to clean small noise spots. */ int rwterode2; /* Structuring element radius to expand vehicle spot. */ /* Work images: */ dsm_image_t im_high; /* High-pass filtered version of frame image. */ dsm_image_t bg_adj; /* Bachground image adjusted for camera gain and shadow factor. */ dsm_image_t bg_high; /* High-pass filtered version of background image. */ dsm_image_t up; /* Bachground update mask. */ dsm_image_t sh_sharp;/* Shadow mask before blurring. */ dsm_image_t disc; /* Image-background discrepancy image. */ dsm_image_t temp; /* Generic work image. */ /* Other work areas: */ int32_t *i32temp; /* Vector of {nx*ny} integers. */ } dsm_segment2_state_t; /* Current state of the segmentation module. */ /* Initializes the state {st} for images with {nx} columns and {ny} rows. Copies {bg0} into the background reference image. */ void dsm_segment2_state_initialize(dsm_segment2_state_t *st, int nx, int ny, dsm_image_t *bg0); /*Tries to segment the (possibly reduced) image {img} into foreground and background within the region of interest defined by {st}. The image {img} must have {st.nx} columns and {st.ny} rows. Returns in {st->wt} the fuzzy classification of each pixel, as background (255) or foreground (0), and in {st->sh} the shadow factor (scaled 0.0 --> 0, 2.0 --> 255). The parameter {lambda} should be the in {img}. */ void dsm_segment2_identify_background ( dsm_image_t *img, dsm_segment2_state_t *st, const char *out_prefix /* Filename prefix for debugging images, or {NULL}. */ ); #endif