vericudebuget commited on
Commit
1ad2c6c
·
verified ·
1 Parent(s): 536c11c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +28 -20
README.md CHANGED
@@ -110,8 +110,8 @@ def denoise_image(image_path, model_path, patch_size=256, num_threads=4, overlap
110
  pad_bottom = patch_size - (height % patch_size) if height % patch_size != 0 else 0
111
 
112
  # Add padding with reflection instead of zeros
113
- padded_width = width + pad_right + overlap
114
- padded_height = height + pad_bottom + overlap
115
 
116
  # Create padded image using reflection padding
117
  padded_image = Image.new("RGB", (padded_width, padded_height))
@@ -136,9 +136,9 @@ def denoise_image(image_path, model_path, patch_size=256, num_threads=4, overlap
136
  # Generate patches with positions
137
  patches = []
138
  positions = []
139
- for i in range(0, padded_height - patch_size + 1, patch_size - overlap):
140
- for j in range(0, padded_width - patch_size + 1, patch_size - overlap):
141
- patch = padded_image.crop((j, i, j + patch_size, i + patch_size))
142
  patches.append(patch)
143
  positions.append((i, j))
144
 
@@ -151,21 +151,25 @@ def denoise_image(image_path, model_path, patch_size=256, num_threads=4, overlap
151
  weight_map = np.zeros((padded_height, padded_width), dtype=np.float32)
152
 
153
  # Create smooth blending weights
154
- patch_weights = np.ones((patch_size, patch_size), dtype=np.float32)
155
- if overlap > 0:
156
- # Create smooth transition in overlap regions
157
- fade = np.cos(np.linspace(np.pi, 2*np.pi, overlap)) * 0.5 + 0.5
158
- patch_weights[:overlap, :] *= fade[:, np.newaxis]
159
- patch_weights[-overlap:, :] *= fade[::-1][:, np.newaxis]
160
- patch_weights[:, :overlap] *= fade[np.newaxis, :]
161
- patch_weights[:, -overlap:] *= fade[::-1][np.newaxis, :]
162
-
163
- # Blend patches
164
  for (i, j), denoised_patch in zip(positions, denoised_patches):
165
- denoised_image[i:i + patch_size, j:j + patch_size] += (
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  denoised_patch * patch_weights[:, :, np.newaxis]
167
  )
168
- weight_map[i:i + patch_size, j:j + patch_size] += patch_weights
169
 
170
  # Normalize by weights
171
  mask = weight_map > 0
@@ -177,12 +181,15 @@ def denoise_image(image_path, model_path, patch_size=256, num_threads=4, overlap
177
 
178
  # Save the result
179
  denoised_image_path = os.path.splitext(image_path)[0] + "_denoised.png"
 
 
180
  Image.fromarray(denoised_image).save(denoised_image_path)
181
 
182
  if __name__ == "__main__":
183
- image_path = r"path/to/image"
184
  model_path = r"path/to/model.pkl"
185
- denoise_image(image_path, model_path, num_threads=12 #Use the number of threads your processor has.)
 
186
  ```
187
 
188
 
@@ -230,4 +237,5 @@ Vericu de Buget
230
 
231
  ## Model Card Contact
232
 
233
 
 
110
  pad_bottom = patch_size - (height % patch_size) if height % patch_size != 0 else 0
111
 
112
  # Add padding with reflection instead of zeros
113
+ padded_width = width + pad_right
114
+ padded_height = height + pad_bottom
115
 
116
  # Create padded image using reflection padding
117
  padded_image = Image.new("RGB", (padded_width, padded_height))
 
136
  # Generate patches with positions
137
  patches = []
138
  positions = []
139
+ for i in range(0, padded_height, patch_size - overlap):
140
+ for j in range(0, padded_width, patch_size - overlap):
141
+ patch = padded_image.crop((j, i, min(j + patch_size, padded_width), min(i + patch_size, padded_height)))
142
  patches.append(patch)
143
  positions.append((i, j))
144
 
 
151
  weight_map = np.zeros((padded_height, padded_width), dtype=np.float32)
152
 
153
  # Create smooth blending weights
 
 
 
 
 
 
 
 
 
 
154
  for (i, j), denoised_patch in zip(positions, denoised_patches):
155
+ patch_height, patch_width, _ = denoised_patch.shape
156
+ patch_weights = np.ones((patch_height, patch_width), dtype=np.float32)
157
+ if i > 0:
158
+ patch_weights[:overlap, :] *= np.linspace(0, 1, overlap)[:, np.newaxis]
159
+ if j > 0:
160
+ patch_weights[:, :overlap] *= np.linspace(0, 1, overlap)[np.newaxis, :]
161
+ if i + patch_height < padded_height:
162
+ patch_weights[-overlap:, :] *= np.linspace(1, 0, overlap)[:, np.newaxis]
163
+ if j + patch_width < padded_width:
164
+ patch_weights[:, -overlap:] *= np.linspace(1, 0, overlap)[np.newaxis, :]
165
+
166
+ # Clip the patch values to prevent very bright pixels
167
+ denoised_patch = np.clip(denoised_patch, 0, 255)
168
+
169
+ denoised_image[i:i + patch_height, j:j + patch_width] += (
170
  denoised_patch * patch_weights[:, :, np.newaxis]
171
  )
172
+ weight_map[i:i + patch_height, j:j + patch_width] += patch_weights
173
 
174
  # Normalize by weights
175
  mask = weight_map > 0
 
181
 
182
  # Save the result
183
  denoised_image_path = os.path.splitext(image_path)[0] + "_denoised.png"
184
+ print(f"Saving denoised image to {denoised_image_path}")
185
+
186
  Image.fromarray(denoised_image).save(denoised_image_path)
187
 
188
  if __name__ == "__main__":
189
+ image_path = input("Enter the path of the image: ")
190
  model_path = r"path/to/model.pkl"
191
+ denoise_image(image_path, model_path, num_threads=12)
192
+ print("Denoising completed.") # Use the number of threads your processor has.)
193
  ```
194
 
195
 
 
237
 
238
  ## Model Card Contact
239
 
240
241
+ [ConvoLite](https://convolite.github.io/selector.html)