Browse Source

Use jagged instead of multidimensional array as suggested in #462.

Only create the kernels once in the filters.


Former-commit-id: 4df56763ba8b568b5880f85b2fe1147b39ecae4f
Former-commit-id: 609592f6cbd8bd084f05b3e510697edd204d2aec
Former-commit-id: 3f6ccfb3c69420d39b5bd62080e7be54fad17a97
pull/1/head
dirk 9 years ago
parent
commit
577ca7b436
  1. 28
      src/ImageProcessorCore/Samplers/Processors/Convolution/Convolution2DFilter.cs
  2. 4
      src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/EdgeDetector2DFilter.cs
  3. 24
      src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs
  4. 24
      src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/PrewittProcessor.cs
  5. 20
      src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs
  6. 24
      src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/ScharrProcessor.cs
  7. 24
      src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/SobelProcessor.cs

28
src/ImageProcessorCore/Samplers/Processors/Convolution/Convolution2DFilter.cs

@ -23,7 +23,7 @@ namespace ImageProcessorCore.Processors
/// </summary>
/// <param name="kernelX">The horizontal gradient operator.</param>
/// <param name="kernelY">The vertical gradient operator.</param>
public Convolution2DFilter(float[,] kernelX, float[,] kernelY)
public Convolution2DFilter(float[][] kernelX, float[][] kernelY)
{
this.KernelX = kernelX;
this.KernelY = kernelY;
@ -32,22 +32,20 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>
public float[,] KernelX { get; }
public float[][] KernelX { get; }
/// <summary>
/// Gets the vertical gradient operator.
/// </summary>
public float[,] KernelY { get; }
public float[][] KernelY { get; }
/// <inheritdoc/>
public override void Apply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY)
{
float[,] kernelX = this.KernelX;
float[,] kernelY = this.KernelY;
int kernelYHeight = kernelY.GetLength(0);
int kernelYWidth = kernelY.GetLength(1);
int kernelXHeight = kernelX.GetLength(0);
int kernelXWidth = kernelX.GetLength(1);
int kernelYHeight = KernelY.Length;
int kernelYWidth = KernelY[0].Length;
int kernelXHeight = KernelX.Length;
int kernelXWidth = KernelX[0].Length;
int radiusY = kernelYHeight >> 1;
int radiusX = kernelXWidth >> 1;
@ -100,16 +98,16 @@ namespace ImageProcessorCore.Processors
if (fy < kernelXHeight)
{
rX += kernelX[fy, fx] * r;
gX += kernelX[fy, fx] * g;
bX += kernelX[fy, fx] * b;
rX += KernelX[fy][fx] * r;
gX += KernelX[fy][fx] * g;
bX += KernelX[fy][fx] * b;
}
if (fx < kernelYWidth)
{
rY += kernelY[fy, fx] * r;
gY += kernelY[fy, fx] * g;
bY += kernelY[fy, fx] * b;
rY += KernelY[fy][fx] * r;
gY += KernelY[fy][fx] * g;
bY += KernelY[fy][fx] * b;
}
}
}

4
src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/EdgeDetector2DFilter.cs

@ -18,12 +18,12 @@ namespace ImageProcessorCore.Processors
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>
public abstract float[,] KernelX { get; }
public abstract float[][] KernelX { get; }
/// <summary>
/// Gets the vertical gradient operator.
/// </summary>
public abstract float[,] KernelY { get; }
public abstract float[][] KernelY { get; }
/// <inheritdoc/>
public bool Grayscale { get; set; }

24
src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/KayyaliProcessor.cs

@ -15,20 +15,24 @@ namespace ImageProcessorCore.Processors
where TColor : IPackedVector<TPacked>
where TPacked : struct
{
/// <inheritdoc/>
public override float[,] KernelX => new float[,]
private static readonly float[][] kernelX = new float[3][]
{
{ 6, 0, -6 },
{ 0, 0, 0 },
{ -6, 0, 6 }
new float[] { 6, 0, -6 },
new float[] { 0, 0, 0 },
new float[] { -6, 0, 6 }
};
/// <inheritdoc/>
public override float[,] KernelY => new float[,]
private static readonly float[][] kernelY = new float[3][]
{
{ -6, 0, 6 },
{ 0, 0, 0 },
{ 6, 0, -6 }
new float[] { -6, 0, 6 },
new float[] { 0, 0, 0 },
new float[] { 6, 0, -6 }
};
/// <inheritdoc/>
public override float[][] KernelX => kernelX;
/// <inheritdoc/>
public override float[][] KernelY => kernelY;
}
}

