Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
Open sidebar
Mario Andres Serruya
REDIS_TESTS
Commits
f4b4b11a
Commit
f4b4b11a
authored
4 years ago
by
Mario Andres Serruya
Browse files
Options
Download
Email Patches
Plain Diff
Image successfully processed once retrieved from Redis cluster
parent
2c8e322c
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/redis_cli.py
+12
-10
python/redis_cli.py
with
12 additions
and
10 deletions
+12
-10
python/redis_cli.py
+
12
-
10
View file @
f4b4b11a
import
os
import
pickle
import
skimage
import
matplotlib.pyplot
as
p
lt
import
numpy
as
n
p
from
skimage
import
io
,
filters
from
skimage.color
import
rgb2gray
from
rediscluster
import
RedisCluster
#https://pypi.org/project/redis-py-cluster/#files
...
...
@@ -11,12 +12,13 @@ from rediscluster import RedisCluster #https://pypi.org/project/redis-py-cluster
###########################################################################################
#Nodes conforming the cluster.
startup_nodes
=
[{
"host"
:
"compute-11-5"
,
"port"
:
"8000"
},{
"host"
:
"compute-11-8"
,
"port"
:
"8000"
},{
"host"
:
"compute-11-6"
,
"port"
:
"8000"
}]
startup_nodes
=
[{
"host"
:
"compute-11-5"
,
"port"
:
"8000"
},
{
"host"
:
"compute-11-8"
,
"port"
:
"8000"
},
{
"host"
:
"compute-11-6"
,
"port"
:
"8000"
}]
#DEPLOY the cluster:
#note: decode_responses must be set to True when used with python3.
#rc = RedisCluster(startup_nodes = startup_nodes, decode_responses = True)
rc
=
RedisCluster
(
startup_nodes
=
startup_nodes
,
decode_responses
=
False
)
#WRITE a key into the cluster: rc.set("foo", "bar")
#READ a key from the cluster: rc.get("foo")
...
...
@@ -30,12 +32,12 @@ filename = os.path.join('.', 'clouds.jpg')
clouds
=
io
.
imread
(
filename
)
#Turn it to grayscale.
clouds
=
rgb2gray
(
clouds
)
#Store the image in the Redis Cluster as bytes.
rc
.
set
(
"clouds"
,
pickle
.
dumps
(
clouds
))
#Retrieve the image from the redis cluster and reconvert it to ndarray.
clouds_from_redis
=
pickle
.
loads
(
rc
.
get
(
"clouds"
))
#Apply a simple threshold.
threshold
=
filters
.
threshold_otsu
(
clouds
)
image_thesholded
=
clouds
>
threshold
#Show.
#fig, ax = plt.subplots(1,2)
#ax[0].imshow(clouds, 'gray')
#ax[1].imshow(image_thesholded, 'gray')
threshold
=
filters
.
threshold_otsu
(
clouds_from_redis
)
image_thesholded
=
clouds_from_redis
>
threshold
#Save the files.
io
.
imsave
(
"clouds_test.png"
,
image_thesholded
)
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets