This application is a seam carving tool designed to reduce the width of an image by removing vertical seams. It uses advanced image processing techniques to calculate energy maps and determine which seams to remove, enhancing image retargeting. The process considers the image's saliency, depth, gradient, and entropy maps.
- Energy Calculation: Computes an energy map using edge detection, saliency, depth, and entropy maps to guide seam removal. 🔍
- Seam Finding and Removal: Identifies and removes the lowest energy seams iteratively. ✂️
- Seam Visualization: Highlights seams on the image during the carving process for better visualization. 🌟
- Graphical User Interface (GUI): A Tkinter-based GUI for user interaction, allowing easy input of parameters and real-time progress updates. 🖥️
- OpenCV
- NumPy
- scikit-image
- Tkinter
- Pillow
-
Clone the repository:
git clone <repository_url> cd <repository_directory>
-
Install required Python packages:
pip install opencv-python-headless numpy scikit-image pillow
-
Sample Dataset: In the
sample_dataset
folder, each subfolder should be named according to the image category (e.g., Diana). Each subfolder should contain the saliency map and depth map for the corresponding images. 🗂️
-
Run the Application:
python seam_carving_app.py
-
GUI Interaction:
- Enter Category: Input the image category (e.g., Diana, Baby, Snowman). 🖼️
- Number of Columns to Delete: Specify the number of vertical seams (columns) to remove. 📉
- Start Seam Carving: Click the button to begin the process. 🚀
-
Output:
- The application will display the image with highlighted seams during the process. 👁️
- Upon completion, the output image will be saved to the specified directory. 💾
In the calculate_energy
function, we compute the energy map for seam carving using several steps:
-
Gradient Map Calculation: Compute the gradient map of the image.
- Split the gradient map into smaller blocks.
- Calculate the average luminance level for each block.
- Sort the blocks based on their average luminance levels and select the top 87 highest values.
- Multiply the pixels in these blocks by a constant factor of 4.5.
-
Entropy and Depth Maps:
- Calculate the average luminance level for each block in the depth map and the entropy map.
- Compute the overall mean luminance for all blocks in both maps.
- Iterate through the blocks in the entropy map. For blocks where the average depth is below the overall mean depth and the average entropy is above the overall mean entropy, multiply the pixels by a constant factor of 2. This adjustment is made because these regions are considered less important.
if avg_depth_blocks[i, j] < overall_mean_depth and overall_mean_entropy < avg_entropy_blocks[i, j]: block = entropy_energy_normalized[i*block_size_y:(i+1)*block_size_y, j*block_size_x:(j+1)*block_size_x] adjusted_entropy[i*block_size_y:(i+1)*block_size_y, j*block_size_x:(j+1)*block_size_x] = 2 * block
-
Saliency Map:
- Calculate the saliency map and split it into blocks.
- Select the top 120 blocks based on their luminance levels and multiply the pixels in these blocks by a factor of 1.5.
-
Depth Map:
- Apply Otsu thresholding to the depth map.
- Multiply the pixels that exceed the Otsu threshold by a factor of 7.
-
Combining Energy Maps:
- Combine the adjusted energy maps using specific weights:
energy_combined = ( 1.0 * adjusted_energy_edge + 1.0 * adjusted_saliency_map + 1.0 * adjusted_depth_map + 0.5 * -adjusted_entropy )
Our seam carving approach provides visually superior results compared to the methods outlined in the paper "Seam Carving for Content-Aware Image Resizing" (ICIP 2014) link to paper. Specifically, for images categorized as 'people' and 'snowman,' our method excels in preserving important content and minimizing visual distortion.
In particular:
-
For 'people' images: Our approach maintains the integrity of facial features and other critical details better, resulting in more natural-looking resized images. 👤✨
-
For 'snowman' images: The preservation of the snowman's shape and details is notably better, avoiding the unnatural distortions that can occur with other seam carving techniques. ⛄🔍
These improvements in visual quality make our method a preferable choice for applications requiring high fidelity in image retargeting. 🏆
🎉 We’re excited about contributions and forks! If you have any questions or suggestions, please feel free to reach out to us:
- Mohammad Hossein: [email protected] 📧
- Amir Reza: [email protected] 📧