ajustando ASP com Flask

This commit is contained in:
2023-09-24 10:56:01 -03:00
parent 125b456743
commit f0fa227035
10 changed files with 80 additions and 93 deletions

View File

@@ -1,30 +1,29 @@
from wand.image import Image
def box_blur_image_separable(image, blurred_image, radius_x, radius_y):
pixels = image.get_pixels()
blurred_pixels = blurred_image.get_pixels()
def box_blur_image_separable(image, radius_x, radius_y):
blurred_image = image.clone()
width, height = image.width, image.height
for pixel in pixels:
x, y = pixel[0], pixel[1]
for y in range(height):
for x in range(width):
blurred_image[x, y] = image[x, y]
r_total, g_total, b_total = 0, 0, 0
pixel_count = 0
for offset_y in range(-radius_y, radius_y + 1):
for offset_x in range(-radius_x, radius_x + 1):
new_x = x + offset_x
new_y = y + offset_y
r_total, g_total, b_total = 0, 0, 0
pixel_count = 0
for offset_y in range(-radius_y, radius_y + 1):
for offset_x in range(-radius_x, radius_x + 1):
new_x = x + offset_x
new_y = y + offset_y
if 0 <= new_x < image.width and 0 <= new_y < image.height:
pixel_color = pixels[new_y * image.width + new_x]
r_total += pixel_color.red
g_total += pixel_color.green
b_total += pixel_color.blue
pixel_count += 1
if 0 <= new_x < width and 0 <= new_y < height:
r_total += image[new_x, new_y].red_int8
g_total += image[new_x, new_y].green_int8
b_total += image[new_x, new_y].blue_int8
pixel_count += 1
blurred_pixel = blurred_pixels[y * image.width + x]
blurred_pixel.red = int(r_total / pixel_count)
blurred_pixel.green = int(g_total / pixel_count)
blurred_pixel.blue = int(b_total / pixel_count)
blurred_image[x, y].red_int8 = int(r_total / pixel_count)
blurred_image[x, y].green_int8 = int(g_total / pixel_count)
blurred_image[x, y].blue_int8 = int(b_total / pixel_count)
return blurred_image
@@ -34,10 +33,9 @@ class ImageService:
def box_blur_image(self, img, radius):
with Image(blob=img) as image:
blurred_image = image.clone()
image = box_blur_image_separable(image, blurred_image, radius, 0)
image = box_blur_image_separable(image, blurred_image, 0, radius)
return image
blurred_image = box_blur_image_separable(image, radius, 0)
blurred_image = box_blur_image_separable(blurred_image, 0, radius)
return blurred_image.make_blob()
def get_simple_image(self):
with open("./static/small-image.png", "rb") as file:
@@ -50,3 +48,6 @@ class ImageService:
def save_image(self, img):
with open("image.png", "wb") as file:
file.write(img)
return True