Esempio n. 1
0
        public Bitmap Process(Bitmap source, IFilter filter)
        {
            Bitmap         copiedSource = (Bitmap)source.Clone();
            LockableBitmap outBitmap    = new LockableBitmap(copiedSource);

            outBitmap.LockBits();

            LockableBitmap processedBitmap = new LockableBitmap(source);

            processedBitmap.LockBits();

            try
            {
                SobelImageEnumerator enumerator = new SobelImageEnumerator(processedBitmap);

                while (enumerator.MoveNext())
                {
                    try
                    {
                        ExecuteStep(enumerator.Current, filter, processedBitmap, outBitmap);
                    }
                    catch (Exception ex)
                    {
                        Log.Current.Error(ex);
                    }
                }
            }
            finally
            {
                processedBitmap.UnlockBits();
                outBitmap.UnlockBits();
            }

            return(copiedSource);
        }
Esempio n. 2
0
 public void Dispose()
 {
     if (source != null)
     {
         source.UnlockBits();
     }
 }
Esempio n. 3
0
        public Bitmap Process(Bitmap source, params IPerItemAlgorithm[] perItemAlgorithms)
        {
            LockableBitmap lockableBitmap = new LockableBitmap(source);

            lockableBitmap.LockBits();

            try
            {
                foreach (IPerItemAlgorithm algorithm in perItemAlgorithms)
                {
                    for (int x = 0; x < lockableBitmap.Width; x++)
                    {
                        for (int y = 0; y < lockableBitmap.Height; y++)
                        {
                            Color processedColor = algorithm.Execute(lockableBitmap.GetPixel(x, y));
                            lockableBitmap.SetPixel(x, y, processedColor);
                        }
                    }
                }
            }
            finally
            {
                lockableBitmap.UnlockBits();
            }

            return(source);
        }
Esempio n. 4
0
        public Bitmap Process(Bitmap sourceToProcess)
        {
            Bitmap copiedSource = (Bitmap)sourceToProcess.Clone();

            LockableBitmap outBitmap = new LockableBitmap(copiedSource);

            outBitmap.LockBits();

            LockableBitmap lockableBitmap = new LockableBitmap(sourceToProcess);

            lockableBitmap.LockBits();

            try
            {
                IPattern <double> pattern          = RetrievePatternValue(lockableBitmap);
                double[]          processedPattern = hopfieldNeuralNetwork.Determine(pattern);

                ApplyPatternValues(processedPattern, outBitmap);
            }
            finally
            {
                lockableBitmap.UnlockBits();
                outBitmap.UnlockBits();
            }

            return(copiedSource);
        }
Esempio n. 5
0
        public Bitmap Process(Bitmap source, IPointsDetector detector)
        {
            LockableBitmap processedBitmap = new LockableBitmap(source);

            processedBitmap.LockBits();

            try
            {
                СharacteristicPoint[] characteristicsPoints = null;
                try
                {
                    characteristicsPoints = detector.Detect(processedBitmap);
                }
                finally
                {
                    processedBitmap.UnlockBits();
                }

                ProcessOutput(source, characteristicsPoints);
            }
            catch (Exception ex)
            {
                Log.Current.Error(ex);
            }

            return(source);
        }
Esempio n. 6
0
        public Bitmap Determine(
            Bitmap source,
            int clustersNumber,
            Region[] regions,
            IClusteringAlgorithmFactory clusteringAlgorithmFactory)
        {
            LockableBitmap lockableBitmap = new LockableBitmap(source);

            lockableBitmap.LockBits();

            IClusteringAlgorithm <double> clusteringAlgorithm =
                clusteringAlgorithmFactory.Create(clustersNumber, lockableBitmap);

            try
            {
                Region[] clusteredRegions = clusteringAlgorithm.Distribute(regions);

                foreach (Region region in clusteredRegions)
                {
                    FillRegion(region, lockableBitmap);
                }
            }
            finally
            {
                lockableBitmap.UnlockBits();
            }

            return(source);
        }
