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