A newer version of the Streamlit SDK is available: 1.62.0
metadata
title: Image Sampling and Quantization Demo
colorFrom: blue
colorTo: purple
sdk: streamlit
sdk_version: 1.39.0
app_file: app.py
pinned: false
license: mit
Interactive Image Sampling and Quantization Demo
An educational demonstration showing how sampling and quantization impact image visualization and storage.
What You'll Learn
This interactive demo teaches fundamental concepts in digital image processing:
1. Spatial Sampling
- How reducing sampling grid size makes images more pixelated
- The direct relationship between pixel count and file size
- Visual impact of resolution reduction
2. Quantization (Bit Depth)
- How bit depth controls the number of colors/gray levels
- The trade-off between image quality and storage
- Visual degradation as bits per pixel decrease
3. Image Compression
- Differences between JPEG and PNG compression
- How JPEG's lossy compression creates blocking artifacts
- Comparison of file sizes across different compression methods
Features
- Interactive Sliders: Real-time adjustment of sampling rate and bit depth
- Live File Size Estimates: See how changes affect storage requirements
- Side-by-Side Comparisons: Original vs. processed images
- Compression Artifacts: Visualize JPEG blocking effects
- Educational Insights: Learn the theory behind each concept
Local Development
Setup
# Clone the repository
git clone <your-repo-url>
cd sampling-quantization
# Install dependencies
pip install -r requirements.txt
Run Locally
# Simple run
streamlit run app.py
# Or use the provided script
chmod +x run_simple.sh
./run_simple.sh
The app will be available at http://localhost:8501
Deployment to Hugging Face Spaces
This app is designed to be deployed to Hugging Face Spaces:
- Create a new Space on Hugging Face
- Choose "Docker" as the SDK
- Push this repository to your Space
Or use the deployment script:
chmod +x deploy.sh
./deploy.sh
Educational Use
This demo is designed for:
- Graduate image analysis courses
- Computer vision fundamentals
- Digital image processing tutorials
- Self-paced learning about image storage
Key Concepts Covered
- Nyquist Sampling Theorem: Understanding sampling limits
- Bit Depth: Relationship between bits and color/gray levels
- File Size Calculation: Width x Height x Bits per pixel / 8
- Lossy vs. Lossless Compression: JPEG vs. PNG trade-offs
- Blocking Artifacts: DCT-based compression effects
Project Structure
sampling-quantization/
βββ app.py # Main Streamlit application
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ packages.txt # System dependencies for HF Spaces
βββ .python-version # Python version specification
βββ pyproject.toml # Project metadata
βββ run_simple.sh # Local development script
βββ deploy.sh # Deployment helper script
βββ sample_images/ # Example images (optional)
License
MIT License - feel free to use for educational purposes.
Credits
Inspired by interactive teaching tools for computer vision education.