Total Energy at the rightmost boundary in calculate_energy function


in the function mentioned above we are supposed to implement the total energy of every pixel but only considering the first “w” columns. Does this mean that for the calculation of the total energy of a pixel in column “w - 1” we are supposed to ignore the total energy of the upper left neighbor? (the neighbor is present, but it is in a row we want to “ignore”)

I.e. in other words, do we calculate the total energy for every pixel in the entire picture and then omit the rows “w” to "w_0 = (img → w) - 1"OR do we act as if the picture had width w_0 in the first place and hence there is “nothing” left of index “w - 1”.

I understand that even in the second case the original width is not useless information as the energy must be stored s.t. the index of the index of a pixel in “img” is also the index of its total energy in “energy”.


1 Like

If you look at the big picture (i.e. the whole algorithm), you can see that there is only one answer that leads to the desired result:
In every iteration one seam is removed and thus the pixels to the right of that seam are shifted left and on the right side a new column of “empty” pixels – which should be filled with black pixels (see project description) – appears.
These are the pixels with x coordinate greater or equal to w.

Consequently, they should be completely ignored in the calculation of the total energy, as they are not part of image but only still in memory because it would be inefficient to reallocate the memory in every iteration.

Yes, exactly. You also need the original width w0 to access the correct pixels in the image.

I think you had two mix-ups in your description:

I suppose you meant “upper right neighbor”.

I suppose you meant “OR do we act as if the picture had width w”.