|
|
//
|
|
|
// Created by Arnaud Blanchard on 22/12/15.
|
|
|
// Copyright ETIS 2015. All rights reserved.
|
|
|
//
|
|
|
#include "blc_channel.h"
|
|
|
#include "blc_program.h"
|
|
|
#include <unistd.h>
|
|
|
#include <math.h>
|
|
|
|
|
|
#define DEFAULT_OUTPUT_NAME ":d2gaussian<pid>"
|
|
|
|
|
|
int main(int argc, char **argv){
|
|
|
blc_channel output;
|
|
|
char const *output_name, *size_str, *type_str, *sigma_str, *gain_str;
|
|
|
float sigma, coeff, x, y, gain;
|
|
|
|
|
|
|
|
|
int i, j, id, jd;
|
|
|
uint32_t type;
|
|
|
|
|
|
blc_program_set_description("Create second derivative gaussian");
|
|
|
blc_program_add_option(&gain_str, 'g', "gain", "real", "gain to apply to the filter", "1");
|
|
|
blc_program_add_option(&output_name, 'o', "output", "blc_channel-out", "channel name", DEFAULT_OUTPUT_NAME);
|
|
|
blc_program_add_option(&size_str, 's', "size", "(integer)[x(integer)]", "size of the output 1 or 2D", "3x3");
|
|
|
blc_program_add_option(&type_str, 't', "type", "FL32", "type of values", "FL32");
|
|
|
blc_program_add_option(&sigma_str, 'S', "sigma", "float", "sigma of the initial gaussian", "1");
|
|
|
|
|
|
|
|
|
blc_program_init(&argc, &argv, blc_quit);
|
|
|
|
|
|
if (strcmp(output_name, DEFAULT_OUTPUT_NAME)==0) SYSTEM_ERROR_CHECK(asprintf((char**)&output_name, ":d2gaussian%d", getpid()),-1, NULL);
|
|
|
|
|
|
type=STRING_TO_UINT32(type_str);
|
|
|
|
|
|
SSCANF(1, gain_str, "%f", &gain);
|
|
|
SYSTEM_SUCCESS_CHECK(sscanf(sigma_str, "%f", &sigma), 1, "Error parsing '%s'", sigma_str);
|
|
|
|
|
|
output.create_or_open(output_name, BLC_CHANNEL_WRITE, type, 'NDEF', size_str);
|
|
|
output.publish();
|
|
|
|
|
|
|
|
|
// 1/(pi*sigma²)(1-1/2(x²+y²)/sigma²)*exp(-1/2*(x²+y²)/sigma²)
|
|
|
|
|
|
FOR(j, output.dims[1].length){
|
|
|
FOR(i, output.dims[0].length){
|
|
|
x=i-(float)output.dims[0].length/2.0+0.5;
|
|
|
y=j-(float)output.dims[1].length/2.0+0.5;
|
|
|
coeff=(x*x+y*y)/(float)(2*sigma*sigma); //(x²+y²)/(2*sigma²)
|
|
|
output.floats[i+j*output.dims[0].length]=gain/(M_PI*sigma*sigma)*(1-coeff)*exp(-coeff);
|
|
|
}
|
|
|
}
|
|
|
if (output.sem_ack_data) sem_wait(output.sem_ack_data);
|
|
|
if (output.sem_new_data) sem_post(output.sem_new_data);
|
|
|
|
|
|
BLC_COMMAND_LOOP(-1){};
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
} |