Description
Now you are able to manipulate pictures and ready to start.
The first step is to calculate the energy for each pixel of the image. Energy is the pixel's importance. The higher the pixel energy, the less likely this pixel is to be removed from the picture while reducing.
There are several different energy functions invented for seam carving. In this project, we will use dual-gradient energy function.
The energy of the pixel is
Where the square of x-gradient
y-gradient
Don't be confused! You will calculate values and that are already squared, so you don't need to square them again to calculate .
Where , , are differences of red, green and blue components between pixels and .
Let's consider a grey pixel on the example image:
X-differences are:
So, x-gradient is
Y-differences are:
Same for y-gradient
Finally,
Energy for border pixels is calculated with a 1-pixel shift from the border. For example:
Objective
Calculate energies for all pixels of the image. Normalize calculated energies using the following formula:
intensity = (255.0 * energy / maxEnergyValue).toInt()
To display energy as a grey-scale image, set color components of the output image pixels to calculated intensity. For example, (red = intensity, green = intensity, blue = intensity).
You should use double precision in this and in the following stages.
Example
The greater-than symbol followed by a space (> ) represents the user input. Note that it's not part of the input.
> java Main -in sky.png -out sky-energy.png
For the following sky.png:
sky-energy.png should look like this: