'plot histogram after averaging images
I have the following code to average a set of images (say 100 images) and to plot the histogram of the averaged image (one image). I am not getting the histogram with this code. Could you please help me in this code.
# reading multiple images
S01=[i for i in glob.glob("C:/Users/experiment 1/S01/*.tif")]
# Averaging images
s=np.array([np.array(Image.open(fname)) for fname in
S01])
s_avg=np.array(np.mean(s,axis=(0)),dtype=np.uint16)
s_out=Image.fromarray(s_avg)
#plot histogram
plt.hist(s_out,bins=auto)
plt.show()
Solution 1:[1]
No need to convert s_avg to an Image, you can compute the histogram of the array using .ravel()
fnames = [i for i in glob.glob("C:/Users/experiment 1/S01/*.tif")]
s=np.array([np.array(Image.open(fname)) for fname in fnames])
s_avg=np.mean(s,axis=(0))
#plot histogram
plt.hist(s_avg.ravel(),bins=100)
plt.show()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | endive1783 |
