我想评估一下寻找“正确”旋转文件的想法。想法是应用边缘检测器并计算每行和每列的白色值。为了对其进行评估,我想在图像旁边绘制此计数(或具有小bin大小的直方图)。我怎样才能做到这一点?
#!/usr/bin/env python
import scipy.misc
import numpy as np
import scipy.ndimage
import seaborn as sns
im = scipy.misc.imread("morc-0102.jpg", mode="L")
height, width = im.shape
k = np.array([[1, -1],
[1, -1]])
im = scipy.ndimage.convolve(im, k, mode='constant', cval=0.0)
# Calculate histogram
hist_height = np.zeros(height)
hist_width = np.zeros(width)
for y in range(height):
for x in range(width):
hist_height[y] += im[y][x]
hist_width[x] += im[y][x]
sns.distplot(hist_height, kde=False, rug=False)
sns.distplot(hist_width, kde=False, rug=False)
sns.plt.show()
scipy.misc.imshow(im)
与此类似的可视化效果:在图像的右侧hist_height
绘制了(标准化)计数,在底部绘制了(标准化)计数hist_width
。
我想我以前看过很相似的东西。我知道如何通过调整画布大小并“手动”绘制每行来手动执行此操作,但是我想像matplotlib / seaborn这样的库直接支持此操作吗?
如何将两个条形图添加为子图?像这样
import matplotlib.pyplot as plt
import numpy as np
# remove upper corner plot
ax1 = plt.subplot2grid((3, 3), (0, 2))
ax1.axis('off')
# plot some example image
imageExample = np.random.uniform(0,1,(5,5))
ax2 = plt.subplot2grid((3, 3), (1, 0), colspan=2, rowspan=2)
ax2.imshow(imageExample)
ax2.axis('off')
# use 'barh' for horizontal bar plot
horzSum = np.sum(imageExample,1)
ax3 = plt.subplot2grid((3, 3), (1, 2), rowspan=2, sharey=ax2)
ax3.barh(range(len(horzSum)), horzSum)
ax3.axis('off')
vertSum = np.sum(imageExample, 0)
ax4 = plt.subplot2grid((3, 3), (0, 0), colspan=2, sharex=ax2)
ax4.bar(range(len(vertSum)), vertSum)
ax4.axis('off')
plt.subplots_adjust(wspace=0, hspace=0)
plt.show()
设置width
的bar
和barh
为1,color='r'
你会得到非常相似,你的目标是什么,除了空白,或许您可以摆脱莫名其妙的东西。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句