File size: 9,200 Bytes
2830970
 
 
 
 
5edd87d
2830970
 
 
5edd87d
2830970
 
 
 
e97e778
 
 
 
2830970
 
 
 
 
 
 
5edd87d
2830970
5edd87d
 
2830970
 
5edd87d
 
e97e778
5edd87d
2830970
5edd87d
 
 
 
 
2830970
5edd87d
 
 
 
 
 
e97e778
 
2830970
 
 
 
5edd87d
2830970
 
 
 
5edd87d
2830970
 
 
 
e97e778
 
 
 
5edd87d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e97e778
 
 
5edd87d
 
 
2830970
5edd87d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21e7265
2830970
 
 
 
5edd87d
 
2830970
 
5edd87d
 
 
2830970
5edd87d
 
21e7265
5edd87d
 
 
 
 
2830970
 
5edd87d
 
 
 
 
2830970
 
e97e778
 
5edd87d
e97e778
5edd87d
 
 
 
2830970
 
5edd87d
2830970
5edd87d
 
 
 
 
 
 
 
 
2830970
 
e97e778
21e7265
 
e97e778
 
21e7265
2830970
 
 
e97e778
5edd87d
e97e778
5edd87d
2830970
 
e97e778
2830970
5edd87d
e97e778
 
 
21e7265
 
 
 
 
 
e97e778
 
2830970
e97e778
21e7265
e97e778
2830970
 
e97e778
 
5edd87d
e97e778
5edd87d
 
e97e778
5edd87d
e97e778
5edd87d
 
e97e778
5edd87d
 
 
 
e97e778
 
5edd87d
 
