File size: 3,680 Bytes
3425796
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
title: 'Structura AI: Depth & Structural Masking'
sdk: docker
emoji: πŸš€
colorFrom: indigo
colorTo: blue
pinned: true
app_port: 8000
---

# Structura AI: Depth & Structural Masking Web Application

Structura AI is a web-based image analysis tool that generates a structural mask by combining monocular depth estimation and texture-based feature detection.
The system integrates MiDaS (DPT-Hybrid) for depth prediction with OpenCV-based edge, corner, and texture fusion to produce a detailed, high-frequency structural representation of any input image.

This mask is useful for segmentation workflows, diffusion model conditioning, preprocessing for generative AI, architectural analysis, and general computer vision pipelines.

---

## Features

* MiDaS Depth Estimation: High-quality depth prediction using the DPT-Hybrid model.
* Combined Structural Masking: Fusion of depth gradients, edges (Canny), Laplacian detail, and Harris corner responses.
* FastAPI Backend: Clean API endpoint (`POST /mask/`) returning PNG masks with inference time metadata.
* Web UI: A simple and modern interface built with HTML, CSS, and JavaScript allowing image upload, preview, overlay visualization, and mask download.
* Docker Support: Fully dockerized and ready for deployment on services such as Hugging Face Spaces.

---

## Demo

This section is reserved for demo images and demo videos.
Add examples such as:

* Original input image
* Generated structural mask
* Overlay visualization
* A short screen recording demonstrating the UI

---

## Technology Stack

Backend: FastAPI, Uvicorn
AI / Computer Vision: PyTorch, MiDaS, OpenCV (headless), NumPy
Frontend: HTML, CSS, JavaScript
Deployment: Docker, Hugging Face Spaces

---

## Repository Structure

```
structura-ai/
β”œβ”€β”€ app.py
β”œβ”€β”€ depth_texture_mask.py
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ templates/
β”‚   └── index.html
└── static/
    β”œβ”€β”€ styles.css
    └── app.js
```

---

## Local Installation and Usage

### 1. Clone the Repository

```
git clone https://github.com/PritamTheCoder/midas-depth-texture-mask-api.git
cd midas-depth-texture-mask-api
```

### 2. Create and Activate a Virtual Environment

```
python -m venv venv

# Windows
venv\Scripts\activate

# macOS / Linux
source venv/bin/activate
```

### 3. Install Dependencies

```
pip install -r requirements.txt
```

### 4. Start the Application

```
uvicorn app:app --reload --host 0.0.0.0 --port 8000
```

### 5. Access the Web UI

Open the browser and navigate to:
[http://127.0.0.1:8000/](http://127.0.0.1:8000/)

The MiDaS model weights will automatically download on the first startup.

---

## Deployment on Hugging Face Spaces (Docker)

The project includes a Dockerfile configured for seamless deployment on Hugging Face Spaces.

### Required File Structure

Ensure the following files are present at the repository root:

```
Dockerfile
app.py
depth_texture_mask.py
requirements.txt
templates/
static/
```

### Deployment Steps

1. Create a new Hugging Face Space.
2. Select "Docker" as the runtime.
3. Upload or commit all repository files.
4. Hugging Face will automatically:

   * Build the Docker image
   * Install dependencies
   * Expose the correct port
   * Start the FastAPI server

The application will then be available as a hosted interactive web demo.

---

## License

This project is licensed under the MIT License.
See the LICENSE file for details.

---

## Acknowledgements

MiDaS by Intel-ISL
FastAPI for backend framework
OpenCV for feature detection and image processing
PyTorch for deep learning inference support
Hugging Face for deployment infrastructure

---