Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -141,45 +141,6 @@ def create_gradient_vector_field(gx, gy, image_shape, step=20, reverse=False):
|
|
141 |
|
142 |
return vector_field
|
143 |
|
144 |
-
# def invert_gradient_vector_field(gx, gy, image_shape):
|
145 |
-
# """
|
146 |
-
# Invert the gradient vector field using a more accurate method.
|
147 |
-
#
|
148 |
-
# :param gx: X-component of the gradient
|
149 |
-
# :param gy: Y-component of the gradient
|
150 |
-
# :param image_shape: Shape of the original image (height, width)
|
151 |
-
# :return: Inverted gx and gy
|
152 |
-
# """
|
153 |
-
# rows, cols = image_shape
|
154 |
-
# y, x = np.mgrid[0:rows, 0:cols]
|
155 |
-
#
|
156 |
-
# # Calculate the new positions after applying the gradient
|
157 |
-
# new_x = x + gx
|
158 |
-
# new_y = y + gy
|
159 |
-
#
|
160 |
-
# # Create a mask for valid (non-NaN, non-infinite) values
|
161 |
-
# mask = np.isfinite(new_x) & np.isfinite(new_y)
|
162 |
-
#
|
163 |
-
# # Flatten and filter the arrays
|
164 |
-
# x_flat = x[mask]
|
165 |
-
# y_flat = y[mask]
|
166 |
-
# new_x_flat = new_x[mask]
|
167 |
-
# new_y_flat = new_y[mask]
|
168 |
-
#
|
169 |
-
# # Create the inverse mapping
|
170 |
-
# inv_x = interpolate.griddata((new_x_flat, new_y_flat), x_flat, (x, y), method='linear', fill_value=np.nan)
|
171 |
-
# inv_y = interpolate.griddata((new_x_flat, new_y_flat), y_flat, (x, y), method='linear', fill_value=np.nan)
|
172 |
-
#
|
173 |
-
# # Calculate the inverse gradient
|
174 |
-
# inv_gx = inv_x - x
|
175 |
-
# inv_gy = inv_y - y
|
176 |
-
#
|
177 |
-
# # Fill NaN values with zeros
|
178 |
-
# inv_gx = np.nan_to_num(inv_gx)
|
179 |
-
# inv_gy = np.nan_to_num(inv_gy)
|
180 |
-
#
|
181 |
-
# return -inv_gx, -inv_gy # Note the negation here
|
182 |
-
|
183 |
def apply_gradient_transform(image, gx, gy):
|
184 |
"""
|
185 |
Apply the gradient transformation to an image.
|
@@ -297,7 +258,9 @@ def predict_image(img, model, conf_threshold, iou_threshold):
|
|
297 |
return im
|
298 |
|
299 |
def transform_image(image, func_choice, randomization_check, radius, center_x, center_y, strength, reverse_gradient=True, spiral_frequency=1):
|
300 |
-
|
|
|
|
|
301 |
|
302 |
# Downsample large images
|
303 |
max_size = 640 # Increased from 512 to allow for more detail, decreased from 1024 to match YOLO model training.
|
@@ -424,7 +387,7 @@ def transform_image(image, func_choice, randomization_check, radius, center_x, c
|
|
424 |
vector_field = np.zeros_like(I)
|
425 |
inverted_vector_field = np.zeros_like(I)
|
426 |
|
427 |
-
result = Image.fromarray(transformed)
|
428 |
|
429 |
# categories = ['Distorted', 'Maze']
|
430 |
|
|
|
141 |
|
142 |
return vector_field
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
def apply_gradient_transform(image, gx, gy):
|
145 |
"""
|
146 |
Apply the gradient transformation to an image.
|
|
|
258 |
return im
|
259 |
|
260 |
def transform_image(image, func_choice, randomization_check, radius, center_x, center_y, strength, reverse_gradient=True, spiral_frequency=1):
|
261 |
+
with Image.open(image) as img:
|
262 |
+
img = img.convert('RGB')
|
263 |
+
I = np.array(img)
|
264 |
|
265 |
# Downsample large images
|
266 |
max_size = 640 # Increased from 512 to allow for more detail, decreased from 1024 to match YOLO model training.
|
|
|
387 |
vector_field = np.zeros_like(I)
|
388 |
inverted_vector_field = np.zeros_like(I)
|
389 |
|
390 |
+
result = Image.fromarray(transformed.astype('uint8'), 'RGB')
|
391 |
|
392 |
# categories = ['Distorted', 'Maze']
|
393 |
|