public BestMatch LocateTheBestAproximateMatchForGivenRootPixel(PixelLocation encoderPoint, PixelLocation rootPoint) { BestMatch bestMatch = new BestMatch(); int rowOffset = 0; var widthOfTheMatchInThePreviousRow = _width - 1 - encoderPoint.X; do { int colOffset = 0; var nextRootPoint = new PixelLocation(rootPoint.X, rootPoint.Y + rowOffset); if (IsPixelEncoded[nextRootPoint.Y, nextRootPoint.X] || nextRootPoint.Y >= encoderPoint.Y && nextRootPoint.X >= encoderPoint.X) { colOffset = CoverColumns(encoderPoint, colOffset, rowOffset, nextRootPoint, widthOfTheMatchInThePreviousRow); } widthOfTheMatchInThePreviousRow = colOffset; rowOffset++; var matchSize = widthOfTheMatchInThePreviousRow * rowOffset; var blockDimensions = new Dimension(widthOfTheMatchInThePreviousRow, rowOffset); var matchMse = GetMse(encoderPoint, rootPoint, blockDimensions); if (matchSize >= bestMatch.Size && matchMse <= Constants.MaxMse) { bestMatch.Height = rowOffset; bestMatch.Width = widthOfTheMatchInThePreviousRow; bestMatch.Size = matchSize; } } while (widthOfTheMatchInThePreviousRow != 0 && encoderPoint.Y + rowOffset != _height - 1); return(bestMatch); }
private int CoverColumns(PixelLocation encoderPoint, int colOffset, int rowOffset, PixelLocation nextRootPoint, int widthOfTheMatchInThePreviousRow) { do { var nextToBeEncoded = new PixelLocation(encoderPoint.X + colOffset, encoderPoint.Y + rowOffset); if (IsEdge(nextToBeEncoded.X, nextToBeEncoded.Y)) { break; } if (IsPixelEncoded[nextToBeEncoded.Y, nextToBeEncoded.X]) { colOffset++; } else { var pixelToBeEncoded = WorkImage[nextToBeEncoded.Y, nextToBeEncoded.X]; var possibleMatchPixel = WorkImage[nextRootPoint.Y, nextRootPoint.X]; if (Math.Abs(pixelToBeEncoded - possibleMatchPixel) <= Constants.Threshold) { colOffset++; } else { break; } } } while (colOffset != widthOfTheMatchInThePreviousRow); return(colOffset); }
public void LocateTheBestAproximateMatchForGivenRootPixelGivesTheExpectedBestMatch() { _gz2DlzEncoderFacade.InputFilePath = One3X4MatchBlockBmpPath; _gz2DlzEncoderFacade.AbstractPredictor = new ABasedPredictor(); _gz2DlzEncoderFacade.ImageReader = _bmpReader; _gz2DlzEncoderFacade.Archiver = new Paq6V2Archiver(); _encoder = new Gz2DlzEncoder(_gz2DlzEncoderFacade); var originalImage = _encoder.WorkImage; var width = originalImage.GetLength(0); for (int i = 0; i < width; i++) { _encoder.IsPixelEncoded[0, i] = true; _encoder.IsPixelEncoded[1, i] = true; _encoder.IsPixelEncoded[2, i] = true; _encoder.IsPixelEncoded[3, i] = true; _encoder.IsPixelEncoded[4, i] = true; } for (int i = 0; i < 5; i++) { _encoder.IsPixelEncoded[0, i] = true; } var encoderPosition = new PixelLocation(5, 5); var rootPosition = new PixelLocation(1, 1); BestMatch bestMatch = _encoder.LocateTheBestAproximateMatchForGivenRootPixel(encoderPosition, rootPosition); Assert.AreEqual(4, bestMatch.Height); Assert.AreEqual(4, bestMatch.Width); Assert.AreEqual(16, bestMatch.Size); }
private void EncodeWorkImage() { for (int y = 1; y < _height; y++) { for (int x = 0; x < _width; x++) { if (!IsPixelEncoded[y, x]) { var rootPoint = new PixelLocation(GetRootX(x), GetRootY(y)); var encoderPoint = new PixelLocation(x, y); var bestMatch = LocateTheBestAproximateMatchForGivenRootPixel(encoderPoint, rootPoint); if (bestMatch.Size > Constants.MinMatchSize) { IsMatchFound[y, x] = true; MatchDimension[y, x] = new Dimension(bestMatch.Width, bestMatch.Height); MatchLocation[y, x] = rootPoint; SetResidualAndIsPixelEncoded(x, y); } else { IsMatchFound[y, x] = false; PredictNoMatchBlock(x, y); x += Constants.NoMatchBlockWidth - 1; } } } } }
private void InstatiateTables() { IsMatchFound = new bool[_height, _width]; IsPixelEncoded = new bool[_height, _width]; MatchLocation = new PixelLocation[_height, _width]; MatchDimension = new Dimension[_height, _width]; Residual = new int[_height, _width]; WorkImage = new byte[_height, _width]; }
private int GetMse(PixelLocation encoderPoint, PixelLocation matchedPoint, Dimension blockDimension) { int sum = 0; for (int i = 0; i < blockDimension.Height; i++) { for (int j = 0; j < blockDimension.Width; j++) { var nextX = encoderPoint.X + j; if (nextX < _width) { sum += Convert.ToInt32(Math.Pow(WorkImage[encoderPoint.Y + i, nextX] - WorkImage[matchedPoint.Y + i, matchedPoint.X + j], 2)); } } } return(sum / blockDimension.Height * blockDimension.Width); }
public PixelLocation[,] GetMatchLocationFromString(string[] values) { var i = 2 + _dimension.Height * _dimension.Width; PixelLocation[,] matrix = new PixelLocation[_dimension.Height, _dimension.Width]; for (int y = 0; y < _dimension.Height; y++) { for (int x = 0; x < _dimension.Width; x++) { var valueX = Convert.ToInt32(values[i++]); var valueY = Convert.ToInt32(values[i++]); matrix[y, x] = new PixelLocation(valueX, valueY); } } return(matrix); }
private PixelLocation[,] LoadMatchLocationFromFileAndSetWidthAndHeight(string outputFileName) { using (BitReader bitReader = new BitReader(outputFileName)) { _width = Convert.ToInt32(bitReader.ReadNBits(Constants.NumberOfBitsForSize)); _height = Convert.ToInt32(bitReader.ReadNBits(Constants.NumberOfBitsForSize)); var matrix = new PixelLocation[_height, _width]; for (int y = 0; y < _height; y++) { for (int x = 0; x < _width; x++) { var xValue = bitReader.ReadNBits(Constants.NumberOfBitsForX); var yValue = bitReader.ReadNBits(Constants.NumberOfBitsForX); matrix[y, x] = new PixelLocation(Convert.ToInt32(xValue), Convert.ToInt32(yValue)); } } return(matrix); } }
public void AddToPixelLocations(PixelLocation pixelLocation) { base.AddObject("PixelLocations", pixelLocation); }
public static PixelLocation CreatePixelLocation(int ID, int vertex_ID) { PixelLocation pixelLocation = new PixelLocation(); pixelLocation.ID = ID; pixelLocation.Vertex_ID = vertex_ID; return pixelLocation; }
public PixelLine(int startX, int startY, int endX, int endY) { Start = new PixelLocation(startX, startY); End = new PixelLocation(endX, endY); }