public void Render() { if (Disposed) { return; } if (_needUpdate) { lock (_updateLock) { _vertex?.DisposeAll(); _vertex = _chunkVertexArrayProvider.ToElementArray().GetHandle(); _chunkVertexArrayProvider = null; _needUpdate = false; } } lock (_renderLock) { if (_vertex == null || _shader == null) { return; } _textureDictionary.Bind(); _shader.Use(); _shader.Model = Matrix4.Identity; _shader.Projection = _projectionMatrix.GetMatrix(); _shader.View = _viewMatrix.GetMatrix(); _vertex.Bind(); _vertex.Render(); } }
protected override List <ImagePoint> GetPointsInternal() { var mat = provider.GetMatrix().data; List <ImagePoint> ans = new List <ImagePoint>(); for (int i = 1; i + 1 < mat.GetLength(0); i++) { for (int j = 1; j + 1 < mat.GetLength(1); j++) { double v = mat[i, j]; if (v >= threshold) { //System.Diagnostics.Trace.WriteLine($"pass threshold: {i},{j}"); if (v > mat[i - 1, j - 1] && v > mat[i - 1, j] && v > mat[i - 1, j + 1] && v > mat[i, j - 1] && v > mat[i, j + 1] && v > mat[i + 1, j - 1] && v > mat[i + 1, j] && v > mat[i + 1, j + 1]) { ans.Add(new ImagePoint(j, i, v)); } } } } ans.Sort(); return(ans); }
protected override MyImageD GetImageDInternal() { MyMatrix blue_mat = blue_channel.GetMatrix(), green_mat = green_channel.GetMatrix(), red_mat = red_channel.GetMatrix(), alpha_mat = alpha_channel.GetMatrix(); System.Diagnostics.Trace.Assert(Utils.AllTheSame(blue_mat.data.GetLength(0), green_mat.data.GetLength(0), red_mat.data.GetLength(0), alpha_mat.data.GetLength(0))); System.Diagnostics.Trace.Assert(Utils.AllTheSame(blue_mat.data.GetLength(1), green_mat.data.GetLength(1), red_mat.data.GetLength(1), alpha_mat.data.GetLength(1))); MyImageD ans = new MyImageD(blue_mat.data.GetLength(1), blue_mat.data.GetLength(0)); Parallel.For(0, ans.height, i => { for (int j = 0; j < ans.width; j++) { //bgra int k = i * ans.stride + j * 4; ans.data[k + 0] = blue_mat.data[i, j]; ans.data[k + 1] = green_mat.data[i, j]; ans.data[k + 2] = red_mat.data[i, j]; ans.data[k + 3] = alpha_mat.data[i, j]; } }); return(ans); }
public void Render() { var matrix = _viewMatrix.GetMatrix(); matrix.Column3 = Vector4.UnitW; _shader.Use(); _shader.View = matrix; _shader.Projection = _projectionMatrix.GetMatrix(); _vertexArray.Bind(); _vertexArray.Render(PrimitiveType.Lines); }
public void Render() { _shader.Use(); _shader.Color = Color; _shader.Model = Matrix4.CreateTranslation(Box.Min) * Matrix4.CreateScale(Box.Size); _shader.View = _viewMatrix.GetMatrix(); _shader.Projection = _projectionMatrix.GetMatrix(); _eah.Bind(); _eah.Render(OpenTK.Graphics.OpenGL4.PrimitiveType.Lines); }
protected override MyMatrix GetMatrixInternal() { double[,] data = (double[, ])provider.GetMatrix().data.Clone(); Parallel.For(0, data.GetLength(0), i => { for (int j = 0; j < data.GetLength(1); j++) { data[i, j] = Math.Max(mn, Math.Min(mx, data[i, j])); } }); return(new MyMatrix(data)); }
protected override MyMatrix GetMatrixInternal() { double[,] raw = provider.GetMatrix().data; double[,] data = new double[raw.GetLength(0), raw.GetLength(1)]; Parallel.For(0, data.GetLength(0), i => { int i1 = Math.Max(0, i - 1), i2 = Math.Min(data.GetLength(0) - 1, i + 1); for (int j = 0; j < data.GetLength(1); j++) { data[i, j] = raw[i2, j] - raw[i1, j]; } }); return(new MyMatrix(data)); }
protected override MyMatrix GetMatrixInternal() { double[,] data1 = provider1.GetMatrix().data; double[,] data2 = provider2.GetMatrix().data; System.Diagnostics.Trace.Assert(data1.GetLength(0) == data2.GetLength(0) && data1.GetLength(1) == data2.GetLength(1)); double[,] data = new double[data1.GetLength(0), data1.GetLength(1)]; Parallel.For(0, data.GetLength(0), i => { for (int j = 0; j < data.GetLength(1); j++) { data[i, j] = data1[i, j] * data2[i, j]; } }); return(new MyMatrix(data)); }
protected override MyMatrix GetMatrixInternal() { double[,] data = (double[, ])provider0.GetMatrix().data.Clone(); foreach (var provider in providers) { var addi = provider.GetMatrix().data; System.Diagnostics.Trace.Assert(addi.GetLength(0) == data.GetLength(0) && addi.GetLength(1) == data.GetLength(1)); Parallel.For(0, data.GetLength(0), i => { for (int j = 0; j < data.GetLength(1); j++) { data[i, j] += addi[i, j]; } }); } return(new MyMatrix(data)); }
protected override List<ImagePoint> GetPointsInternal() { double[,] data = mat_provider.GetMatrix().data; List<ImagePoint> points = points_provider.GetPoints(), ans = new List<ImagePoint>(); foreach(var p in points) { int x0 = (int)p.x, y0 = (int)p.y; int xn = Math.Max(0, x0 - 1), yn = Math.Max(0, y0 - 1); int xp = Math.Min(data.GetLength(1) - 1, x0 + 1), yp = Math.Min(data.GetLength(0) - 1, y0 + 1); double fnn = data[yn, xn], fn0 = data[y0, xn], fnp = data[yp, xn], f0n = data[yn, x0], f00 = data[y0, x0], f0p = data[yp, x0], fpn = data[yn, xp], fp0 = data[y0, xp], fpp = data[yp, xp]; double dfx = (fp0 - fn0) / 2, dfy = (f0p - f0n) / 2, dfxx = fp0 - 2 * f00 + fn0, dfyy = f0p - 2 * f00 + f0n, dfxy = (fnn - fnp - fpn + fpp) / 4; // -[[dfxx,dfxy],[dfxy,dfyy]]^-1[[dfx],[dfy]] double det = dfxx * dfyy - dfxy * dfxy; // -1/det[[dfyy,-dfxy],[-dfxy,dfxx]][[dfx],[dfy]] double dx = -(dfyy * dfx + (-dfxy) * dfy) / det, dy = -((-dfxy) * dfx + dfxx * dfy) / det; //if (Math.Sqrt(dx * dx + dy * dy) < 0.5) dx = dy = 0; double x = x0 + dx, y = y0 + dy; ans.Add(new ImagePoint(x, y, p.importance + dx * dfx + dy * dfy + 0.5 * (dx * dx * dfxx + 2 * dx * dy * dfxy + dy * dy * dfyy))); } return ans; }
protected override MyMatrix GetMatrixInternal() { double[,] data_xx = provider_xx.GetMatrix().data; double[,] data_xy = provider_xy.GetMatrix().data; double[,] data_yy = provider_yy.GetMatrix().data; System.Diagnostics.Trace.Assert(Utils.AllTheSame(data_xx.GetLength(0), data_xy.GetLength(0), data_yy.GetLength(0))); System.Diagnostics.Trace.Assert(Utils.AllTheSame(data_xx.GetLength(1), data_xy.GetLength(1), data_yy.GetLength(1))); double[,] data = new double[data_xx.GetLength(0), data_xx.GetLength(1)]; Parallel.For(0, data.GetLength(0), i => { for (int j = 0; j < data.GetLength(1); j++) { double a00 = data_xx[i, j], a01 = data_xy[i, j], a11 = data_yy[i, j]; // Harris //const double k = 0.04; //data[i, j] = (a00 * a11 - a01 * a01) - k * Math.Pow(a00 + a11, 2); // Harmonic mean data[i, j] = (a00 * a11 - a01 * a01) / (a00 + a11); } }); return(new MyMatrix(data)); }
protected override MyImageD GetImageDInternal() { return(provider.GetMatrix().ToHeatImageD(exp)); }
public CompressedImage Compress(Bitmap bmp) { if (bmp.PixelFormat != PixelFormat.Format24bppRgb) { throw new Exception($"{bmp.PixelFormat} pixel format is not supported, supported rgb24"); } var pixelsMatrix = _pixelsExtractor.Extract(bmp); var converterPixelsMatrix = MatrixRgbToYCbCrConveter.Convert(pixelsMatrix); var residueYPiece = bmp.Height % (_thinIndex * _dctSize); var residueXPiece = bmp.Width % (_thinIndex * _dctSize); var countAddYPiece = residueYPiece == 0 ? 0 : _thinIndex * _dctSize - residueYPiece; var countAddXPiece = residueXPiece == 0 ? 0 : _thinIndex * _dctSize - residueXPiece; var extendedPixelsMatrix = _matrixExtender.Extend(converterPixelsMatrix, countAddYPiece, countAddXPiece); var yCbCrchannels = _channelExtractor.Extract(extendedPixelsMatrix); var thinnedCbChannel = _matrixThinner.Thin(yCbCrchannels.CbChannel, _thinIndex); var thinnedCrChannel = _matrixThinner.Thin(yCbCrchannels.CrChannel, _thinIndex); var dctYPieces = _dctCompressor.Compress(yCbCrchannels.YChannel, _dctSize, _compressionLevel, _lumiaMatrixProvider.GetMatrix()); var dctCbPieces = _dctCompressor.Compress(thinnedCbChannel, _dctSize, _compressionLevel, _colorMatrixProvider.GetMatrix()); var dctCrPieces = _dctCompressor.Compress(thinnedCrChannel, _dctSize, _compressionLevel, _colorMatrixProvider.GetMatrix()); var result = new List <byte>(); var countYBlocksPerColorBlock = _thinIndex * _thinIndex; for (int i = 0, thinI = 0; i < dctYPieces.Length; thinI++) { for (var j = 0; j < countYBlocksPerColorBlock; j++) { result.AddRange(dctYPieces[i++]); } result.AddRange(dctCbPieces[thinI]); result.AddRange(dctCrPieces[thinI]); } var rle = Rle <byte> .Encode(result).ToArray(); Dictionary <BitsWithLength, byte> decodeTable; long bitsCount; var huf = HuffmanCodec.Encode(rle, out decodeTable, out bitsCount); var compressedImage = new CompressedImage { ThinIndex = _thinIndex, CompressionLevel = _compressionLevel, DataBytes = huf, Height = extendedPixelsMatrix.GetLength(0), Width = extendedPixelsMatrix.GetLength(1), DecodeTable = decodeTable, BitsCount = bitsCount }; return(compressedImage); }
public Bitmap Decompress(CompressedImage compressedImage) { var unHuf = HuffmanCodec.Decode(compressedImage.DataBytes, compressedImage.DecodeTable, compressedImage.BitsCount); var unRle = Rle <byte> .Decode(unHuf).ToArray(); var yDct = new List <double>(); var cbDct = new List <double>(); var crDct = new List <double>(); var countYBlocks = compressedImage.ThinIndex * compressedImage.ThinIndex; var cellsToBlock = compressedImage.CompressionLevel; for (var i = 0; i < unRle.Length;) { for (var j = 0; j < countYBlocks * cellsToBlock; j++) { yDct.Add(unRle[i++]); } for (var j = 0; j < cellsToBlock; j++) { cbDct.Add(unRle[i++]); } for (var j = 0; j < cellsToBlock; j++) { crDct.Add(unRle[i++]); } } var yDctBlocks = DevideIntoPiece(yDct, compressedImage.CompressionLevel); var cbDctBlocks = DevideIntoPiece(cbDct, compressedImage.CompressionLevel); var crDctBlocks = DevideIntoPiece(crDct, compressedImage.CompressionLevel); var yChannel = _dctDecompressor.Decompress(yDctBlocks, _dctSize, compressedImage.Height, compressedImage.Width, _lumiaMatrixProvider.GetMatrix()); var thinnedCbChannel = _dctDecompressor.Decompress(cbDctBlocks, _dctSize, compressedImage.Height / compressedImage.ThinIndex, compressedImage.Width / compressedImage.ThinIndex, _colorMatrixProvider.GetMatrix()); var thinnedCrChannel = _dctDecompressor.Decompress(crDctBlocks, _dctSize, compressedImage.Height / compressedImage.ThinIndex, compressedImage.Width / compressedImage.ThinIndex, _colorMatrixProvider.GetMatrix()); var cbChannel = _pieceMatrixExtender.Extend(thinnedCbChannel, compressedImage.ThinIndex); var crChannel = _pieceMatrixExtender.Extend(thinnedCrChannel, compressedImage.ThinIndex); var yCbCrChannels = new YCbCrChannels(yChannel, cbChannel, crChannel); var yCbCrPixels = _iChannelsPacker.Pack(yCbCrChannels, compressedImage.Height, compressedImage.Width); var matrixRgbPixels = MatrixYCbCrToRgbConverter.Convert(yCbCrPixels); var bmp = _bitmapBuilder.Build(matrixRgbPixels); return(bmp); }
protected override MyMatrix GetMatrixInternal() { return(provider.GetMatrix()); }