# Local Energy Calculation

Hi,

I am trying to calculate the local energy of every pixel using `diff_color` function. To do so, I pass the indexes of 2 pixels to the function, but I keep getting this error message:

``````src/energy.c:54:29: error: passing 'int' to parameter of incompatible type 'struct pixel'
diff_color ((j-1, i), ( j, i));
``````

Am I doing something wrong? Could you please help me with the issue? Thanks in advance

You can’t pass the index of the pixels. You need to pass arguments of type `struct pixel`.
You can (for example) define two pointer to your currently visited pixels and pass their value as arguments:

``````struct pixel* a = /* no spoilers */;
struct pixel* b = /* no spoilers */;
diff_color(*a, *b); // this line would evaluate to the color difference of a and b
``````
1 Like

I might have a misunderstood hier:

like for the pixels in the first row (expect for the very first one…ought to be 0):

their local energy should be diff_color(*a, *(a-1))*diff_color(*a, *(a-1))?

for the pixel in the first column (except the very first one):

diff_color(*a, *(the one direct above a))*diff_color(*a, *(the one direct above a))?

the other normal ones then
diff_color(*a, *(a-1))*diff_color(*a, *(a-1)) + diff_color(*a, *(the one direct above a))*diff_color(*a, *(the one direct above a)) ?

The energy for a pixel `p` ist calculated as follows:
(pseudo code)

``````// where x = any pixel position, w = image width
pixel p = pixels[x];
pixel pixel_neighbor_left = pixels[x-1];
pixel pixel_neighbor_upper = pixels[x-w];

// sum up color differences
local_energy_of_p =
diff_color(p, pixel_neighbor_left) +
diff_color(p, pixel_neighbor_upper);
``````

Hope that pseudo code makes it more clear 1 Like

ok, i see, one last confirmation:

if the pixel position is on the very first column:
the it should be
local_energy_of_p =
diff_color(p, pixel_neighbor_upper);

cause its left neighbor does not exists, so their diff_color is zero?

Exactly. Only visit neighbors that exist @Lux

1 Like