【发布时间】:2017-02-11 12:39:16
【问题描述】:
我正在尝试自动检测嘈杂图像矩阵中的矩形。这些值是二进制的,有任意数量的矩形,由于噪声,边缘可能有点模糊。我想最终得到矩形的坐标或其他一些这样的方法,让我可以专注于这些区域。
我一直在尝试使用 PET 包中的霍夫变换,但不明白如何解释输出。我对其他软件包或技术持开放态度。
library(PET)
AddRectangle<- function(df, startx, starty, cols, rows){
RectangleVector <- rep(1:cols, times = rows)
#Start Point
RectangleVector <- ncol(df)*(starty-1) + (startx-1) + RectangleVector
#Row changes
RectangleVector<- RectangleVector+ rep((0:(rows-1))*ncol(df), each = cols)
RectangleVector
}
#create matrix, this is an arbitrary example.
dfrows <- 100
dfcols <- 100
df <- matrix(0, nrow = dfrows, ncol = dfcols)
#put in rectangles
df[AddRectangle(df, startx = 3, starty = 3, cols = 10, rows =10)] <-1
df[AddRectangle(df, startx = 40, starty = 50, cols = 30, rows =20)] <-1
df[AddRectangle(df, startx = 45, starty = 10, cols = 30, rows =35)] <-1
df[AddRectangle(df, startx = 80, starty = 80, cols = 10, rows =10)] <-1
image(df,col = grey(seq(0, 1, length = 2)))
set.seed(2017)
#add in noise
noisydf<- df
#Positives
noisydf[runif(dfrows*dfcols)>0.97]<-1
#negatives
noisydf[runif(dfrows*dfcols)>0.97]<-0
#Visualise
image(noisydf,col = grey(seq(0, 1, length = 2)))
此代码创建以下图像。
使用宠物包我得到了一张非常漂亮的照片,但不知道如何处理它。我想得到的是矩形的坐标。我与霍夫变换无关,任何成功的方法都可以。
test <- hough(noisydf)
image(test$hData)
【问题讨论】:
-
请提供起始图片。
-
给出的代码生成显示的图像。我正在寻找一种在嘈杂的二进制矩阵中查找矩形的通用方法,因此没有特定的图像,也没有图像格式,因为我正在查看类矩阵的对象。您是否有理由专门要求图像?如果信息丢失,我将尝试澄清。我是图像处理的新手,如果我错过了有用的信息,我们深表歉意。
-
所以您想从显示的图像继续并找到矩形?如果是这样,我认为您需要
cv::connectedComponents,然后设置一个最小区域以排除小斑点。
标签: r opencv image-processing hough-transform