I would like to take a colour image and convert it to a binary image where what was close to either black or white return False, and all the intermediate values return True.
What is the proper syntax to impose the two conditions below simultaneously?
binary = color.rgb2gray(img) > 0.05
binary = color.rgb2gray(img) < 0.95
If I used this:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from skimage import color
import requests
from PIL import Image
from StringIO import StringIO
url = 'https://mycarta.files.wordpress.com/2014/03/spectrogram_jet.png'
r = requests.get(url)
img = np.asarray(Image.open(StringIO(r.content)).convert('RGB'))
and then:
binary = color.rgb2gray(img) < 0.95
I would get a proper binary image that I can plot with:
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111)
plt.imshow(binary, cmap='gray')
ax.xaxis.set_ticks([])
ax.yaxis.set_ticks([])
plt.show()
Similarly with this:
color.rgb2gray(img) < 0.95
But if I tried them together like this:
binary = color.rgb2gray(img) > 0.05 and color.rgb2gray(img) < 0.95
I got this message:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()