Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Update image_processing.py
Browse files Browse the repository at this point in the history
  • Loading branch information
CreepyMemes authored Jan 25, 2023
1 parent 99deee1 commit 1f77386
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/utils/image_processing.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from PIL import Image
from PIL import Image, ImageEnhance

# Opens an image and converts to grayscale
# Opens an image, converts to grayscale and increases contrast
def open_image(file):
img = Image.open(file).convert('L')
img = ImageEnhance.Contrast(img).enhance(3)
return img

# Calculate height value to maintain the original aspect ratio
Expand Down Expand Up @@ -40,12 +41,11 @@ def get_row_height_map(row, average):
result = []
total = 0
for pixel in row:
total += pixel - average
total += pixel - average * 1.5
result.append(total)
return [ pixel - total/2 for pixel in result ]

# Converts a whole image into a height map
def get_height_map(pixels, cols, rows):
average = get_average(pixels, cols, rows)
return normalize( [ get_row_height_map(row, average) for row in pixels ] )

0 comments on commit 1f77386

Please sign in to comment.