This project implements an image manipulation system using OpenCV and C++. It demonstrates fundamental image processing operations including contrast enhancement, rotation, and flipping using Object-Oriented Programming principles.
- β Load and display images
- β
Manual contrast enhancement (without
convertTo()) - β Adjustable brightness control
- β Image rotation (90Β°, 180Β°, 270Β°)
- β Image flipping (horizontal, vertical, both)
- β Interactive menu-driven interface
- β Save processed images
- β Object-oriented design with proper encapsulation
ImageManipulator/
βββ ImageManipulator.h # Header file with class declaration
βββ ImageManipulator.cpp # Implementation file
βββ main.cpp # Main program with interactive menu
βββ demo.cpp # Automated demonstration (optional)
βββ CMakeLists.txt # CMake build configuration
βββ README.md # This file
-
C++ Compiler
- GCC 7.0+ (Linux/Mac)
- Visual Studio 2017+ (Windows)
- Clang 5.0+
-
OpenCV Library (Version 3.x or 4.x)
- Install on Ubuntu/Debian:
sudo apt-get update sudo apt-get install libopencv-dev
- Install on macOS:
brew install opencv
- Install on Windows: Download from OpenCV.org
- Install on Ubuntu/Debian:
-
CMake (Optional, version 3.10+)
sudo apt-get install cmake # Ubuntu/Debian brew install cmake # macOS
# Create build directory
mkdir build
cd build
# Generate build files
cmake ..
# Compile
make
# Run the program
./ImageManipulatorLinux/Mac:
g++ -o ImageManipulator main.cpp ImageManipulator.cpp `pkg-config --cflags --libs opencv4`
./ImageManipulatorWindows (with OpenCV installed):
g++ -o ImageManipulator.exe main.cpp ImageManipulator.cpp -I"C:\opencv\include" -L"C:\opencv\lib" -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_imgproc
ImageManipulator.exe- Create new C++ project
- Add all
.cppand.hfiles - Configure OpenCV:
- Project Properties β C/C++ β Additional Include Directories β Add OpenCV include path
- Project Properties β Linker β Additional Library Directories β Add OpenCV lib path
- Project Properties β Linker β Input β Add required .lib files
- Build and run
-
Start the program:
./ImageManipulator
-
Enter image path when prompted:
Enter image path: /path/to/your/image.jpg -
Choose operations from menu:
========== Image Manipulator Menu ========== 1. Display Original Image 2. Enhance Contrast 3. Rotate Image (90Β°) 4. Rotate Image (180Β°) 5. Rotate Image (270Β°) 6. Flip Horizontally 7. Flip Vertically 8. Flip Both Directions 9. Save Processed Image 10. Load New Image 0. Exit
Choose option 2
Enter alpha: 1.5 (increases contrast)
Enter beta: 20 (increases brightness)
Alpha Guidelines:
alpha > 1.0: Increases contrast (e.g., 1.5, 2.0)alpha = 1.0: No contrast changealpha < 1.0: Decreases contrast (e.g., 0.5, 0.7)
Beta Guidelines:
beta > 0: Increases brightness (e.g., 20, 50)beta = 0: No brightness changebeta < 0: Decreases brightness (e.g., -20, -50)
Choose option 3, 4, or 5
- Option 3: Rotates 90Β° clockwise
- Option 4: Rotates 180Β°
- Option 5: Rotates 270Β° (90Β° counter-clockwise)
Choose option 6, 7, or 8
- Option 6: Horizontal flip (mirror left-right)
- Option 7: Vertical flip (mirror top-bottom)
- Option 8: Both directions (equivalent to 180Β° rotation)
Compile and run the automated demo:
g++ -o demo demo.cpp ImageManipulator.cpp `pkg-config --cflags --libs opencv4`
./demoThis will automatically demonstrate all operations with preset values.
The ImageManipulator class follows OOP principles:
Encapsulation:
- Private data members (
originalImage,processedImage,imagePath) - Public interface methods for all operations
Key Methods:
loadImage(path)- Loads image from fileenhanceContrast(alpha, beta)- Manual pixel-by-pixel contrast adjustmentrotateImage(angle)- Rotates image by 90Β°, 180Β°, or 270Β°flipImage(flipCode)- Flips image horizontally, vertically, or bothdisplayOriginal()- Shows original imagedisplayProcessed()- Shows processed imagesaveImage(path)- Saves processed image to file
Important: We do NOT use convertTo() as required by the assignment.
Manual Implementation:
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
for (each channel in pixel) {
new_value = alpha * old_value + beta
new_value = clamp(new_value, 0, 255)
output_pixel[channel] = new_value
}
}
}Why Manual Implementation?
- Demonstrates understanding of image structure
- Shows pixel-level manipulation skills
- Allows custom processing logic
- Educational value in learning low-level operations
| Parameters | Effect |
|---|---|
| alpha=1.5, beta=0 | Increased contrast, same brightness |
| alpha=1.0, beta=50 | Same contrast, increased brightness |
| alpha=1.3, beta=20 | Both increased |
| alpha=0.7, beta=-30 | Both decreased (darker, less contrast) |
| Operation | Result |
|---|---|
| Rotate 90Β° | Portrait β Landscape conversion |
| Rotate 180Β° | Upside down |
| Flip Horizontal | Mirror image (left becomes right) |
| Flip Vertical | Upside down mirror |
Solution:
- Check if file path is correct
- Ensure image format is supported (JPG, PNG, BMP, etc.)
- Use absolute path if relative path fails
Solution:
# Verify OpenCV installation
pkg-config --modversion opencv4
# If not found, reinstall OpenCV
sudo apt-get install libopencv-devSolution:
- Ensure C++11 or later standard
- Check OpenCV include paths
- Verify all library links
Solution:
- Check if display server is running (Linux)
- Ensure GUI support in OpenCV build
- Try saving image instead of displaying
- Image loading and display
- Contrast enhancement with user input (alpha/beta)
- Manual implementation (NO
convertTo()) - Rotation by 90Β°, 180Β°, 270Β°
- Flipping (horizontal, vertical, both)
- Object-oriented implementation
- Class diagram
- Documentation and report
- Screenshots of results
- Explanation of operations
After completing this assignment, you will understand:
-
Image Representation
- Images as 2D/3D matrices
- Pixel value ranges (0-255)
- Color channels (BGR in OpenCV)
-
Linear Transformations
- Contrast adjustment using multiplication
- Brightness adjustment using addition
- Clamping values to valid range
-
Geometric Transformations
- Rotation mechanics
- Flipping operations
- Coordinate transformations
-
OOP in C++
- Class design and encapsulation
- Constructor/destructor usage
- Method organization
-
OpenCV Basics
- cv::Mat class
- Image I/O operations
- Basic image processing functions
This is an academic assignment. If you want to extend it:
- Add more image filters (blur, sharpen, edge detection)
- Implement custom rotation angles
- Add histogram equalization
- Support batch processing
This project is for educational purposes as part of an academic assignment.
Jawad Ahmed
Roll Number: 533047
Course: Object Oriented Programming
Assignment: Assignment 2 - Image Manipulation using OpenCV
# 1. Install OpenCV
sudo apt-get install libopencv-dev
# 2. Clone/Download project files
# 3. Build
mkdir build && cd build
cmake ..
make
# 4. Run
./ImageManipulator
# 5. Enter image path and enjoy!Last Updated: October 2025