Java matrix-based grayscale (0–255) image ops: vertical/horizontal flip and 90° rotations; deep copies, int[][] storage, O(n*m) per transform.
Author: Shimon Esterkin (207972258)
Version: Maman14.2023b
The Matrix class implements a two-dimensional image processing system for black and white images. Each pixel is represented by an integer value between 0 (white) and 255 (black), representing different shades of gray.
- 2D array of integers (0-255)
- White (0) to Black (255) range
- Grayscale value support
- Custom dimensions
- Vertical flipping
- Horizontal flipping
- 90° clockwise rotation
- 90° counter-clockwise rotation
Matrix.java
├── Constants
│ ├── WHITE (0)
│ └── BLACK (255)
├── Instance Variables
│ └── _mat (int[][])
├── Constructors
│ ├── Matrix(int[][])
│ └── Matrix(int, int)
└── Methods
├── Image Operations
└── Utility Methods
// Create from existing 2D array
int[][] data = {{255, 128, 0}, {0, 128, 255}};
Matrix image = new Matrix(data);
// Create empty matrix
Matrix emptyImage = new Matrix(3, 4); // 3 rows, 4 columns
// Flip operations
Matrix verticalFlip = image.flipVertically();
Matrix horizontalFlip = image.flipHorizontally();
// Rotation operations
Matrix clockwise = image.rotateClockwise();
Matrix counterClockwise = image.rotateCounterClockwise();
-
Vertical Flip
- Mirrors image left to right
- Preserves dimensions
- Each row is reversed
-
Horizontal Flip
- Mirrors image top to bottom
- Preserves dimensions
- Rows are reversed
-
Rotations
- 90-degree transformations
- Dimensions are swapped
- Preserves image content
- Deep copying for constructors
- New matrix for each operation
- Efficient string building
-
Array-based Constructor
Matrix(int[][] array) // Creates deep copy of input array
-
Dimension-based Constructor
Matrix(int rows, int cols) // Creates empty matrix with specified size
- All operations return new Matrix objects
- Original matrix remains unchanged
- Automatic dimension handling
- O(n*m) for all operations
- Efficient memory usage
- Optimized string building
- No recursive operations
-
Image Creation
- Ensure valid dimensions
- Use appropriate constructor
- Verify input data range
-
Transformations
- Consider dimension changes
- Chain operations carefully
- Check results validity
// Complete image inversion
Matrix inverted = original.flipHorizontally().flipVertically();
// 180-degree rotation
Matrix rotated180 = original.rotateClockwise().rotateClockwise();
-
Basic Operations
- Matrix creation
- Simple transformations
- Dimension verification
-
Edge Cases
- Single row/column matrices
- Square vs. rectangular matrices
- Maximum values (255)
-
Transformation Chains
- Multiple flips
- Combined rotations
- Mixed operations
- Fixed value range (0-255)
- No color support
- No diagonal operations
- No image file I/O
- Color support
- Additional transformations
- Image file handling
- Compression support
- Filter operations
- Fork the repository
- Create your feature branch
- Commit your changes
- Create pull request
Note: This implementation is part of an academic project demonstrating matrix operations and image processing concepts in Java.