Commit f4b4b11a authored by Mario Andres Serruya's avatar Mario Andres Serruya
Browse files

Image successfully processed once retrieved from Redis cluster

parent 2c8e322c
No related merge requests found
Showing with 12 additions and 10 deletions
+12 -10
import os
import pickle
import skimage
import matplotlib.pyplot as plt
import numpy as np
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)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment