Skip to content

Commit

Permalink
Move write_array_to_image to utils.export
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisVincent committed Nov 6, 2022
1 parent e0ab826 commit bf7e670
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 20 additions & 0 deletions stimuli/utils/export.py
Expand Up @@ -2,6 +2,7 @@
from hashlib import md5

import numpy as np
from PIL import Image


def arrs_to_checksum(stim, keys=["img", "mask"]):
Expand All @@ -16,3 +17,22 @@ def to_json(stim, filename):
# stimulus-dict(s) as (pretty) JSON
with open(filename, "w", encoding="utf-8") as f:
json.dump(stim, f, ensure_ascii=False, indent=4)


def write_array_to_image(filename, arr):
"""
Save a 2D numpy array as a grayscale image file.
Parameters
----------
filename : str
full path to the file to be creaated.
arr : np.ndarray
2D numpy array
The data to be stored in the image. Values will be cropped to [0,255].
"""
if Image:
imsize = arr.shape
im = Image.new("L", (imsize[1], imsize[0]))
im.putdata(arr.flatten())
im.save(filename)
20 changes: 0 additions & 20 deletions stimuli/utils/utils.py
Expand Up @@ -4,26 +4,6 @@
"""
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image


def write_array_to_image(filename, arr):
"""
Save a 2D numpy array as a grayscale image file.
Parameters
----------
filename : str
full path to the file to be creaated.
arr : np.ndarray
2D numpy array
The data to be stored in the image. Values will be cropped to [0,255].
"""
if Image:
imsize = arr.shape
im = Image.new("L", (imsize[1], imsize[0]))
im.putdata(arr.flatten())
im.save(filename)


def degrees_to_pixels(degrees, ppd):
Expand Down

0 comments on commit bf7e670

Please sign in to comment.