Browse Source

fixed issue with the border tiles, when tile width != tile height

pull/673/head
popow 8 years ago
parent
commit
f72908f7a8
  1. 14
      src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistEqualizationProcessor.cs
  2. 4
      src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistEqualizationSWProcessor.cs
  3. 2
      src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationMethod.cs
  4. 10
      src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationOptions.cs

14
src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistEqualizationProcessor.cs

@ -100,25 +100,27 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
this.ProcessBorderColumn(source, pixels, cdfData, 0, tileWidth, tileHeight, xStart: 0, xEnd: halfTileWidth);
// fix right column
this.ProcessBorderColumn(source, pixels, cdfData, this.Tiles - 1, tileWidth, tileHeight, xStart: source.Width - halfTileWidth, xEnd: source.Width);
int rightBorderStartX = ((this.Tiles - 1) * tileWidth) + halfTileWidth;
this.ProcessBorderColumn(source, pixels, cdfData, this.Tiles - 1, tileWidth, tileHeight, xStart: rightBorderStartX, xEnd: source.Width);
// fix top row
this.ProcessBorderRow(source, pixels, cdfData, 0, tileWidth, tileHeight, yStart: 0, yEnd: halfTileHeight);
// fix bottom row
this.ProcessBorderRow(source, pixels, cdfData, this.Tiles - 1, tileWidth, tileHeight, yStart: source.Height - halfTileHeight, yEnd: source.Height);
int bottomBorderStartY = ((this.Tiles - 1) * tileHeight) + halfTileHeight;
this.ProcessBorderRow(source, pixels, cdfData, this.Tiles - 1, tileWidth, tileHeight, yStart: bottomBorderStartY, yEnd: source.Height);
// left top corner
this.ProcessCornerTile(source, pixels, cdfData[0, 0], xStart: 0, xEnd: halfTileWidth, yStart: 0, yEnd: halfTileHeight, pixelsInTile: pixelsInTile);
// left bottom corner
this.ProcessCornerTile(source, pixels, cdfData[0, this.Tiles - 1], xStart: 0, xEnd: halfTileWidth, yStart: source.Height - halfTileHeight, yEnd: source.Height, pixelsInTile: pixelsInTile);
this.ProcessCornerTile(source, pixels, cdfData[0, this.Tiles - 1], xStart: 0, xEnd: halfTileWidth, yStart: bottomBorderStartY, yEnd: source.Height, pixelsInTile: pixelsInTile);
// right top corner
this.ProcessCornerTile(source, pixels, cdfData[this.Tiles - 1, 0], xStart: source.Width - halfTileWidth, xEnd: source.Width, yStart: 0, yEnd: halfTileHeight, pixelsInTile: pixelsInTile);
this.ProcessCornerTile(source, pixels, cdfData[this.Tiles - 1, 0], xStart: rightBorderStartX, xEnd: source.Width, yStart: 0, yEnd: halfTileHeight, pixelsInTile: pixelsInTile);
// right bottom corner
this.ProcessCornerTile(source, pixels, cdfData[this.Tiles - 1, this.Tiles - 1], xStart: source.Width - halfTileWidth, xEnd: source.Width, yStart: source.Height - halfTileHeight, yEnd: source.Height, pixelsInTile: pixelsInTile);
this.ProcessCornerTile(source, pixels, cdfData[this.Tiles - 1, this.Tiles - 1], xStart: rightBorderStartX, xEnd: source.Width, yStart: bottomBorderStartY, yEnd: source.Height, pixelsInTile: pixelsInTile);
}
/// <summary>
@ -162,7 +164,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
int pixelsInTile = tileWidth * tileHeight;
int cdfY = 0;
for (int y = halfTileWidth; y < source.Height - halfTileWidth; y += tileHeight)
for (int y = halfTileHeight; y < source.Height - halfTileHeight; y += tileHeight)
{
int yLimit = Math.Min(y + tileHeight, source.Height - 1);
int tileY = 0;

4
src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistEqualizationSWProcessor.cs

@ -130,8 +130,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
/// <returns>A pixel row of the length of the tile width.</returns>
private Span<TPixel> GetPixelRow(ImageFrame<TPixel> source, Span<TPixel> rowPixels, int x, int y, int tileWidth)
{
rowPixels.Clear();
if (y < 0)
{
y = Math.Abs(y);
@ -145,6 +143,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
// Special cases for the left and the right border where GetPixelRowSpan can not be used
if (x < 0)
{
rowPixels.Clear();
int idx = 0;
for (int dx = x; dx < x + tileWidth; dx++)
{
@ -156,6 +155,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
}
else if (x + tileWidth > source.Width)
{
rowPixels.Clear();
int idx = 0;
for (int dx = x; dx < x + tileWidth; dx++)
{

2
src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationMethod.cs

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
AdaptiveTileInterpolation,
/// <summary>
/// Adaptive sliding window histogram equalization.
/// Adaptive histogram equalization using sliding window. Slower then the tile interpolation mode, but can yield to better results.
/// </summary>
AdaptiveSlidingWindow,
}

10
src/ImageSharp/Processing/Processors/Normalization/HistogramEqualizationOptions.cs

@ -20,19 +20,19 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
public int LuminanceLevels { get; set; } = 256;
/// <summary>
/// Gets or sets a value indicating whether to clip the histogram bins at a specific value. Defaults to false.
/// Gets or sets a value indicating whether to clip the histogram bins at a specific value. Defaults to true.
/// </summary>
public bool ClipHistogram { get; set; } = false;
public bool ClipHistogram { get; set; } = true;
/// <summary>
/// Gets or sets the histogram clip limit in percent of the total pixels in the grid. Histogram bins which exceed this limit, will be capped at this value.
/// Gets or sets the histogram clip limit in percent of the total pixels in a tile. Histogram bins which exceed this limit, will be capped at this value.
/// Defaults to 0.35.
/// </summary>
public float ClipLimitPercentage { get; set; } = 0.035f;
/// <summary>
/// Gets or sets the number of tiles the image is split into (horizontal and vertically) for the adaptive histogram equalization. Defaults to 8.
/// Gets or sets the number of tiles the image is split into (horizontal and vertically) for the adaptive histogram equalization. Defaults to 10.
/// </summary>
public int Tiles { get; set; } = 8;
public int Tiles { get; set; } = 10;
}
}

Loading…
Cancel
Save