Esempio n. 7
0
        public Bitmap MarkRegions(Bitmap source, IScanner scanner, int threshold)
        {
            IDictionary <int, List <ScanInfo> > regions = scanner.Scan(source);

            LockableBitmap lockableBitmap = new LockableBitmap(source);

            lockableBitmap.LockBits();

            try
            {
                int regionIndex = 1;

                foreach (KeyValuePair <int, List <ScanInfo> > region in
                         regions.Where(region => region.Value.Count >= threshold))
                {
                    FillRegion(regionIndex, region, lockableBitmap);

                    regionIndex++;
                }
            }
            finally
            {
                lockableBitmap.UnlockBits();
            }

            return(source);
        }
        public int[] Calculate(Bitmap bitmap)
        {
            int[] lumininances = new int[256];

            LockableBitmap lockableBitmap = new LockableBitmap(bitmap);

            lockableBitmap.LockBits();

            try
            {
                for (int i = 0; i < lockableBitmap.Width; i++)
                {
                    for (int j = 0; j < lockableBitmap.Height; j++)
                    {
                        byte brightness = lockableBitmap.GetPixel(i, j).Brightness();
                        lumininances[brightness]++;
                    }
                }
            }
            finally
            {
                lockableBitmap.UnlockBits();
            }
            return(lumininances);
        }
Esempio n. 9
0
        public void AddPattern(Bitmap source)
        {
            LockableBitmap lockableBitmap = new LockableBitmap(source);

            lockableBitmap.LockBits();

            try
            {
                IPattern <double> pattern = RetrievePatternValue(lockableBitmap);
                hopfieldNeuralNetwork.Teach(pattern);
            }
            finally
            {
                lockableBitmap.UnlockBits();
            }
        }
Esempio n. 10
0
        public Bitmap Process(Bitmap source, IMultiFilter filter)
        {
            Bitmap         copiedSource = (Bitmap)source.Clone();
            LockableBitmap outBitmap    = new LockableBitmap(copiedSource);

            outBitmap.LockBits();

            LockableBitmap processedBitmap = new LockableBitmap(source);

            processedBitmap.LockBits();

            try
            {
                GaussEnumerator enumerator = new GaussEnumerator(processedBitmap);

                while (enumerator.MoveNext())
                {
                    try
                    {
                        Color processedColor = filter.Execute(enumerator.Current);

                        ApertureItem processedApertureItem =
                            enumerator.Current[enumerator.Current.GetLength(0) / 2, enumerator.Current.GetLength(0) / 2];

                        ProcessOutput(processedApertureItem, processedColor, outBitmap);
                    }
                    catch (Exception exception)
                    {
                        Log.Current.Error(exception);
                    }
                }
            }
            finally
            {
                processedBitmap.UnlockBits();
                outBitmap.UnlockBits();
            }

            return(copiedSource);
        }
Esempio n. 11
0
        public IDictionary <int, List <ScanInfo> > Scan(Bitmap source)
        {
            LockableBitmap lockableBitmap = new LockableBitmap(source);

            lockableBitmap.LockBits();
            LockableBitmapWrapper lockableBitmapWrapper = new LockableBitmapWrapper(lockableBitmap);

            try
            {
                SequentialEnumerator enumerator = new SequentialEnumerator(lockableBitmapWrapper);
                while (enumerator.MoveNext())
                {
                    AbcMask mask = enumerator.Current;
                    if (mask.Current.Color.IsWhite())
                    {
                        if (!mask.Left.IsLabeled && !mask.Top.IsLabeled)
                        {
                            if (regions.Count > 0)
                            {
                                mask.Current.RegionNumber = regions.Keys.Max() + 1;
                            }
                            else
                            {
                                mask.Current.RegionNumber = 0;
                            }

                            AddRegionAndMove(
                                regionNumber: mask.Current.RegionNumber,
                                info: mask.Current);
                        }
                        else if (!mask.Left.IsLabeled && mask.Top.IsLabeled)
                        {
                            mask.Current.RegionNumber = mask.Top.RegionNumber;

                            Move(regionNumber: mask.Current.RegionNumber, info: mask.Current);
                        }
                        else if (mask.Left.IsLabeled && !mask.Top.IsLabeled)
                        {
                            mask.Current.RegionNumber = mask.Left.RegionNumber;

                            Move(regionNumber: mask.Current.RegionNumber, info: mask.Current);
                        }
                        else if (mask.Left.IsLabeled && mask.Top.IsLabeled)
                        {
                            if (mask.Left.RegionNumber == mask.Top.RegionNumber)
                            {
                                mask.Current.RegionNumber = mask.Left.RegionNumber;

                                Move(regionNumber: mask.Current.RegionNumber, info: mask.Current);
                            }
                            else
                            {
                                ReAllocate(mask);
                            }
                        }
                        mask.Current.IsLabeled = true;
                    }
                }
            }
            finally
            {
                lockableBitmap.UnlockBits();
            }

            return(regions);
        }
Esempio n. 12
0
 public void UnlockBits()
 {
     source.UnlockBits();
 }