upload exercises
This commit is contained in:
parent
32ad3f2662
commit
d17339a560
75 changed files with 773 additions and 0 deletions
27
Exercise2c/OUTDATED_process_image.py
Executable file
27
Exercise2c/OUTDATED_process_image.py
Executable file
|
@ -0,0 +1,27 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
# This module provides the magic_signature() function, safely and
|
||||
# securely calculated to provide invaluable signature of an image.
|
||||
|
||||
def magic(fname):
|
||||
n_threads = os.getenv('OMP_NUM_THREADS', '(unset)')
|
||||
print(f"Worker {fname=} OMP_NUM_THREADS={n_threads}")
|
||||
|
||||
# We delay the import of numpy because we want to set OMP_NUM_THREADS.
|
||||
# We delay the import of PIL in case is uses numpy internally.
|
||||
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
im = Image.open(fname)
|
||||
try:
|
||||
m = np.median(im, axis=2)
|
||||
except np.AxisError:
|
||||
return -1
|
||||
n = (m @ m.T).mean()
|
||||
return int(n)
|
||||
|
||||
if __name__ == '__main__':
|
||||
for fname in sys.argv[1:]:
|
||||
print(f'{fname} → {magic(fname)}')
|
Loading…
Add table
Add a link
Reference in a new issue