Reputation: 159
I have an array of a gray scale image
Array
sample of array like this;
array([[[142, 142, 142],
[143, 143, 143],
[142, 142, 142],
...,
[147, 147, 147],
[148, 148, 148],
[143, 143, 143]],
[[142, 142, 142],
[142, 142, 142],
[142, 142, 142],
...,
[148, 148, 148],
[150, 150, 150],
[147, 147, 147]],
And array type is
Array.dtype
dtype('uint8')
I want to plot 16, 32 and 64-bin-histograms of this array, anyone have an idea?
Upvotes: 1
Views: 1271
Reputation: 3763
I noticed that you have an RGB image (3 channels). You likely would want to visualize its histogram by each channel (red, green and blue).
You can easily achieve this by using pandas
. For example, given an RGB Image array img
with the same data structure as your variable Array
, you can plot the histogram for each channel by converting it to DataFrame
import pandas as pd
df = pd.DataFrame({
'red': img[...,0].ravel(),
'green': img[...,1].ravel(),
'blue': img[...,2].ravel()
})
And then plotting it using plot.hist
df.plot.hist(bins=n_bins, alpha=.3, xlim=[0,255], color=['red', 'green', 'blue'])
Where n_bins
is the number of bins.
For n_bins=16
For n_bins=32
For n_bins=64
Upvotes: 1