Find_print_min_path

I’ve looked at the description of the minimum energy path, but I’m not really sure what I should print. By x index, should I print the index that I have stored in the seam? If so, why is the parameter in the function find_print_min_path img and not seam?

Hi Christinaa,

the seam in the image runs from top to bottom, so there is one pixel per row that is part of it.
You are supposed to print the x-indices of those pixels.
Finding those indices and populating the seam array with them is supposed to be handled by the function calculate_optimal_path in the file energy.c, so you are correct in that you should print the entries of that seam array.
For this, make sure to follow the format outlined in the project description.

Regarding the second part of your question:

If so, why is the parameter in the function find_print_min_path img and not seam?

If you peek into the main function, you can see only find_print_min_path is called for its respective flag, but none of the other functions you are supposed to implement in this exercise.
The one responsible for that is exactly the find_print_min_path function, so it would not make sense to have the seam as a parameter - you first need to find it by calling the correct functions from within, before printing it.
That basically leaves the find_print_min_path function with three tasks:

  • Handle the memory required for the energy matrix and seam array
  • Determine the seam with the help of calculate_energy, calculate_min_energy_column, and calculate_optimal_path
  • Print the results

Does this answer your question?

Lucas

4 Likes

Thank you for your response. Most of my questions have been answered. However, there’s a few things that I’m not really sure of.

What the ‘x indices of a pixel’ mean?

Since I have to specify the parameters myself, should I just assign the value of ‘w’ in the functions calculate_energy , calculate_min_energy_column , and calculate_optimal_path, as the width of the image?

Moreover, I tried to initialise seam and energy using seam_init and energy_init in the find_print_min_path function but got an error that said

implicit declaration of function ‘seam_init’ is invalid in C99’. Is this not how I’m supposed to initialise them?

What the ‘x indices of a pixel’ mean?

If you take a look at figure 2 in the project description, you can see each pixel can be assigned a position in the image, consisting of a row and a column. Here, x is the column a pixel is located in, while y is the row of the pixel. Section 2.3 then explains how this translates to the one-dimensional array representation used in the image structure.

Since I have to specify the parameters myself, should I just assign the value of ‘w’ in the functions calculate_energy , calculate_min_energy_column , and calculate_optimal_path , as the width of the image?

Yes, in this sub-task we consider the whole image, so your idea is correct. The parameter w becomes more relevant when you actually carve the seam out of the image in sub-task 3.3.

Is this not how I’m supposed to initialise them?

The functions energy_init and seam_init are used internally by the tests and not directly usable in the rest of the project since .c files are not supposed to be included elsewhere, but you can of course use them as inspiration. :wink:

4 Likes

Thank you. This was very helpful. :smile: