MATH 3120 Final Project - Advanced Singular Value Decomposition for Intelligent Image Compression
Final Project for MATH 3120: Numerical Linear Algebra
University of Pennsylvania, School of Engineering and Applied Science
Fall 2024 - Computer Engineering
A client-side web application demonstrating real-time SVD image compression. This final project showcases the practical applications of numerical linear algebra concepts learned in MATH 3120, combining advanced mathematical theory with modern web technologies for interactive educational visualization.
Live Demo: https://svd-wheat.vercel.app/
- Academic Project Overview
- Features
- Tech Stack
- Screenshots
- Quick Start
- Installation
- Deployment
- Usage
- Architecture
- Mathematical Foundation
- Educational Content
- Limitations
- Contributing
- Academic License and Usage
- Academic Acknowledgments
- Support
- Performance Optimizations
This project represents the culmination of learning in MATH 3120: Numerical Linear Algebra at the University of Pennsylvania. As a final project for the course, it demonstrates the practical application of Singular Value Decomposition (SVD) concepts taught throughout the semester, specifically applied to the domain of image compression.
MATH 3120: Numerical Linear Algebra covers fundamental concepts in computational linear algebra, including:
- Matrix decompositions (SVD, QR, LU)
- Eigenvalue and eigenvector computations
- Numerical stability and error analysis
- Applications to data science and engineering
This final project synthesizes these concepts into a comprehensive web application that demonstrates the power of SVD in image compression, making abstract mathematical concepts tangible through interactive visualization.
The project serves multiple educational purposes:
- Practical Application: Implementing SVD algorithms learned in class
- Real-world Relevance: Demonstrating how linear algebra applies to image processing
- Technical Skills: Combining mathematical theory with modern software development
- Educational Value: Creating an interactive tool for understanding SVD concepts
This academic project goes beyond traditional coursework by:
- Building a client-side web application with browser-based mathematical computing
- Implementing real-time SVD processing with performance monitoring
- Creating educational content that explains the mathematical foundation
- Providing interactive visualizations for better concept understanding
- Demonstrating professional software development practices
- Real-time SVD Processing: Live decomposition with visual progress tracking
- Interactive Parameter Control: Adjustable rank and color mix, plus algorithm selection
- Multi-channel Processing: Separate RGB channel processing for optimal compression
- Performance Monitoring: Real-time metrics including processing time and compression ratios
- Quality Assessment: Built-in quality scoring and visual comparison tools
- Interactive Upload: Drag-and-drop file upload with instant preview
- Real-time Processing: Progress bar and live status updates
- Parameter Controls: Intuitive controls for rank and color mix, plus algorithm selection
- Visual Feedback: Dynamic progress indicators and performance metrics
- Responsive Design: Mobile-friendly interface built with React and Tailwind CSS
- Mathematical Foundation: Comprehensive SVD theory and implementation guides
- Interactive Visualizations: Step-by-step decomposition process demonstrations
- Compression Comparison: Side-by-side original vs compressed image analysis
- Performance Analytics: Detailed metrics and optimization insights
- Educational Content: In-depth explanations of linear algebra concepts
- Graceful Error Recovery: Comprehensive error boundaries and user feedback
- Performance Monitoring: Real-time processing metrics and optimization
- Memory Management: Efficient handling of large image files
- Cross-browser Compatibility: Optimized for modern web browsers
For detailed information about each screenshot, see screenshots/README.md
The main application interface showcasing the interactive SVD image compression tool with the welcome section, image upload area, and primary navigation. Features the professional sci-fi themed design with matrix rain effects and holographic styling that creates an engaging educational experience for MATH 3120 students.
Interactive matrix representation showing how images are converted to numerical matrices for SVD processing. This educational visualization helps MATH 3120 students understand the fundamental concept of representing visual data as mathematical matrices, demonstrating the bridge between linear algebra theory and practical image processing.
Real-time performance monitoring dashboard displaying compression metrics, processing time, memory usage, and quality assessments. This interface provides students with insights into the computational complexity and efficiency of SVD algorithms, directly connecting to the numerical analysis concepts covered in MATH 3120.
Educational quiz interface designed to test student understanding of SVD concepts and image compression principles. This interactive learning tool reinforces the mathematical concepts taught in MATH 3120 through engaging questions about singular value decomposition, matrix decomposition, and compression theory.
Comprehensive system architecture showing client-side structure, data flow, and component relationships.
Interactive SVG visualization comparing original and compressed images with detailed metrics and mathematical analysis. This dynamic diagram illustrates the effectiveness of different SVD rank approximations and provides visual feedback on compression quality, perfect for understanding the trade-offs in numerical linear algebra applications.
Get up and running in under 2 minutes:
# Clone the repository
git clone https://github.com/tmarhguy/svd.git
cd compression-svd
# Install dependencies and start
npm install
npm run dev
# Open your browser to http://localhost:3000- Node.js 20.x - Download
- Modern Web Browser - Chrome, Firefox, Safari, or Edge
Click to expand detailed setup instructions
-
Clone and navigate to the project:
git clone https://github.com/tmarhguy/svd.git cd compression-svd -
Install dependencies:
npm install
-
Start development server:
npm run dev
-
Verify installation: Navigate to
http://localhost:3000
The application uses default configurations optimized for most use cases. For advanced users:
-
Environment variables (optional):
# Frontend (.env.local) # File handling and compute budgets NEXT_PUBLIC_FILE_SIZE_LIMIT=20971520 # 20MB default NEXT_PUBLIC_MAX_LOAD_DIM=1024 # max dimension on load NEXT_PUBLIC_LARGE_CROP_SIDE=1024 # fallback square crop side # Compute pipeline NEXT_PUBLIC_COMPUTE_DIM=256 # working compute dimension NEXT_PUBLIC_PREVIEW_DIM=128 # instant preview dimension NEXT_PUBLIC_MAX_COMPUTE_PIXELS=2000000 # ~2MP compute budget NEXT_PUBLIC_ENABLE_WORKERS=1 # set 0 to disable web workers
-
Performance tuning:
# Client-side processing settings # Workers are enabled by default; set to 0 to force main-thread fallback NEXT_PUBLIC_ENABLE_WORKERS=1 # Adjust compute budget for slower/faster devices NEXT_PUBLIC_COMPUTE_DIM=256 NEXT_PUBLIC_PREVIEW_DIM=128 NEXT_PUBLIC_MAX_COMPUTE_PIXELS=2000000
This project is optimized for Vercel deployment with zero configuration:
-
Install Vercel CLI:
npm i -g vercel
-
Deploy to production:
npm run deploy
-
Deploy preview:
npm run deploy:preview
- Push your code to GitHub
- Connect your repository to Vercel
- Automatic deployments on every push to main branch
- Preview deployments for pull requests
For production customization, set these in your Vercel dashboard:
# File handling and compute budgets
NEXT_PUBLIC_FILE_SIZE_LIMIT=20971520
NEXT_PUBLIC_MAX_LOAD_DIM=1024
NEXT_PUBLIC_LARGE_CROP_SIDE=1024
# Compute pipeline
NEXT_PUBLIC_COMPUTE_DIM=256
NEXT_PUBLIC_PREVIEW_DIM=128
NEXT_PUBLIC_MAX_COMPUTE_PIXELS=2000000
NEXT_PUBLIC_ENABLE_WORKERS=1After deployment, you can add a custom domain in your Vercel dashboard for a professional academic presentation.
Alternative deployment platforms
npm run build
# Deploy as a Next.js app with SSR (functions/edge). Static export is not supported.Static export is not supported due to client-only features and dynamic imports.
npm run build
npm run start
# Runs on http://localhost:3000-
Upload Image:
- Drag and drop an image file or click to browse
- Supported formats: JPG, PNG, BMP, GIF (first frame only)
- Maximum file size: configurable (default 20MB)
-
Adjust Compression Settings:
- Rank Slider: Control the number of singular values (1…maxRank, where maxRank ≈ min(image width, image height))
- Color Mix: Adjust color-vs-grayscale blending of RGB channels
- Algorithm: Choose between power iteration, Jacobi, and QR variants (power iteration is the default)
-
Monitor Processing:
- Real-time progress indicators
- Performance metrics display
- Processing time tracking
-
Review Results:
- Side-by-side comparison
- Quality metrics
Click to expand compression parameter details
Rank Parameter:
- Controls the number of singular values used in reconstruction
- Lower values = higher compression, lower quality
- Higher values = lower compression, higher quality
- Recommended range: 10-50 for most images
Quality Parameter (internal):
- Not exposed in the default UI. The pipeline supports an internal quality weighting under an alternative reconstruction engine; by default the app uses classic truncated SVD controlled by rank.
Color Mix:
- Adjusts processing of RGB channels
- Can optimize for specific color characteristics
- Useful for images with dominant color themes
Click to expand performance monitoring details
Real-time Metrics:
- Processing time (milliseconds)
- Memory usage
- Compression ratio
- Quality score
Performance Indicators:
- Color-coded metrics (green/yellow/red)
- Performance score (0-100)
- Progress bar
- Processing status updates
This section tracks Lighthouse performance over time and highlights optimizations made to the app.
- Global mobile performance (v12.6.0): 43–57 / 100 across regions
- Typical metrics (mobile):
- FCP: ~1.1–1.4s
- LCP: ~3.3–5.0s
- TBT: ~11.7–18.3s
- CLS: 0
Desktop (prod, Lighthouse categories):
- Performance: 90
- Accessibility: 84
- Best Practices: 100
- SEO: 100
Mobile (prod, Lighthouse categories):
- Performance: 73
- Accessibility: 84
- Best Practices: 100
- SEO: 100
Reports saved locally as lighthouse-prod-desktop.json and lighthouse-prod-mobile.json.
- Removed duplicate work on initial upload: single SVD precompute + fast reconstruction
- Parallelized per-channel reconstruction with web workers
- Capped compute size to a predictable budget (computeDim <= 256)
- Reduced SVD effort for startup (rank cap 24, iterations <= 20, power-iteration)
- Debounced slider recompute; reconstruction uses precomputed factors
- Approximate-first SVD, then exact SVD with incremental low-rank updates
- Preserved original aspect ratio and prevented layout shifts (CLS = 0)
- Defer default sample processing until first interaction or idle time
- Ensure a light, static hero is the LCP candidate; move heavy comparison below the fold
- Show instant low-res preview (e.g., 128×128, rank ~12) and refine in background
- content-visibility: auto on heavy sections; lazy-load non-critical assets
# Build and start production server
npm run build
npm run start &
# Run Lighthouse (performance only) and save reports
npx lighthouse http://localhost:3000 \
--only-categories=performance \
--output=json --output=html \
--output-path=./lighthouse/report-prod \
--chrome-flags="--headless=new --no-sandbox"Reports are written to compression-svd/lighthouse/report-prod.report.html and .json.
Summary of applied optimizations that improved responsiveness and startup time:
- React component optimizations:
- Memoization with
useMemo,useCallback, andmemoto reduce re-renders - Code splitting via dynamic imports for heavy sections
- Lazy loading for below-the-fold content
- Memoization with
- SVD computation optimizations:
- Compute dimension capped to 256 with device-aware scaling
- Single SVD precompute then fast reconstructions on slider changes
- Parallel channel work with Web Workers; better error handling
- State and UI performance:
- Debounced slider updates
- Preserved aspect ratios; no layout shifts (stable CLS)
- Matrix visualization uses Canvas for color and a single
<pre>text block for numbers
- Bundle/runtime and config tweaks:
- Removed deprecated/minify flags causing build issues
- Split chunks tuning and removal of problematic
require('crypto')cases - Pruned unused files/assets and slide tooling
Environment defaults (can be adjusted via .env.local):
NEXT_PUBLIC_FILE_SIZE_LIMIT=20971520
NEXT_PUBLIC_MAX_LOAD_DIM=1024
NEXT_PUBLIC_LARGE_CROP_SIDE=1024
NEXT_PUBLIC_COMPUTE_DIM=256
NEXT_PUBLIC_PREVIEW_DIM=128
NEXT_PUBLIC_MAX_COMPUTE_PIXELS=2000000
NEXT_PUBLIC_ENABLE_WORKERS=1
The application follows a modern client-side architecture with comprehensive browser-based processing:
- Frontend: React-based SPA with TypeScript and Tailwind CSS
- SVD Engine: Custom JavaScript implementation of matrix decomposition
- Web Workers: Multi-threaded processing for performance
- Canvas API: Image manipulation and pixel-level processing
- Performance Monitor: Real-time metrics and analytics
- Error Handling: Comprehensive error boundaries and recovery
- Image Upload: Client-side file validation and preview
- Browser Processing: Local SVD decomposition using Web Workers
- Real-time Updates: Progress tracking and live preview
- Result Display: Compressed image and quality metrics
- Performance Analytics: Metrics collection and visualization
SVD decomposes a matrix A into three components:
A = UΣV^T
Where:
- U: Left singular vectors (orthogonal matrix)
- Σ: Singular values (diagonal matrix)
- V^T: Right singular vectors (orthogonal matrix)
- Matrix Representation: Convert image to numerical matrix
- SVD Decomposition: Factorize matrix using SVD
- Rank Reduction: Keep only k largest singular values
- Reconstruction: Rebuild image from reduced components
- Quality Assessment: Compare original vs compressed
Compression Ratio = (Original Size - Compressed Size) / Original Size × 100%
Notes on metrics used in the app:
- Size saved (%) = (Original − Compressed) / Original × 100% (what the UI labels as "Compression" percent reduction)
- Compression ratio (×) = Original / Compressed (e.g., 6.4×). Both can be reported; labels clarify the difference.
- The app computes a PSNR-derived normalized score for display.
- SSIM and MSE are standard metrics discussed in the documentation but are not computed by the current UI.
- What is an Image?: Digital pixel theory and color channels
- How Computers See Images: Matrix representation and processing
- SVD Mathematics: Step-by-step decomposition process
- Compression Comparison: Visual analysis tools
- Real-world Applications: Industry use cases and examples
- Linear Algebra: Matrix operations and transformations
- Eigenvalues/Eigenvectors: Fundamental concepts
- Orthogonal Matrices: Properties and applications
- Numerical Methods: Efficient computation techniques
- Error Analysis: Quality assessment methods
- Step-by-step Guides: Detailed SVD computation process
- Visual Demonstrations: Animated matrix transformations
- Parameter Exploration: Real-time parameter adjustment
- Quality Assessment: Built-in comparison tools
- Performance Analytics: Detailed metrics and insights
- File Size: Maximum 20MB per image (configurable via
NEXT_PUBLIC_FILE_SIZE_LIMIT) - Format Support: JPG, PNG, BMP, and GIF (first frame only)
- Processing Time: Large images may take several seconds
- Browser Compatibility: Modern browsers required
- Memory Usage: Large images require significant memory
- Very Large Images: May cause browser memory issues
- Complex Textures: Some textures may not compress well
- Color Accuracy: Slight color shifts possible with high compression
- Processing Limits: Client-side processing limitations
We welcome contributions! Here's how to get started:
Click to expand contribution guidelines
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes and test thoroughly
- Commit with conventional commits:
git commit -m "feat: add amazing new feature" - Push to your fork and create a Pull Request
# Clone your fork
git clone https://github.com/yourusername/svd.git
# Install dependencies and start
cd compression-svd && npm install
# Run development server
npm run dev- TypeScript: Strict mode, comprehensive typing
- JavaScript: ES6+, modern syntax, proper error handling
- Testing: Maintain >80% code coverage
- Documentation: Update README for new features
- Performance: Optimize for large image processing in browser
- Frontend: React components, UI/UX improvements
- Algorithms: SVD optimization, mathematical accuracy
- Documentation: Tutorials, mathematical explanations
- Testing: Unit tests, integration tests
- Performance: Web Workers, memory optimization
This project is licensed under the MIT License.
Important Note: This is an academic final project for MATH 3120: Numerical Linear Algebra at the University of Pennsylvania. While the code is open source under MIT License, this work represents original academic effort for course requirements.
- This project represents original work completed for MATH 3120 final project requirements
- All mathematical concepts are based on course materials and standard numerical linear algebra texts
- Implementation follows academic best practices for educational software development
- Code is shared for educational purposes and portfolio demonstration
- ✅ Commercial use allowed (post-graduation)
- ✅ Modification allowed for learning purposes
- ✅ Distribution allowed with attribution
- ✅ Private use allowed
If you use this project for academic purposes, please cite as:
Marhguy, T. (2024). SVD Image Compression: A Numerical Linear Algebra Approach.
Final Project for MATH 3120: Numerical Linear Algebra.
University of Pennsylvania, School of Engineering and Applied Science.
https://github.com/tmarhguy/svd
This is a final project for MATH 3120: Numerical Linear Algebra at the University of Pennsylvania.
- Course instructor: Maxine Elena Calle — Mathematics Ph.D. student and NSF Graduate Research Fellow at the University of Pennsylvania. Research interests include algebraic topology, homotopy theory, and category theory, with an interest in mathematical visualization and communication. See profile: web.sas.upenn.edu/callem
- Gratitude to teaching staff and classmates for a supportive learning environment
- MATH 3120: Numerical Linear Algebra — Course framework and mathematical foundation
- University of Pennsylvania, School of Engineering and Applied Science — Academic context
- Next.js/React — Web UI and interactivity
- TypeScript — Type-safe development
- Tailwind CSS — Styling
- Web Workers & Canvas API — In-browser computation and rendering
- Course materials and standard numerical linear algebra references
- Academic papers on SVD and image compression
- Open-source community resources used for learning
Quick Links:
Student: Tyrone Marhguy
University Email: tmarhguy@seas.upenn.edu
Course: MATH 3120 - Numerical Linear Algebra (Final Project)
University: University of Pennsylvania, School of Engineering and Applied Science
Major: Computer Engineering, Class of 2028
Semester: Fall 2024
Project Type: Final Course Project - Numerical Linear Algebra Applications
Star this repository if you found this MATH 3120 final project helpful!
Academic Final Project by Tyrone Marhguy for MATH 3120: Numerical Linear Algebra
University of Pennsylvania, School of Engineering and Applied Science
Fall 2024 - Computer Engineering Class of 2028



