关于图片分割和亮度识别的问题~!!!
如何用VB把一张二值化以后的图片分成若干区域,比如分成12*12个矩形,然后识别矩形中的亮度~ 白的多就变成白色,黑的多就变成黑色。 vb
[解决办法]
'假定 lWidth 和 lHeight 为图片大小
Dim xBlock As Long
Dim yBlock As Long
Dim x As Long
Dim y As Long
Dim lBlockWidth As Long
Dim lBlockHeight As Long
Dim lWhite As Long
For xBlock = 1 To lWidth Step 12
lBlockWidth = IIf(xBlock + 11 <= lWidth, 12, lWidth - xBlock + 1)
For yBlock = 1 To lHeight Step 12
lBlockHeight = IIf(yBlock + 11 <= lHeight, 12, lHeight - yBlock + 1)
lWhite = 0
For x = xBlock To xBlock + lBlockWidth - 1
For y = yBlock To yBlock + lBlockHeight - 1
lWhite = lWhite + IIf(像素(x, y) = 白色, 1, 0) '<-这里自己替换
Next
Next
Debug.Print "(" & xBlock & "," & yBlock & ")", _
lBlockWidth & "x" & lBlockHeight, _
IIf(lWhite >= (lBlockWidth * lBlockHeight / 2), "白", "黑")
Next
Next