public void Apply(string inputPath, string intermediatePath, int tnum)
        {
            RGBThreshold thd        = StraboParameters.rgbThreshold;
            string       outputPath = intermediatePath + StraboParameters.textLayerOutputFileName;

            Apply(inputPath, outputPath, intermediatePath, thd, tnum);
        }
示例#2
0
        public static string ApplyRGBColorThresholding(string inputPath, string outputPath, RGBThreshold thd, int tnum)
        {
            AForge.Imaging.Filters.BradleyLocalThresholding bradley = new AForge.Imaging.Filters.BradleyLocalThresholding();
            _srcimg.Dispose();
            _srcimg  = null;
            _srcimg  = new Bitmap(inputPath);
            _srcData = _srcimg.LockBits(
                new Rectangle(0, 0, _srcimg.Width, _srcimg.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            _dstimg = new  bool[_srcimg.Height, _srcimg.Width];

            try
            {
                Thread[] thread_array = new Thread[tnum];
                for (int i = 0; i < tnum; i++)
                {
                    thread_array[i] = new Thread(new ParameterizedThreadStart(Binarization.RunRGBColorThresholding));
                    thread_array[i].Start(i);
                }
                for (int i = 0; i < tnum; i++)
                {
                    thread_array[i].Join();
                }

                _srcimg.UnlockBits(_srcData);
                _srcimg.Dispose();
                _srcimg = null;

                Bitmap img = ImageUtils.Array2DToBitmap(_dstimg);
                img.Save(outputPath);
                img.Dispose();
                img     = null;
                _dstimg = null;

                return(outputPath);
            }
            catch (Exception e)
            {
                Log.WriteLine(e.Message);
                Log.WriteLine(e.Source);
                Log.WriteLine(e.StackTrace);
                throw;
            }
        }
 public void Apply(string inputPath, string outputPath, string intermediatePath, RGBThreshold thd, int tnum)
 {
     try
     {
         if (thd.upperBlueColorThd == thd.lowerBlueColorThd || thd.upperGreenColorThd == thd.lowerGreenColorThd || thd.upperRedColorThd == thd.lowerRedColorThd)
         {
             Binarization.ApplyBradleyLocalThresholding(inputPath, outputPath);
         }
         else
         {
             Binarization.ApplyRGBColorThresholding(inputPath, outputPath, thd, tnum);
         }
     }
     catch (Exception e)
     {
         Log.WriteLine("ExtractTextLayerFromMapWorker:" + e.Message);
         Log.WriteLine(e.Source);
         Log.WriteLine(e.StackTrace);
         throw;
     }
 }