Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
textons.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include "modules/computer_vision/cv.h"
#include "modules/computer_vision/textons.h"
+ Include dependency graph for textons.c:

Go to the source code of this file.

Macros

#define TEXTONS_LOAD_DICTIONARY   1
 
#define TEXTONS_ALPHA   10
 
#define TEXTONS_N_TEXTONS   20
 
#define TEXTONS_N_SAMPLES   100
 
#define TEXTONS_PATCH_SIZE   6
 
#define TEXTONS_N_LEARNING_SAMPLES   10000
 
#define TEXTONS_FULL_SAMPLING   0
 
#define TEXTONS_BORDER_WIDTH   0
 
#define TEXTONS_BORDER_HEIGHT   0
 
#define TEXTONS_DICTIONARY_NUMBER   0
 
#define DICTIONARY_PATH   /data/video/
 

Functions

struct image_ttexton_func (struct image_t *img)
 Main texton processing function that first either loads or learns a dictionary and then extracts the texton histogram. More...
 
void DictionaryTrainingYUV (uint8_t *frame, uint16_t width, uint16_t height)
 Function that performs one pass for dictionary training. More...
 
void DistributionExtraction (uint8_t *frame, uint16_t width, uint16_t height)
 Function that extracts a texton histogram from an image. More...
 
void save_texton_dictionary (void)
 Save the texton dictionary. More...
 
void load_texton_dictionary (void)
 Load a texton dictionary. More...
 
void textons_init (void)
 Initialize. More...
 
void textons_stop (void)
 

Variables

float **** dictionary
 
uint32_t learned_samples = 0
 
uint8_t dictionary_initialized = 0
 
float * texton_distribution
 
uint8_t load_dictionary = TEXTONS_LOAD_DICTIONARY
 
uint8_t alpha_uint = TEXTONS_ALPHA
 
uint8_t n_textons = TEXTONS_N_TEXTONS
 
uint8_t patch_size = TEXTONS_PATCH_SIZE
 
uint32_t n_learning_samples = TEXTONS_N_LEARNING_SAMPLES
 
uint32_t n_samples_image = TEXTONS_N_SAMPLES
 
uint8_t FULL_SAMPLING = TEXTONS_FULL_SAMPLING
 
uint32_t border_width = TEXTONS_BORDER_WIDTH
 
uint32_t border_height = TEXTONS_BORDER_HEIGHT
 
uint8_t dictionary_number = TEXTONS_DICTIONARY_NUMBER
 
uint8_t dictionary_ready = 0
 
float alpha = 0.0
 
static FILE * dictionary_logger = NULL
 

Detailed Description

Takes an image and represents the texture and colors in the image with a texton histogram. A texton is a cluster centroid in a space populated by image patches. First, this code learns or loads a texton dictionary. Then, for each incoming image, patches are sampled from the image, compared to textons in the dictionary, and the closest texton is identified, augmenting the corresponding bin in the texton histogram.

Definition in file textons.c.

Macro Definition Documentation

◆ DICTIONARY_PATH

#define DICTIONARY_PATH   /data/video/

Definition at line 112 of file textons.c.

◆ TEXTONS_ALPHA

#define TEXTONS_ALPHA   10

Definition at line 49 of file textons.c.

◆ TEXTONS_BORDER_HEIGHT

#define TEXTONS_BORDER_HEIGHT   0

Definition at line 84 of file textons.c.

◆ TEXTONS_BORDER_WIDTH

#define TEXTONS_BORDER_WIDTH   0

Definition at line 79 of file textons.c.

◆ TEXTONS_DICTIONARY_NUMBER

#define TEXTONS_DICTIONARY_NUMBER   0

Definition at line 89 of file textons.c.

◆ TEXTONS_FULL_SAMPLING

#define TEXTONS_FULL_SAMPLING   0

Definition at line 74 of file textons.c.

◆ TEXTONS_LOAD_DICTIONARY

#define TEXTONS_LOAD_DICTIONARY   1

Definition at line 44 of file textons.c.

◆ TEXTONS_N_LEARNING_SAMPLES

#define TEXTONS_N_LEARNING_SAMPLES   10000

Definition at line 69 of file textons.c.

◆ TEXTONS_N_SAMPLES

#define TEXTONS_N_SAMPLES   100

Definition at line 59 of file textons.c.

◆ TEXTONS_N_TEXTONS

#define TEXTONS_N_TEXTONS   20

Definition at line 54 of file textons.c.

◆ TEXTONS_PATCH_SIZE

#define TEXTONS_PATCH_SIZE   6

Definition at line 64 of file textons.c.

Function Documentation

◆ DictionaryTrainingYUV()

void DictionaryTrainingYUV ( uint8_t frame,
uint16_t  width,
uint16_t  height 
)

Function that performs one pass for dictionary training.

It extracts samples from an image, finds the closest texton and moves it towards the sample.

Parameters
[in]frame*The YUV image data
[in]widthThe width of the image
[in]heightThe height of the image

