File size: 3,309 Bytes
2d190aa d962d48 2d190aa d962d48 2d190aa d962d48 2d190aa d962d48 2d190aa d962d48 2d190aa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | ---
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
```bash
# Clone the repository
git clone <your-repo-url>
cd sampling-quantization
# Install dependencies
pip install -r requirements.txt
```
### Run Locally
```bash
# 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:
1. Create a new Space on [Hugging Face](https://huggingface.co/spaces)
2. Choose "Docker" as the SDK
3. Push this repository to your Space
Or use the deployment script:
```bash
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.
|