An implementation of the seam-carving algorithm for content-aware image resizing. Users can resize an image by defining its desired height and width in pixels.
- Seam-carving is a content-aware image resizing method where the image size is reduced pixel by pixel, either in height or width.
- Vertical seams connect pixels from the top to the bottom with one pixel in each row, and horizontal seams connect pixels from left to right with one pixel in each column.
- Steps:
- Energy Calculation: Every pixel has RGB values. Calculate energy for each pixel using, for example, the dual-gradient energy function. (However, other energy functions can be chosen.
- Seam Identification: Identify the lowest energy seam.
- Seam Removal: Eliminate the identified seam.
- Extract RGB values for each pixel from
./data/input/sample.jpeg
and save them into./data/input/rgb_in.txt
. - Load RGB values from
./data/input/rgb_in.txt
into a 3D matrix. - Execute the seam carving algorithm.
- Store RGB values of the resized image into
./data/output/rgb_out.txt
. - Create
./data/output/sample_out.jpeg
from./data/output/rgb_out.txt
.
The Python script ./src/driver.py
does the 1st and 5th steps. The corresponding ./src/main.cpp
file, triggered by the Python script, handles the 2nd and 4th steps.
-
Pillow (Python Imaging Library): Utilized for extracting RGB pixel values and regenerating images from these values.
pip install Pillow
Note: This Python script is compatible with Linux/Mac OS only. Windows users may request the input text file (rgb_in.txt) to begin working on the problem.
-
Navigate to the
**Image_Resizer**
directory in the terminal. -
Run the
driver.py
Python script located in/src
. Pass the input image filename (must reside in/data/input
) as a command line argument.python ./src/driver.py sample1.jpeg