Definition at line 166 of file textons.c.

References alpha, alpha_uint, image_t::buf, c(), dictionary, dictionary_initialized, frame, learned_samples, n_samples_image, n_textons, patch_size, s, and image_t::w.

Referenced by texton_func().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DistributionExtraction()

void DistributionExtraction ( uint8_t frame,
uint16_t  width,
uint16_t  height 
)

Function that extracts a texton histogram from an image.

Parameters
[in]frame*The YUV image data
[in]widthThe width of the image
[in]heightThe height of the image

Definition at line 311 of file textons.c.

References border_height, border_width, image_t::buf, c(), dictionary, frame, FULL_SAMPLING, n_samples_image, n_textons, patch_size, and texton_distribution.

Referenced by texton_func().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_texton_dictionary()

void load_texton_dictionary ( void  )

Load a texton dictionary.

Definition at line 471 of file textons.c.

References dictionary, dictionary_initialized, dictionary_logger, dictionary_number, DICTIONARY_PATH, dictionary_ready, EOF, learned_samples, load_dictionary, n_textons, and patch_size.

Referenced by texton_func().

+ Here is the caller graph for this function:

◆ save_texton_dictionary()

void save_texton_dictionary ( void  )

Save the texton dictionary.

Definition at line 441 of file textons.c.

References dictionary, dictionary_logger, dictionary_number, DICTIONARY_PATH, n_textons, and patch_size.

Referenced by texton_func().

+ Here is the caller graph for this function:

◆ texton_func()

struct image_t * texton_func ( struct image_t img)

Main texton processing function that first either loads or learns a dictionary and then extracts the texton histogram.

Parameters
[out]*imgThe output image
[in]*imgThe input image (YUV422)

Definition at line 121 of file textons.c.

References alpha, image_t::buf, image_t::buf_size, dictionary_ready, DictionaryTrainingYUV(), DistributionExtraction(), frame, image_t::h, if(), learned_samples, load_dictionary, load_texton_dictionary(), n_learning_samples, patch_size, save_texton_dictionary(), and image_t::w.

Referenced by textons_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ textons_init()

void textons_init ( void  )

Initialize.

Definition at line 501 of file textons.c.

References dictionary, dictionary_initialized, dictionary_ready, learned_samples, n_textons, patch_size, texton_distribution, texton_func(), and image_t::w.

+ Here is the call graph for this function:

◆ textons_stop()

void textons_stop ( void  )

Definition at line 522 of file textons.c.

References dictionary, and texton_distribution.

Variable Documentation

◆ alpha

◆ alpha_uint

uint8_t alpha_uint = TEXTONS_ALPHA

Definition at line 95 of file textons.c.

Referenced by DictionaryTrainingYUV().

◆ border_height

Definition at line 102 of file textons.c.

Referenced by DistributionExtraction().

◆ border_width

Definition at line 101 of file textons.c.

Referenced by DistributionExtraction().

◆ dictionary

◆ dictionary_initialized

uint8_t dictionary_initialized = 0

Definition at line 39 of file textons.c.

Referenced by DictionaryTrainingYUV(), load_texton_dictionary(), and textons_init().

◆ dictionary_logger

FILE* dictionary_logger = NULL
static

Definition at line 110 of file textons.c.

Referenced by load_texton_dictionary(), and save_texton_dictionary().

◆ dictionary_number

uint8_t dictionary_number = TEXTONS_DICTIONARY_NUMBER

Definition at line 103 of file textons.c.

Referenced by load_texton_dictionary(), and save_texton_dictionary().

◆ dictionary_ready

uint8_t dictionary_ready = 0

Definition at line 106 of file textons.c.

Referenced by load_texton_dictionary(), texton_func(), and textons_init().

◆ FULL_SAMPLING

uint8_t FULL_SAMPLING = TEXTONS_FULL_SAMPLING

Definition at line 100 of file textons.c.

Referenced by DistributionExtraction().

◆ learned_samples

uint32_t learned_samples = 0

Definition at line 38 of file textons.c.

Referenced by DictionaryTrainingYUV(), load_texton_dictionary(), texton_func(), and textons_init().

◆ load_dictionary

uint8_t load_dictionary = TEXTONS_LOAD_DICTIONARY

Definition at line 94 of file textons.c.

Referenced by load_texton_dictionary(), and texton_func().

◆ n_learning_samples

uint32_t n_learning_samples = TEXTONS_N_LEARNING_SAMPLES

Definition at line 98 of file textons.c.

Referenced by texton_func().

◆ n_samples_image

uint32_t n_samples_image = TEXTONS_N_SAMPLES

Definition at line 99 of file textons.c.

Referenced by DictionaryTrainingYUV(), and DistributionExtraction().

◆ n_textons

◆ patch_size

◆ texton_distribution

float* texton_distribution

Definition at line 40 of file textons.c.

Referenced by DistributionExtraction(), textons_init(), and textons_stop().