svd

# SVD Image Compression **MATH 3120 Final Project - Advanced Singular Value Decomposition for Intelligent Image Compression** [![Academic Project](https://img.shields.io/badge/Academic-MATH%203120%20Final%20Project-blue.svg)](https://www.upenn.edu/) [![University](https://img.shields.io/badge/University-Penn%20Engineering-red.svg)](https://www.seas.upenn.edu/) [![Course](https://img.shields.io/badge/Course-Numerical%20Linear%20Algebra-green.svg)](https://www.math.upenn.edu/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?logo=typescript&logoColor=white)](https://www.typescriptlang.org/) [![React](https://img.shields.io/badge/React-20232A?logo=react&logoColor=61DAFB)](https://reactjs.org/) [![Next.js](https://img.shields.io/badge/Next.js-000000?logo=next.js&logoColor=white)](https://nextjs.org/) **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/

Table of Contents

Academic Project Overview

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.

Course Context

MATH 3120: Numerical Linear Algebra covers fundamental concepts in computational linear algebra, including:

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.

Academic Objectives

The project serves multiple educational purposes:

Project Scope

This academic project goes beyond traditional coursework by:

Features

Core Compression Capabilities

Advanced Web Interface

Educational Components

Error Handling & Performance

Tech Stack

### Frontend ![React](https://img.shields.io/badge/React-20232A?style=for-the-badge&logo=react&logoColor=61DAFB) ![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white) ![Next.js](https://img.shields.io/badge/Next.js-000000?style=for-the-badge&logo=next.js&logoColor=white) ![TailwindCSS](https://img.shields.io/badge/Tailwind_CSS-38B2AC?style=for-the-badge&logo=tailwind-css&logoColor=white) ![Framer Motion](https://img.shields.io/badge/Framer_Motion-0055FF?style=for-the-badge&logo=framer&logoColor=white) ### Core Processing ![JavaScript](https://img.shields.io/badge/JavaScript-F7DF1E?style=for-the-badge&logo=javascript&logoColor=black) ![Web Workers](https://img.shields.io/badge/Web_Workers-FF6B35?style=for-the-badge&logo=web&logoColor=white) ![Canvas API](https://img.shields.io/badge/Canvas_API-FF4081?style=for-the-badge&logo=html5&logoColor=white) ### Mathematical Libraries ![Client-Side SVD](https://img.shields.io/badge/Client_Side_SVD-9C27B0?style=for-the-badge&logo=algorithm&logoColor=white) ![Linear Algebra](https://img.shields.io/badge/Linear_Algebra-FF6B6B?style=for-the-badge&logo=math&logoColor=white) ![Browser Computing](https://img.shields.io/badge/Browser_Computing-4CAF50?style=for-the-badge&logo=javascript&logoColor=white)

Screenshots

For detailed information about each screenshot, see screenshots/README.md

Main Interface

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.

Main Interface

Matrix Visualization

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.

Matrix Visualization

Performance Analytics

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.

Performance Analytics

Interactive Quiz

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.

Interactive Quiz

System Architecture

Comprehensive system architecture showing client-side structure, data flow, and component relationships.

System Architecture

Compression Comparison Visualization

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.

Compression Comparison

Quick Start

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

Installation

Prerequisites

Setup

Click to expand detailed setup instructions 1. **Clone and navigate to the project:** ```bash git clone https://github.com/tmarhguy/svd.git cd compression-svd ``` 2. **Install dependencies:** ```bash npm install ``` 3. **Start development server:** ```bash npm run dev ``` 4. **Verify installation:** Navigate to `http://localhost:3000`

Configuration

The application uses default configurations optimized for most use cases. For advanced users:

  1. 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
    
  2. 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
    

Deployment

This project is optimized for Vercel deployment with zero configuration:

One-Click Deploy

Deploy with Vercel

Manual Deployment

  1. Install Vercel CLI:

    npm i -g vercel
    
  2. Deploy to production:

    npm run deploy
    
  3. Deploy preview:

    npm run deploy:preview
    

GitHub Integration

  1. Push your code to GitHub
  2. Connect your repository to Vercel
  3. Automatic deployments on every push to main branch
  4. Preview deployments for pull requests

Environment Variables (Optional)

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=1

Custom Domain

After deployment, you can add a custom domain in your Vercel dashboard for a professional academic presentation.

Other Deployment Options

