【发布时间】:2013-01-10 09:11:05
【问题描述】:
我正在使用页面分割算法。代码的输出写入图像,每个区域的像素都分配了唯一的颜色。我想处理图像以找到区域的边界框。我需要找到所有颜色,然后找到该颜色的所有像素,然后找到它们的边界框。
以下是示例图片。
我目前从 R、G、B 通道的直方图开始。直方图告诉我数据位置。
img = Image.open(imgfilename)
img.load()
r,g,b = img.split()
ra,ga,ba = [ np.asarray(p,dtype="uint8") for p in (r,g,b) ]
rhist,edges = np.histogram(ra,bins=256)
ghist,edges = np.histogram(ga,bins=256)
bhist,edges = np.histogram(ba,bins=256)
print np.nonzero(rhist)
print np.nonzero(ghist)
print np.nonzero(bhist)
输出: (数组([ 0, 1, 128, 205, 255]),) (数组([ 0, 20, 128, 186, 255]),) (数组([ 0, 128, 147, 150, 255]),)
在这一点上我有点困惑。通过目测,我有颜色(0,0,0),(1,0,0),(0,20,0),(128,128,128)等。我应该如何将非零输出置换为 np.where() 的像素值?
我正在考虑将 3,row,col narray 展平为 24 位压缩 RGB 值 (r
【问题讨论】:
-
这么多令人难以置信的建议!
标签: python image-processing numpy