优化:修复Logger类型错误,重写CLAHE算法,像素遍历改用unsafe指针加速
This commit is contained in:
@@ -291,15 +291,23 @@ public class QfnLeadPadVoidProcessor : ImageProcessorBase
|
||||
|
||||
// 双阈值分割(X-Ray正片:焊点=暗区域,灰度在[threshLow, threshHigh]范围内判为焊点)
|
||||
var binary = new Image<Gray, byte>(w, h);
|
||||
byte[,,] srcData = blurred.Data;
|
||||
byte[,,] dstData = binary.Data;
|
||||
|
||||
for (int y = 0; y < h; y++)
|
||||
unsafe
|
||||
{
|
||||
for (int x = 0; x < w; x++)
|
||||
byte* srcPtr = (byte*)blurred.Mat.DataPointer;
|
||||
byte* dstPtr = (byte*)binary.Mat.DataPointer;
|
||||
int srcStep = blurred.Mat.Step;
|
||||
int dstStep = binary.Mat.Step;
|
||||
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
byte val = srcData[y, x, 0];
|
||||
dstData[y, x, 0] = (val >= threshLow && val <= threshHigh) ? (byte)255 : (byte)0;
|
||||
byte* srcRow = srcPtr + y * srcStep;
|
||||
byte* dstRow = dstPtr + y * dstStep;
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
byte val = srcRow[x];
|
||||
dstRow[x] = (val >= threshLow && val <= threshHigh) ? (byte)255 : (byte)0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,18 +418,28 @@ public class QfnLeadPadVoidProcessor : ImageProcessorBase
|
||||
|
||||
// 双阈值分割(正片模式:空洞=亮区域,灰度在[voidThreshLow, voidThreshHigh]范围内判为空洞)
|
||||
var voidImg = new Image<Gray, byte>(w, h);
|
||||
byte[,,] srcData = input.Data;
|
||||
byte[,,] dstData = voidImg.Data;
|
||||
byte[,,] maskData = mask.Data;
|
||||
|
||||
for (int y = 0; y < h; y++)
|
||||
unsafe
|
||||
{
|
||||
for (int x = 0; x < w; x++)
|
||||
byte* srcPtr = (byte*)input.Mat.DataPointer;
|
||||
byte* dstPtr = (byte*)voidImg.Mat.DataPointer;
|
||||
byte* mskPtr = (byte*)mask.Mat.DataPointer;
|
||||
int srcStep = input.Mat.Step;
|
||||
int dstStep = voidImg.Mat.Step;
|
||||
int mskStep = mask.Mat.Step;
|
||||
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
if (maskData[y, x, 0] > 0)
|
||||
byte* srcRow = srcPtr + y * srcStep;
|
||||
byte* dstRow = dstPtr + y * dstStep;
|
||||
byte* mskRow = mskPtr + y * mskStep;
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
byte val = srcData[y, x, 0];
|
||||
dstData[y, x, 0] = (val >= voidThreshLow && val <= voidThreshHigh) ? (byte)255 : (byte)0;
|
||||
if (mskRow[x] > 0)
|
||||
{
|
||||
byte val = srcRow[x];
|
||||
dstRow[x] = (val >= voidThreshLow && val <= voidThreshHigh) ? (byte)255 : (byte)0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user