Alternative deployment platforms #### **Netlify** ```bash npm run build # Deploy as a Next.js app with SSR (functions/edge). Static export is not supported. ``` #### **GitHub Pages** Static export is not supported due to client-only features and dynamic imports. #### **Self-Hosted** ```bash npm run build npm run start # Runs on http://localhost:3000 ```

Usage

Web Interface

  1. 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)
  2. 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)
  3. Monitor Processing:
    • Real-time progress indicators
    • Performance metrics display
    • Processing time tracking
  4. Review Results:
    • Side-by-side comparison
    • Quality metrics

Compression Settings

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

Performance Monitoring

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

Performance Evolution (Lighthouse)

This section tracks Lighthouse performance over time and highlights optimizations made to the app.

Previous Production (svd-wheat.vercel.app)

Current Local Production Build (this repo)

Desktop (prod, Lighthouse categories):

Mobile (prod, Lighthouse categories):

Reports saved locally as lighthouse-prod-desktop.json and lighthouse-prod-mobile.json.

What changed (high impact optimizations)

Planned/Recommended for better LCP (< 4s)

Reproducing Lighthouse locally

# 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.

Performance Optimizations

Summary of applied optimizations that improved responsiveness and startup time:

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

Architecture

The application follows a modern client-side architecture with comprehensive browser-based processing:

Core Components

Data Flow

  1. Image Upload: Client-side file validation and preview
  2. Browser Processing: Local SVD decomposition using Web Workers
  3. Real-time Updates: Progress tracking and live preview
  4. Result Display: Compressed image and quality metrics
  5. Performance Analytics: Metrics collection and visualization

Mathematical Foundation

Singular Value Decomposition (SVD)

SVD decomposes a matrix A into three components:

A = UΣV^T

Where:

Image Compression Process

  1. Matrix Representation: Convert image to numerical matrix
  2. SVD Decomposition: Factorize matrix using SVD
  3. Rank Reduction: Keep only k largest singular values
  4. Reconstruction: Rebuild image from reduced components
  5. Quality Assessment: Compare original vs compressed

Compression Ratio

Compression Ratio = (Original Size - Compressed Size) / Original Size × 100%

Notes on metrics used in the app:

Quality Metrics

Educational Content

Interactive Learning Modules

Mathematical Concepts Covered

Interactive Features

Limitations

Current Constraints

Known Issues

Contributing

We welcome contributions! Here’s how to get started:

Click to expand contribution guidelines ### Quick Contribution Guide 1. **Fork the repository** 2. **Create a feature branch:** ```bash git checkout -b feature/amazing-feature ``` 3. **Make your changes and test thoroughly** 4. **Commit with conventional commits:** ```bash git commit -m "feat: add amazing new feature" ``` 5. **Push to your fork and create a Pull Request** ### Development Setup ```bash # 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 ``` ### Code Standards - **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 ### Areas for Contribution - **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

Academic License and Usage

This project is licensed under the MIT License.

Academic Context

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.

Academic Integrity

License Terms

Citation

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

Academic Acknowledgments

This is a final project for MATH 3120: Numerical Linear Algebra at the University of Pennsylvania.

Course and Institution

Technical Acknowledgments

Educational Resources

Support & Community

### Need Help? [![GitHub Issues](https://img.shields.io/badge/GitHub-Issues-red?style=for-the-badge&logo=github)](https://github.com/tmarhguy/svd/issues) [![Discussions](https://img.shields.io/badge/GitHub-Discussions-blue?style=for-the-badge&logo=github)](https://github.com/tmarhguy/svd/discussions) **Quick Links:** - [Report Bug](https://github.com/tmarhguy/svd/issues/new?template=bug_report.md) - [Request Feature](https://github.com/tmarhguy/svd/issues/new?template=feature_request.md) - [View Documentation](https://github.com/tmarhguy/svd/wiki) - [Join Discussion](https://github.com/tmarhguy/svd/discussions) ### Student Information **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 ### Social Links - [LinkedIn](https://linkedin.com/in/tyrone-marhguy) - [GitHub](https://github.com/tmarhguy) - [Portfolio](https://tmarhguy.github.io/tmarhguy) - [Instagram](https://instagram.com/tyrone_marhguy) - [Twitter](https://twitter.com/marhguy_tyrone)

**Star this repository if you found this MATH 3120 final project helpful!** _Academic Final Project by [Tyrone Marhguy](https://github.com/tmarhguy) for MATH 3120: Numerical Linear Algebra_ _University of Pennsylvania, School of Engineering and Applied Science_ _Fall 2024 - Computer Engineering Class of 2028_