Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "math_lib.h"
#include <math.h>
/**
* @brief The function f(x) to define
*
* @param x The x param for the function
* @return double return the result of f(x)
*/
double my_function_x(double x)
{
return -((2 * x - 1) / (exp(pow(x, 2) - x + 2)));
}
/**
* @brief Intergration of my_function_x
*
* @param a the a
* @param b the b
* @param N the N
* @param f the function to use
*
* @return double the result of integrations
*/
double interg(double a, double b, double N, double (*f)(double))
{
double delta_x = ((b - a) / N);
double res = 0.0;
for (int32_t i = 0; i < N; i += 1)
{
res += (*f)(a + (i * delta_x)) * delta_x;
}
return res;
}
/**
* @brief Compute E(n) with function f(x)
*
* @param N The N number
* @return double return the result of E(N)
*/
double E_n(double N)
{
return fabs((VALUE_I - interg(VALUE_A, VALUE_B, N, my_function_x)) / VALUE_I);
}
/**
* @brief Compute the singal s(x)
*
* @param x The param x for the signal
* @return double return the result of s(x)
*/
double s_x(double x, double w_1, double w_2)
{
return sin(2 * M_PI * w_1 * x) + sin(2 * M_PI * w_2 * x);
}
/**
* @brief
*
* @param x
* @param psi
* @return double
*/
double h_x(double x, double psi)
{
return (1 / sqrt(2 * M_PI * psi)) * exp(-pow(x, 2) / (2 * psi));
}
/**
* @brief Normalise the matrix for get more contrast for zone
*
* @param orig The original matrix will be affected
* @param min The minimum in the matrix
* @param max The maximum in the matrix
* @param lumMax The composant max in the matrix in header
*/
void normalise_matrix(matrix *orig, int32_t min, int32_t max, int32_t lumMax)
{
for (uint32_t i = 1; i < orig->col-1; i += 1)
for (uint32_t j = 1; j < orig->row-1; j += 1)

poulpe
committed
orig->data[i][j] = (orig->data[i][j] - min) * (lumMax / (max - min));
/**
* @brief Convolve matrix and return the output in matrix conv, The factor is used for divide the result of kernel
*
* @param conv The convolve matrix output
* @param orig The original matrix to use for the convolve
* @param kernel The kernel to apply to the matrix
* @param factor The factor for divide
*/

poulpe
committed
void convolve_matrix(matrix *conv,matrix * orig, const matrix *const kernel, const int32_t factor)
int32_t kmoin = 0 - kernel->row/2;
int32_t kplus = kernel->col / 2;

poulpe
committed
printf("Orig col : %d\n",orig->col);
printf("Orig row : %d\n",orig->row);
printf("Kernplus : %d\n",kplus);
printf("Kernmoins : %d\n",kmoin);
printf("Kern row : %d\n",kernel->row);
for (uint32_t x = 0; x < orig->col; x++)
for (uint32_t y = 0; y < orig->row; y++)
for (int32_t s = kmoin; s <= kplus; s++)
for (int32_t t = kmoin; t <= kplus; t++)

poulpe
committed
// printf("%d",y);
pixels += orig->data[x + s][y + t] * kernel->data[kplus + s][kplus + t];
if (pixels > 65535)
pixels = 65535;
if (pixels < 0)
pixels = 0;

poulpe
committed
conv->data[x][y] = pixels;
double function_for_trapez(double a, uint32_t N, double (*f)(double), double (*O)(double))
{
double delta_x = 0.0;
double res = 0.0;
for (uint32_t i = 0; i < N; i += 1)
{
res += ((*f)(a + i * delta_x) + (*f)(a + (i + 1) * delta_x) / 2) + O(delta_x * delta_x);
}
return res;
}
double fun1(double *signal, int index, int N, int len)
{
double sum = 0.0;
if ((index + N) < len)
{
for (int i = index; i < index + N; i++)
{
sum += signal[i];
}
return sum/N;
}
return 0;
}
double funH(double *signal,int index, int N, int len)
{
double res = 0.0;
double pi = 3.14;
res = (1 / sqrt(2*pi*N))* exp((-signal[index]*signal[index])/2*N);
return res;
}
/**
* @brief Convolve the signal passed in param and return in the out
*
* @param signal The signal to use for convolution
* @param out The double array alloced for get data after convolve
* @param len The length of data in signal
*/