优化:修复Logger类型错误,重写CLAHE算法,像素遍历改用unsafe指针加速
This commit is contained in:
@@ -73,27 +73,30 @@ public class ThresholdProcessor : ImageProcessorBase
|
||||
|
||||
if (useOtsu)
|
||||
{
|
||||
// 使用Otsu算法
|
||||
CvInvoke.Threshold(inputImage, result, minThreshold, 255, ThresholdType.Otsu);
|
||||
_logger.Debug("Process: UseOtsu = true");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 双阈值分割:介于MinThreshold和MaxThreshold之间的为前景(255),其他为背景(0)
|
||||
byte[,,] inputData = inputImage.Data;
|
||||
byte[,,] outputData = result.Data;
|
||||
|
||||
int height = inputImage.Height;
|
||||
int width = inputImage.Width;
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
unsafe
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
byte* srcPtr = (byte*)inputImage.Mat.DataPointer;
|
||||
byte* dstPtr = (byte*)result.Mat.DataPointer;
|
||||
int srcStep = inputImage.Mat.Step;
|
||||
int dstStep = result.Mat.Step;
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
byte pixelValue = inputData[y, x, 0];
|
||||
outputData[y, x, 0] = (pixelValue >= minThreshold && pixelValue <= maxThreshold)
|
||||
? (byte)255
|
||||
: (byte)0;
|
||||
byte* srcRow = srcPtr + y * srcStep;
|
||||
byte* dstRow = dstPtr + y * dstStep;
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
byte val = srcRow[x];
|
||||
dstRow[x] = (val >= minThreshold && val <= maxThreshold) ? (byte)255 : (byte)0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user