Spaces:
Runtime error
Runtime error
File size: 7,410 Bytes
dead0ef | 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | # π Getting Started with the Edge Detection Demo
## Prerequisites
- **Python 3.11+** (Python 3.9+ should also work)
- **Git** (for cloning the repository)
- **pip** (usually comes with Python)
- **5-10 minutes** of your time
Optional:
- **Make** (for convenient commands)
- **Docker** (for containerized deployment)
## β‘οΈ Quick Start (30 seconds)
The absolute fastest way to get started:
```bash
# 1. Navigate to the project directory
cd edge-detection
# 2. Run the setup script
./setup.sh
# 3. Run the app
./run_simple.sh
```
That's it! Your browser should open to `http://localhost:8501`
---
## π Detailed Installation
### Step 1: Clone the Repository (if needed)
```bash
git clone <repository-url>
cd edge-detection
```
### Step 2: Choose Your Setup Method
#### Option A: Automated Setup Script (Recommended)
```bash
chmod +x setup.sh
./setup.sh
```
This will:
- Check Python version
- Create a virtual environment
- Install all dependencies
#### Option B: Manual Setup
```bash
# Create virtual environment
python3 -m venv venv
# Activate virtual environment
source venv/bin/activate # On macOS/Linux
# OR
venv\Scripts\activate # On Windows
# Upgrade pip
pip install --upgrade pip
# Install dependencies
pip install -r requirements.txt
```
#### Option C: Using Make
```bash
make setup
```
### Step 3: Run the Application
#### Option A: Quick Run Script
```bash
chmod +x run_simple.sh
./run_simple.sh
```
#### Option B: Manual Run
```bash
source venv/bin/activate # Activate virtual environment
streamlit run app.py
```
#### Option C: Using Make
```bash
make run
```
### Step 4: Open in Browser
The app should automatically open in your default browser at:
```
http://localhost:8501
```
If it doesn't open automatically, manually navigate to that URL.
---
## π First Steps in the Demo
Once the app is running:
1. **Upload an Image** (optional)
- Look in the sidebar
- Click "Upload your own image"
- Or use the default generated image
2. **Try Different Methods**
- Select "Sobel" from the dropdown
- Observe the edge detection results
- Try adjusting the kernel size
- Enable "Show Gradient Components"
3. **Explore Prewitt and Roberts**
- Switch methods and compare results
- Notice differences in edge quality and noise sensitivity
4. **Experiment with Laplacian**
- Observe the isotropic response
- See why pre-smoothing is important
- Try different kernel sizes
5. **Master Canny**
- Adjust low and high thresholds
- Observe edge connectivity
- Compare with simpler methods using comparison mode
6. **Read Educational Content**
- Click on the four tabs at the bottom
- Read the explanations
- Understand the mathematical foundations
---
## π§ Troubleshooting
### Problem: "Python not found"
**Solution:**
```bash
# Check if Python is installed
python3 --version
# If not, install Python 3.11+ from python.org
```
### Problem: "Permission denied" when running scripts
**Solution:**
```bash
chmod +x *.sh
```
### Problem: Import errors when running
**Solution:**
```bash
# Make sure you're in the virtual environment
source venv/bin/activate
# Reinstall requirements
pip install --force-reinstall -r requirements.txt
```
### Problem: "Port 8501 already in use"
**Solution:**
```bash
# Find and kill the process using the port
lsof -ti:8501 | xargs kill
# Or run on a different port
streamlit run app.py --server.port 8502
```
### Problem: Images not displaying
**Solution:**
- Check internet connection (for HuggingFace download)
- The app will automatically fall back to a generated image
- Try uploading your own image via the sidebar
### Problem: Slow performance
**Solution:**
- Use smaller images (app auto-resizes to 512px)
- Close other applications
- Try simpler methods (Roberts, Sobel) instead of Canny
---
## π― Next Steps
### For Students
- Work through the educational tabs systematically
- Try uploading different types of images (portraits, landscapes, text)
- Compare all five methods on the same image
- Answer the discussion questions in PROJECT_SUMMARY.md
### For Instructors
- Review QUICKSTART.md for teaching tips
- Customize the app (see CONTRIBUTING.md)
- Deploy to Hugging Face Spaces (see below)
- Share with your class
### For Developers
- Read CONTRIBUTING.md for development guidelines
- Check out PROJECT_SUMMARY.md for technical details
- Consider adding new features (multi-scale, learning-based methods)
---
## π Deploying to Hugging Face Spaces
Want to share this with others online?
### Step 1: Create a Hugging Face Account
- Go to https://huggingface.co/join
- Sign up for free
### Step 2: Create a New Space
- Go to https://huggingface.co/new-space
- Choose "Streamlit" as the SDK
- Make it public (for educational use)
### Step 3: Deploy
```bash
chmod +x deploy.sh
./deploy.sh
```
Follow the prompts and enter your Space name (e.g., "username/edge-detection-demo").
Your demo will be live at: `https://huggingface.co/spaces/username/edge-detection-demo`
---
## π³ Docker Deployment (Advanced)
If you prefer Docker:
```bash
# Build the image
docker build -t edge-detection .
# Run the container
docker run -p 8501:8501 edge-detection
# Access at http://localhost:8501
```
---
## π Common Commands Reference
```bash
# Setup and installation
./setup.sh # Initial setup
make setup # Alternative using make
# Running the app
./run_simple.sh # Quick run
make run # Alternative using make
streamlit run app.py # Direct run
# Testing
python test_setup.py # Verify installation
make test # Alternative using make
# Deployment
./deploy.sh # Deploy to HuggingFace
make deploy # Alternative using make
# Cleanup
make clean # Remove virtual environment
```
---
## π‘ Tips for Best Experience
1. **Image Selection**: Use images with clear edges (buildings, objects, text)
2. **Pre-processing**: Enable Gaussian blur for noisy images
3. **Parameter Tuning**: Start with default values, then experiment
4. **Comparison**: Use comparison mode to understand differences
5. **Educational Content**: Read tabs in order (What Are Edges? β Gradient Methods β Canny β Practical)
---
## π Learning Path
**Beginner** (1-2 hours):
1. Read "What Are Edges?" tab
2. Try Roberts and Sobel
3. Compare results on sample image
4. Upload your own image
**Intermediate** (2-4 hours):
1. Study gradient-based methods tab
2. Experiment with all five methods
3. Enable gradient visualizations
4. Try different kernel sizes
5. Read Canny algorithm tab
**Advanced** (4+ hours):
1. Study practical considerations tab
2. Tune Canny parameters systematically
3. Compare methods quantitatively
4. Test on domain-specific images
5. Consider implementing improvements
---
## π Getting Help
- **Documentation**: Check README.md, QUICKSTART.md, PROJECT_SUMMARY.md
- **GitHub Issues**: Report bugs or request features
- **Discussion Board**: Ask questions about edge detection concepts
---
## β
Verification
To verify everything is working correctly:
```bash
python test_setup.py
```
This will check:
- All dependencies are installed
- App structure is correct
- Edge detection functions work
- Visualizations render properly
---
**Ready to explore edge detection?** Run `./run_simple.sh` and start learning! π
|