24
src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/PrewittProcessor.cs

@ -15,20 +15,24 @@ namespace ImageProcessorCore.Processors
where TColor : IPackedVector<TPacked>
where TPacked : struct
{
/// <inheritdoc/>
public override float[,] KernelX => new float[,]
private static readonly float[][] kernelX = new float[3][]
{
{ -1, 0, 1 },
{ -1, 0, 1 },
{ -1, 0, 1 }
new float[] { -1, 0, 1 },
new float[] { -1, 0, 1 },
new float[] { -1, 0, 1 }
};
/// <inheritdoc/>
public override float[,] KernelY => new float[,]
private static readonly float[][] kernelY = new float[3][]
{
{ 1, 1, 1 },
{ 0, 0, 0 },
{ -1, -1, -1 }
new float[] { 1, 1, 1 },
new float[] { 0, 0, 0 },
new float[] { -1, -1, -1 }
};
/// <inheritdoc/>
public override float[][] KernelX => kernelX;
/// <inheritdoc/>
public override float[][] KernelY => kernelY;
}
}

20
src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/RobertsCrossProcessor.cs

@ -15,18 +15,22 @@ namespace ImageProcessorCore.Processors
where TColor : IPackedVector<TPacked>
where TPacked : struct
{
/// <inheritdoc/>
public override float[,] KernelX => new float[,]
private static readonly float[][] kernelX = new float[2][]
{
{ 1, 0 },
{ 0, -1 }
new float[] { 1, 0 },
new float[] { 0, -1 }
};
/// <inheritdoc/>
public override float[,] KernelY => new float[,]
private static readonly float[][] kernelY = new float[2][]
{
{ 0, 1 },
{ -1, 0 }
new float[] { 0, 1 },
new float[] { -1, 0 }
};
/// <inheritdoc/>
public override float[][] KernelX => kernelX;
/// <inheritdoc/>
public override float[][] KernelY => kernelY;
}
}

24
src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/ScharrProcessor.cs

@ -15,20 +15,24 @@ namespace ImageProcessorCore.Processors
where TColor : IPackedVector<TPacked>
where TPacked : struct
{
/// <inheritdoc/>
public override float[,] KernelX => new float[,]
private static readonly float[][] kernelX = new float[3][]
{
{ -3, 0, 3 },
{ -10, 0, 10 },
{ -3, 0, 3 }
new float[] { -3, 0, 3 },
new float[] { -10, 0, 10 },
new float[] { -3, 0, 3 }
};
/// <inheritdoc/>
public override float[,] KernelY => new float[,]
private static readonly float[][] kernelY = new float[3][]
{
{ 3, 10, 3 },
{ 0, 0, 0 },
{ -3, -10, -3 }
new float[] { 3, 10, 3 },
new float[] { 0, 0, 0 },
new float[] { -3, -10, -3 }
};
/// <inheritdoc/>
public override float[][] KernelX => kernelX;
/// <inheritdoc/>
public override float[][] KernelY => kernelY;
}
}

24
src/ImageProcessorCore/Samplers/Processors/Convolution/EdgeDetection/SobelProcessor.cs

@ -15,20 +15,24 @@ namespace ImageProcessorCore.Processors
where TColor : IPackedVector<TPacked>
where TPacked : struct
{
/// <inheritdoc/>
public override float[,] KernelX => new float[,]
private static readonly float[][] kernelX = new float[3][]
{
{ -1, 0, 1 },
{ -2, 0, 2 },
{ -1, 0, 1 }
new float[] { -1, 0, 1 },
new float[] { -2, 0, 2 },
new float[] { -1, 0, 1 }
};
/// <inheritdoc/>
public override float[,] KernelY => new float[,]
private static readonly float[][] kernelY = new float[3][]
{
{ -1, -2, -1 },
{ 0, 0, 0 },
{ 1, 2, 1 }
new float[] { -1, -2, -1 },
new float[] { 0, 0, 0 },
new float[] { 1, 2, 1 }
};
/// <inheritdoc/>
public override float[][] KernelX => kernelX;
/// <inheritdoc/>
public override float[][] KernelY => kernelY;
}
}

Loading…
Cancel
Save