-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#28 adding numpy support example scripts
- Loading branch information
1 parent
19d86a6
commit f5227e1
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import gmic | ||
import PIL | ||
import PIL.Image | ||
import numpy | ||
from numpy import asarray, array_equal | ||
from matplotlib import pyplot | ||
|
||
l = [] | ||
gmic.run("sp duck", l) | ||
gmic.run("display", l) | ||
|
||
ll = l[0].to_numpy_array(interleave=True, astype=numpy.uint8, squeeze_shape=True) | ||
print(ll.shape) | ||
print(ll.dtype) | ||
|
||
pyplot.imshow(ll) | ||
pyplot.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# TEST 1: numpy(interleaved)->pyplot_display(interleaved)->gmic_from_nparray(deinterleaved)->gmic_display(deinterleaved) | ||
import gmic | ||
import PIL | ||
import PIL.Image | ||
import numpy | ||
from numpy import asarray, array_equal | ||
from matplotlib import pyplot | ||
|
||
gmic.run("sp duck output image.png") | ||
i = PIL.Image.open('image.png') # Lena sample | ||
ii = asarray(i) | ||
print(ii.shape) #(512, 512, 3) | ||
print(ii.dtype) #uint8 | ||
|
||
l = [] | ||
gmic.run("sp duck", l) | ||
ll = l[0].to_numpy_array(interleave=True, astype=numpy.uint8, squeeze_shape=True) | ||
array_equal(ll,ii) # True | ||
print(ll.shape) #(512, 512, 3) | ||
print(ll.dtype) #uint8 | ||
|
||
pyplot.imshow(ll) | ||
pyplot.show() # Lena in good colors, dimensions and orientation | ||
|
||
pyplot.imshow(ii) | ||
pyplot.show() # Lena in good colors, dimensions and orientation | ||
|
||
j = gmic.GmicImage.from_numpy_array(ll, deinterleave=True) | ||
gmic.run("display", j) # Lena in good colors, dimensions and orientation | ||
""" | ||
[gmic]-1./ Display image [0] = '[unnamed]', from point (256,256,0). | ||
[0] = '[unnamed]': | ||
size = (512,512,1,3) [3072 Kio of floats]. | ||
data = (225,225,223,223,225,225,225,223,225,223,223,223,(...),78,78,78,77,91,80,79,89,77,79,79,82). | ||
min = 8, max = 251, mean = 128.241, std = 58.9512, coords_min = (457,60,0,1), coords_max = (425,20,0,0). | ||
""" | ||
|
||
jj = gmic.GmicImage.from_numpy_array(ii, deinterleave=True) | ||
gmic.run("display", jj) # Lena in good colors, dimensions and orientation | ||
""" | ||
[gmic]-1./ Display image [0] = '[unnamed]', from point (256,256,0). | ||
[0] = '[unnamed]': | ||
size = (512,512,1,3) [3072 Kio of floats]. | ||
data = (225,225,223,223,225,225,225,223,225,223,223,223,(...),78,78,78,77,91,80,79,89,77,79,79,82). | ||
min = 8, max = 251, mean = 128.241, std = 58.9512, coords_min = (457,60,0,1), coords_max = (425,20,0,0). | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# TEST 2: numpy(deinterleaved)->gmic_from_nparray(deinterleaved)->gmic_display(deinterleaved) | ||
import gmic | ||
import PIL | ||
import PIL.Image | ||
from numpy import asarray, array_equal | ||
|
||
gmic.run("sp lena output image.png") | ||
i = PIL.Image.open('image.png') | ||
ii = asarray(i) | ||
print(ii.shape) # (512, 512, 3) | ||
print(ii.dtype) # uint8 | ||
|
||
l = [] | ||
gmic.run("sp lena", l) | ||
ll = l[0].to_numpy_array(interleave=False, astype=int, squeeze_shape=True) # default astype=float32, default squeeze_shape=True | ||
print(ll.shape) # (512, 512, 3) | ||
print(ll.dtype) # int64 | ||
array_equal(ll,ii) # False; uint8 vs. int64 match but deinterleave vs interleave unmatch | ||
|
||
j = gmic.GmicImage.from_numpy_array(ll, deinterleave=False) | ||
gmic.run("display", j) # Lena in good orientation, color, size | ||
""" | ||
[gmic]-1./ Display image [0] = '[unnamed]', from point (256,256,0). | ||
[0] = '[unnamed]': | ||
size = (512,512,1,3) [3072 Kio of floats]. | ||
data = (225,225,223,223,225,225,225,223,225,223,223,223,(...),78,78,78,77,91,80,79,89,77,79,79,82). | ||
min = 8, max = 251, mean = 128.241, std = 58.9512, coords_min = (457,60,0,1), coords_max = (425,20,0,0). | ||
""" | ||
|
||
jj = gmic.GmicImage.from_numpy_array(ii, deinterleave=True) | ||
gmic.run("display", jj) # Lena in good orientation, color, size | ||
""" | ||
[gmic]-1./ Display image [0] = '[unnamed]', from point (256,256,0). | ||
[0] = '[unnamed]': | ||
size = (512,512,1,3) [3072 Kio of floats]. | ||
data = (225,225,223,223,225,225,225,223,225,223,223,223,(...),78,78,78,77,91,80,79,89,77,79,79,82). | ||
min = 8, max = 251, mean = 128.241, std = 58.9512, coords_min = (457,60,0,1), coords_max = (425,20,0,0). | ||
""" |