static void Main(string[] args) { Bitmap bitmap_0 = new Bitmap(@"D:\Projects\hisdocpro\HisDocPro\HisDocProUI\bin\Debug\tokens\t_0_c000.png"); //Bitmap bitmap_0 = new Bitmap(PageFileSelected); Bitmap bitmapTemp = new Grayscale(0.2125, 0.7154, 0.0721).Apply(bitmap_0); bitmapTemp = new Threshold(100).Apply(bitmapTemp); bitmapTemp = new Invert().Apply(bitmapTemp); double[,] image = ToolsConvolution.BitMapToDoubleArray(bitmapTemp, 0.5); double[,] kernel = ToolsConvolution.BitMapToDoubleArray(bitmapTemp, 0.5); Print(image); Print(kernel); //double[,] image = new double[6, 6]; //image[2, 1] = 1; //image[2, 2] = 1; //image[2, 3] = 1; //image[2, 4] = 1; //double[,] kernel = new double[3, 3]; //kernel[0, 0] = 1; //kernel[0, 1] = 1; //kernel[0, 2] = 1; //kernel[2, 1] = 1; //Print(image); //Print(kernel); //double[,] result = ToolsConvolution.CorrelationFFT(image, kernel); //Print(result); //Console.ReadLine(); double [,] result = ToolsConvolution.CorrelationFFT(image, kernel); Print(result); //List<string> page = ToolsPDF.Convert(@"D:\Projects\hisdocpro\page.pdf"); }
public ModelToken(IModelApplication application, string filePathImage, string filePathJson) { _application = application; _filePathImage = filePathImage; _filePathJson = filePathJson; _bitmapSource = new Bitmap(filePathImage); if ((_bitmapSource.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed) || (_bitmapSource.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { _bitmapSource = ToolsConvolution.ConvertTo24(_bitmapSource); } Bitmap bitmapTemp = new Grayscale(1, 0, 0).Apply(_bitmapSource); bitmapTemp = new Erosion().Apply(bitmapTemp); bitmapTemp = new Threshold(160).Apply(bitmapTemp); bitmapTemp = new Invert().Apply(bitmapTemp); _kernel = ToolsConvolution.BitMapToDoubleArray(bitmapTemp, 0.5); _threshold = new ModelValueDouble(application.EventTokenChanged, 0); _weigth = new ModelValueDouble(application.EventTokenChanged, 0); ModelRendererBitmapSource renderer = new ModelRendererBitmapSource(_bitmapSource); renderer.Render(); Image = renderer.RenderedImage; ModelRendererBitmapSource rendererProcessed = new ModelRendererBitmapSource(bitmapTemp); rendererProcessed.Render(); ImageProcessed = rendererProcessed.RenderedImage; if (File.Exists(filePathJson)) { Load(); } else { this._threshold = new ModelValueDouble(_application.EventTokenChanged, 0.8); this._weigth = new ModelValueDouble(_application.EventTokenChanged, 1.0); this._label = filePathImage.Split('_')[1]; Save(); } }
private List <ConnectedComponent> GetTokens(Bitmap bitmapTemp) { List <ConnectedComponent>[] component_list_array = new List <ConnectedComponent> [TokenList.Count]; double[,] imageDouble = ToolsConvolution.BitMapToDoubleArray(bitmapTemp, 0.5); Parallel.For(0, TokenList.Count, tokenIndex => { ModelToken token = TokenList[tokenIndex]; var corr = ToolsConvolution.CorrelationFFT(imageDouble, token.GetKernel()); component_list_array[tokenIndex] = ToolsConnectedComponent.GetConnectedComponents(corr, token.Threshold.Value, token); }); List <ConnectedComponent> component_list = new List <ConnectedComponent>(); foreach (List <ConnectedComponent> list in component_list_array) { component_list.AddRange(list); } return(component_list); }