I can plot a histogram for RGB images but I want to plot it separately, one for the red value, one for the green, and one for the blue. How could I separate it?
What I have until now:
#tuple to select colors of each channel line
colors = ("red", "green", "blue")
channel_ids = (0, 1, 2)
# create the histogram plot, with three lines, one for
# each color
plt.xlim([0, 256])
for channel_id, c in zip(channel_ids, colors):
histogram, bin_edges = np.histogram(image[:, :, channel_id], bins=256, range=(0, 256))
plt.plot(bin_edges[0:-1], histogram, color=c)
plt.xlabel("Color value")
plt.ylabel("Pixels")
plt.show()
This is what I get:
EDIT: SOLVED
Quang Hoang warned me in comments, the "mistake" to reach my goal was to simply plot inside the loop, so it shows for each value.
Now I got:
#tuple to select colors of each channel line
colors = ("red", "green", "blue")
channel_ids = (0, 1, 2)
# create the histogram plot, with three lines, one for
# each color
plt.xlim([0, 256])
for channel_id, c in zip(channel_ids, colors):
histogram, bin_edges = np.histogram(image[:, :, channel_id], bins=256, range=(0, 256))
plt.plot(bin_edges[0:-1], histogram, color=c)
plt.xlabel("Color value")
plt.ylabel("Pixels")
plt.show()
Finally: