Add multiple file code and images to use
Signed-off-by: Andy K <donfackandy@gmail.com>
This commit is contained in:
parent
f8e933cbdc
commit
1e3dd6bc32
BIN
imageEngine/gray_images/cute_gray.png
Normal file
BIN
imageEngine/gray_images/cute_gray.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 989 KiB |
BIN
imageEngine/gray_images/figure_2_gray.png
Normal file
BIN
imageEngine/gray_images/figure_2_gray.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 114 B |
1
imageEngine/image_python
Submodule
1
imageEngine/image_python
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit f8e933cbdc76fa3f329c2fdcb3dd5e9cacc23e23
|
BIN
imageEngine/image_test.jpg
Normal file
BIN
imageEngine/image_test.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 186 KiB |
BIN
imageEngine/images/figure_2.png
Normal file
BIN
imageEngine/images/figure_2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 98 B |
BIN
imageEngine/invert_images/invert_cute.png
Normal file
BIN
imageEngine/invert_images/invert_cute.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 MiB |
BIN
imageEngine/sobel/image_test.png
Normal file
BIN
imageEngine/sobel/image_test.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 392 KiB |
25
imageEngine/umage.py
Normal file
25
imageEngine/umage.py
Normal file
@ -0,0 +1,25 @@
|
||||
from PIL import Image
|
||||
import itertools
|
||||
|
||||
|
||||
def load(filename):
|
||||
""" Given a filename that matches an image file,
|
||||
return a list of lists of tuples corresponding to the list of
|
||||
lines of pixels (R, G, B) of the image. """
|
||||
|
||||
with Image.open(filename, 'r') as image:
|
||||
image = image.convert('RGB')
|
||||
content = list(image.getdata())
|
||||
size_x, size_y = image.size
|
||||
return [content[i:i + size_x] for i in range(0, len(content), size_x)]
|
||||
|
||||
|
||||
def save(image, filename='new', extension='jpg'):
|
||||
""" Stores the given image into a file. The name
|
||||
of the file is set to <filename>.<extension> which is
|
||||
'new.jpg' by default. """
|
||||
|
||||
size_x, size_y = len(image), len(image[0])
|
||||
new_image = Image.new('RGB', (size_y, size_x))
|
||||
new_image.putdata(list(itertools.chain.from_iterable(image)))
|
||||
new_image.save('%s.%s' % (filename, extension))
|
Loading…
Reference in New Issue
Block a user