e97e778
 
 
2830970
21e7265
e97e778
2830970
5edd87d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2830970
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Highly Accurate Dichotomous Image Segmentation</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 1000px;
            margin: 0 auto;
            padding: 20px;
            line-height: 1.6;
        }
        h1 {
            color: #333;
            text-align: center;
        }
        .container {
            display: flex;
            flex-direction: column;
            gap: 20px;
        }
        .upload-section {
            border: 2px dashed #ccc;
            padding: 30px;
            text-align: center;
            border-radius: 8px;
            background: #f9f9f9;
        }
        .results {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 20px;
            margin-top: 30px;
        }
        .result-box {
            border: 1px solid #ddd;
            padding: 15px;
            border-radius: 5px;
            text-align: center;
        }
        .result-box h3 {
            margin-top: 0;
        }
        .result-img {
            max-width: 100%;
            height: auto;
            max-height: 300px;
            margin-bottom: 10px;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 12px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #45a049;
        }
        #loading {
            display: none;
            text-align: center;
            margin: 20px 0;
            font-size: 18px;
        }
        .error {
            color: #d32f2f;
            margin: 10px 0;
            text-align: center;
        }
        .download-btn {
            display: inline-block;
            background: #2196F3;
            color: white;
            padding: 8px 15px;
            text-decoration: none;
            border-radius: 4px;
            margin-top: 5px;
        }
        .download-btn:hover {
            background: #0b7dda;
        }
        .info {
            background-color: #f8f9fa;
            padding: 20px;
            border-radius: 8px;
            margin-top: 30px;
        }
        .example-images {
            display: flex;
            gap: 15px;
            margin: 20px 0;
            justify-content: center;
        }
        .example-img {
            width: 150px;
            height: 150px;
            object-fit: cover;
            cursor: pointer;
            border: 2px solid transparent;
            border-radius: 4px;
        }
        .example-img:hover {
            border-color: #4CAF50;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Highly Accurate Dichotomous Image Segmentation</h1>
        
        <div class="upload-section">
            <h2>Upload Image</h2>
            <input type="file" id="imageInput" accept="image/*" style="display: none;">
            <button onclick="document.getElementById('imageInput').click()">Select Image</button>
            <p id="fileName" style="margin: 10px 0;"></p>
            <button onclick="processImage()">Remove Background</button>
            
            <div id="loading">Processing your image... Please wait...</div>
            <div id="error" class="error"></div>
            
            <div class="example-images">
                <img src="/examples/robot.png" class="example-img" onclick="loadExample('robot.png')" alt="Robot Example">
                <img src="/examples/ship.png" class="example-img" onclick="loadExample('ship.png')" alt="Ship Example">
            </div>
        </div>
        
        <div id="resultsContainer" style="display: none;">
            <h2 style="text-align: center;">Results</h2>
            <div class="results" id="results">
                <!-- Results will be inserted here -->
            </div>
        </div>
        
        <div class="info">
            <h3>About this service</h3>
            <p>This is an implementation of DIS, a model that can remove the background from a given image with high accuracy.</p>
            <p>GitHub: <a href="https://github.com/xuebinqin/DIS" target="_blank">https://github.com/xuebinqin/DIS</a></p>
            <p>Telegram bot: <a href="https://t.me/restoration_photo_bot" target="_blank">https://t.me/restoration_photo_bot</a></p>
            <div style="text-align: center; margin-top: 15px;">
                <img src="https://visitor-badge.glitch.me/badge?page_id=dis_image_segmentation" alt="visitor badge">
            </div>
        </div>
    </div>

    <script>
        // Update file name display
        document.getElementById('imageInput').addEventListener('change', function(e) {
            const fileName = e.target.files[0] ? e.target.files[0].name : 'No file selected';
            document.getElementById('fileName').textContent = `Selected: ${fileName}`;
            document.getElementById('error').textContent = '';
            document.getElementById('resultsContainer').style.display = 'none';
        });

        // Process image
        function processImage() {
            const fileInput = document.getElementById('imageInput');
            const file = fileInput.files[0];
            const errorDiv = document.getElementById('error');
            errorDiv.textContent = '';
            
            if (!file) {
                errorDiv.textContent = 'Please select an image first';
                return;
            }
            
            const loading = document.getElementById('loading');
            const resultsContainer = document.getElementById('resultsContainer');
            loading.style.display = 'block';
            resultsContainer.style.display = 'none';
            
            const formData = new FormData();
            formData.append('image', file);
            
            fetch('/api/process', {
                method: 'POST',
                body: formData
            })
            .then(response => {
                if (!response.ok) {
                    return response.json().then(err => { throw err; });
                }
                return response.json();
            })
            .then(data => {
                loading.style.display = 'none';
                
                if (data.error) {
                    errorDiv.textContent = 'Error: ' + data.error;
                    return;
                }
                
                const resultsDiv = document.getElementById('results');
                resultsDiv.innerHTML = `
                    <div class="result-box">
                        <h3>Original Image</h3>
                        <img src="${data.original}" class="result-img" alt="Original Image">
                        <a href="${data.original}" class="download-btn" download="${data.filename}">Download</a>
                    </div>
                    <div class="result-box">
                        <h3>Background Removed</h3>
                        <img src="${data.rgba}" class="result-img" alt="Background Removed">
                        <a href="${data.rgba}" class="download-btn" download="no_bg_${data.filename}">Download</a>
                    </div>
                    <div class="result-box">
                        <h3>Segmentation Mask</h3>
                        <img src="${data.mask}" class="result-img" alt="Segmentation Mask">
                        <a href="${data.mask}" class="download-btn" download="mask_${data.filename}">Download</a>
                    </div>
                `;
                
                resultsContainer.style.display = 'block';
            })
            .catch(error => {
                loading.style.display = 'none';
                console.error('Error:', error);
                errorDiv.textContent = error.error || 'An error occurred while processing the image';
            });
        }

        // Load example image
        function loadExample(filename) {
            fetch(`/examples/${filename}`)
                .then(response => response.blob())
                .then(blob => {
                    const file = new File([blob], filename, { type: blob.type });
                    const dataTransfer = new DataTransfer();
                    dataTransfer.items.add(file);
                    document.getElementById('imageInput').files = dataTransfer.files;
                    
                    // Trigger file name display
                    const event = new Event('change');
                    document.getElementById('imageInput').dispatchEvent(event);
                    
                    // Process the example immediately
                    processImage();
                })
                .catch(error => {
                    console.error('Error loading example:', error);
                    document.getElementById('error').textContent = 'Failed to load example image';
                });
        }
    </script>
</body>
</html>