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; }
133 if (dictionary_ready == 0) {
143 dictionary_ready = 1;
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];
280 dictionary[assignment][i][j][c] += (alpha * error_texton);
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++;
399 if (y > height - patch_size) {
407 if (x > width - patch_size) {
429 free(texton_distances);
452 perror(
"Error while opening the file.\n");
488 dictionary_ready = 1;
491 printf(
"Texton dictionary %d does not exist, we start learning one.\n",
dictionary_number);
503 printf(
"Textons init\n");
507 dictionary_ready = 0;
512 dictionary[
w][i] = (
float **) calloc(patch_size,
sizeof(
float *));
514 dictionary[
w][i][j] = (
float *) calloc(2,
sizeof(
float));
#define TEXTONS_PATCH_SIZE
uint32_t buf_size
The buffer size.
#define TEXTONS_FULL_SAMPLING
uint8_t dictionary_number
Takes an image and represents the texture and colors in the image with a texton histogram.
void DistributionExtraction(uint8_t *frame, uint16_t width, uint16_t height)
Function that extracts a texton histogram from an image.
#define TEXTONS_DICTIONARY_NUMBER
void save_texton_dictionary(void)
Save the texton dictionary.
void textons_init(void)
Initialize.
#define TEXTONS_LOAD_DICTIONARY
uint32_t n_learning_samples
void load_texton_dictionary(void)
Load a texton dictionary.
Computer vision framework for onboard processing.
void * buf
Image buffer (depending on the image_type)
#define TEXTONS_N_TEXTONS
#define TEXTONS_N_LEARNING_SAMPLES
static FILE * dictionary_logger
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 ...
uint8_t dictionary_initialized
#define TEXTONS_N_SAMPLES
#define TEXTONS_BORDER_WIDTH
float * texton_distribution
void DictionaryTrainingYUV(uint8_t *frame, uint16_t width, uint16_t height)
Function that performs one pass for dictionary training.
#define TEXTONS_BORDER_HEIGHT