forked from ugocapeto/thepainter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute_image_moment.c
66 lines (52 loc) · 898 Bytes
/
compute_image_moment.c
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
#include "header.h"
void compute_image_moment(
double *image_arr,
int width,
int height,
int l,
int m,
double *pmoment
)
/*
image_arr is a width*height grayscale image with values between 0.0 and 1.0
*/
/*
l is the degree of the image moment about the x axis
m is the degree of the image moment about the y axis
*/
{
double a;
double b;
int i;
int j;
int pixel;
double intensity_dbl;
double moment;
double x;
double y;
/*
Compute the moment
*/
/*
Initialize the moment
*/
moment= 0.0;
/*
Process the image pixels
*/
for ( i= 0 ; i< height ; i++ ) {
y= (double)i;
for ( j= 0 ; j< width ; j++ ) {
x= (double)j;
pixel= i*width+j;
intensity_dbl= image_arr[pixel];
a= pow(x,(double)l);
b= pow(y,(double)m);
/*
Add to the moment
*/
moment+= a*b*intensity_dbl;
}
}
(*pmoment)= moment;
}