How can I see the RGB channels of a given image with python?
<p>Imagine a I have an image and I want to split it and see the RGB channels. How can I do it using python?</p>

<p>My favorite approach is using <a href="http://scikit-image.org/" rel="nofollow">scikit-image</a>. It is built on top of numpy/scipy and images are internally stored within numpy-arrays.</p>

<p>Your question is a bit vague, so it's hard to answer. I don't know exactly what you want to do but will show you some code.</p>

<h3>Test-image:</h3>

<p>I will use <a href="http://www.colorwiki.com/images/0/0a/Photodisc.png" rel="nofollow">this test image</a>.</p>

<h3>Code:</h3>

<pre><code>import skimage.io as io
import matplotlib.pyplot as plt

# Read
img = io.imread('Photodisc.png')

# Split
red = img[:, :, 0]
green = img[:, :, 1]
blue = img[:, :, 2]

# Plot
fig, axs = plt.subplots(2,2)

cax_00 = axs[0,0].imshow(img)
axs[0,0].xaxis.set_major_formatter(plt.NullFormatter())  # kill xlabels
axs[0,0].yaxis.set_major_formatter(plt.NullFormatter())  # kill ylabels

cax_01 = axs[0,1].imshow(red, cmap='Reds')
fig.colorbar(cax_01, ax=axs[0,1])
axs[0,1].xaxis.set_major_formatter(plt.NullFormatter())
axs[0,1].yaxis.set_major_formatter(plt.NullFormatter())

cax_10 = axs[1,0].imshow(green, cmap='Greens')
fig.colorbar(cax_10, ax=axs[1,0])
axs[1,0].xaxis.set_major_formatter(plt.NullFormatter())
axs[1,0].yaxis.set_major_formatter(plt.NullFormatter())

cax_11 = axs[1,1].imshow(blue, cmap='Blues')
fig.colorbar(cax_11, ax=axs[1,1])
axs[1,1].xaxis.set_major_formatter(plt.NullFormatter())
axs[1,1].yaxis.set_major_formatter(plt.NullFormatter())
plt.show()

# Plot histograms
fig, axs = plt.subplots(3, sharex=True, sharey=True)

axs[0].hist(red.ravel(), bins=10)
axs[0].set_title('Red')
axs[1].hist(green.ravel(), bins=10)
axs[1].set_title('Green')
axs[2].hist(blue.ravel(), bins=10)
axs[2].set_title('Blue')

plt.show()
</code></pre>

<h3>Output:</h3>

<p><a href="http://i.stack.imgur.com/QrsKN.png" rel="nofollow"><img src="http://i.stack.imgur.com/QrsKN.png" alt="enter image description here"></a></p>

<p><a href="http://i.stack.imgur.com/RgIW2.png" rel="nofollow"><img src="http://i.stack.imgur.com/RgIW2.png" alt="enter image description here"></a></p>

<h3>Comment</h3>

<ul>
<li>Output looks good: see for example the yellow flower, which has much green and red, but not much blue which is compatible with wikipedia's scheme from <a href="https://en.wikipedia.org/wiki/RGB_color_model" rel="nofollow">here</a>:</li>
</ul>

<p><a href="http://i.stack.imgur.com/afqqm.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/afqqm.jpg" alt="enter image description here"></a></p>

python image image-processing rgb