43 #ifndef TEXTONS_LOAD_DICTIONARY
44 #define TEXTONS_LOAD_DICTIONARY 1
49 #define TEXTONS_ALPHA 10
53 #ifndef TEXTONS_N_TEXTONS
54 #define TEXTONS_N_TEXTONS 20
58 #ifndef TEXTONS_N_SAMPLES
59 #define TEXTONS_N_SAMPLES 100
63 #ifndef TEXTONS_PATCH_SIZE
64 #define TEXTONS_PATCH_SIZE 6
68 #ifndef TEXTONS_N_LEARNING_SAMPLES
69 #define TEXTONS_N_LEARNING_SAMPLES 10000
73 #ifndef TEXTONS_FULL_SAMPLING
74 #define TEXTONS_FULL_SAMPLING 0
78 #ifndef TEXTONS_BORDER_WIDTH
79 #define TEXTONS_BORDER_WIDTH 0
83 #ifndef TEXTONS_BORDER_HEIGHT
84 #define TEXTONS_BORDER_HEIGHT 0
88 #ifndef TEXTONS_DICTIONARY_NUMBER
89 #define TEXTONS_DICTIONARY_NUMBER 0
111 #ifndef DICTIONARY_PATH
112 #define DICTIONARY_PATH /data/video/
124 if (img->
buf_size == 0) {
return img; }
168 int i, j,
w,
s, texton, c;
183 printf(
"Intializing dictionary!\n");
194 buf =
frame + (width * 2 * (i + y)) + 2 * x;
197 printf(
"Setting dictionary:\n");
217 float *texton_distances, * **patch;
218 texton_distances = (
float *)calloc(
n_textons,
sizeof(
float));
219 patch = (
float ** *)calloc(
patch_size,
sizeof(
float **));
222 patch[i] = (
float **)calloc(
patch_size,
sizeof(
float *));
224 patch[i][j] = (
float *)calloc(2,
sizeof(
float));
235 for (texton = 0; texton <
n_textons; texton++) {
236 texton_distances[texton] = 0;
241 buf =
frame + (width * 2 * (i + y)) + 2 * x;
244 patch[i][j][0] = (float) *
buf;
247 patch[i][j][1] = (float) *
buf;
255 for (c = 0; c < 2; c++) {
257 for (texton = 0; texton <
n_textons; texton++) {
258 texton_distances[texton] += (patch[i][j][c] -
dictionary[texton][i][j][c])
259 * (patch[i][j][c] -
dictionary[texton][i][j][c]);
267 float min_dist = texton_distances[0];
268 for (texton = 1; texton <
n_textons; texton++) {
269 if (texton_distances[texton] < min_dist) {
270 min_dist = texton_distances[texton];
278 for (c = 0; c < 2; c++) {
279 error_texton = patch[i][j][c] -
dictionary[assignment][i][j][c];
297 free(texton_distances);
315 int n_extracted_textons = 0;
323 printf(
"Execute!\n");
326 float *texton_distances, * **patch;
327 texton_distances = (
float *)calloc(
n_textons,
sizeof(
float));
328 patch = (
float ** *)calloc(
patch_size,
sizeof(
float **));
330 patch[i] = (
float **)calloc(
patch_size,
sizeof(
float *));
332 patch[i][j] = (
float *)calloc(2,
sizeof(
float));
346 for (texton = 0; texton <
n_textons; texton++) {
347 texton_distances[texton] = 0;
352 buf =
frame + (width * 2 * (i + y)) + 2 * x;
355 patch[i][j][0] = (float) *
buf;
358 patch[i][j][1] = (float) *
buf;
366 for (c = 0; c < 2; c++) {
368 for (texton = 0; texton <
n_textons; texton++) {
369 texton_distances[texton] += (patch[i][j][c] -
dictionary[texton][i][j][c])
370 * (patch[i][j][c] -
dictionary[texton][i][j][c]);
379 float min_dist = texton_distances[0];
380 for (texton = 1; texton <
n_textons; texton++) {
381 if (texton_distances[texton] < min_dist) {
382 min_dist = texton_distances[texton];
389 n_extracted_textons++;
429 free(texton_distances);
452 perror(
"Error while opening the file.\n");
491 printf(
"Texton dictionary %d does not exist, we start learning one.\n",
dictionary_number);
503 printf(
"Textons init\n");
514 dictionary[
w][i][j] = (
float *) calloc(2,
sizeof(
float));
Computer vision framework for onboard processing.
if(GpsFixValid() &&e_identification_started)
uint32_t buf_size
The buffer size.
void * buf
Image buffer (depending on the image_type)
void save_texton_dictionary(void)
Save the texton dictionary.
void load_texton_dictionary(void)
Load a texton dictionary.
float * texton_distribution
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 ...
#define TEXTONS_PATCH_SIZE
uint32_t n_learning_samples
#define TEXTONS_DICTIONARY_NUMBER
#define TEXTONS_N_TEXTONS
void DictionaryTrainingYUV(uint8_t *frame, uint16_t width, uint16_t height)
Function that performs one pass for dictionary training.
static FILE * dictionary_logger
uint8_t dictionary_initialized
#define TEXTONS_LOAD_DICTIONARY
#define TEXTONS_BORDER_HEIGHT
void textons_init(void)
Initialize.
void DistributionExtraction(uint8_t *frame, uint16_t width, uint16_t height)
Function that extracts a texton histogram from an image.
#define TEXTONS_N_LEARNING_SAMPLES
#define TEXTONS_BORDER_WIDTH
uint8_t dictionary_number
#define TEXTONS_N_SAMPLES
#define TEXTONS_FULL_SAMPLING
Takes an image and represents the texture and colors in the image with a texton histogram.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.