public RegionDetector2_0(CanvasARGB canvas)
        {
            this._canvasPixel         = CanvasPixel.CreateBitmpaFromCanvas(canvas);
            this._canvasPixelOriginal = CanvasPixel.CreateBitmpaFromCanvas(canvas);

            this._regionManipulator = new RegionManipulator(this._canvasPixelOriginal, this._canvasPixel);
        }
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            if (_currentImage == null)
            {
                return;
            }

            int inputNumber = int.Parse(NumberInput.Text);

            Stopwatch performanceCounter = new Stopwatch();

            performanceCounter.Start();

            CanvasARGB canvas = Get_ProgressOrOrigInput();

            RegionDetektor rd = new RegionDetektor();
            CanvasPixel    cp = rd.DetectOld(canvas, inputNumber);

            //cp.TransformFromInterleaveRGB();

            _lastImage = CanvasPixel.CreateBitmpaFromCanvas(cp);

            performanceCounter.Stop();

            Helper_SetAppTitle(string.Format("{0,000} s    - regions : {1}", performanceCounter.Elapsed.TotalSeconds, rd.TotalRegions));

            ShowImage(false);
        }
Beispiel #3
0
        public void SetColor_AsNearToAverageToAll(CanvasPixel originalCanvasPixel, CanvasPixel canvasPixel)
        {
            Pixel[] data     = canvasPixel.Data;
            Pixel[] origData = originalCanvasPixel.Data;

            Int64 sumR = 0;
            Int64 sumG = 0;
            Int64 sumB = 0;

            for (int i = 0; i < Pixels.Length; i++)
            {
                int   item         = Pixels[i];
                Pixel origDataItem = origData[item];
                sumR += origDataItem.CR;
                sumG += origDataItem.CG;
                sumB += origDataItem.CB;
            }

            //int color = (int)(sum / Pixels.Count);

            Color.CR = (byte)(sumR / Pixels.Length);
            Color.CG = (byte)(sumG / Pixels.Length);
            Color.CB = (byte)(sumB / Pixels.Length);

            Color = GetNearestPixel(origData, Pixels, Color);

            int tmp = Color.Get_ColorClearAlpha_Int();

            for (int i = 0; i < Pixels.Length; i++)
            {
                int item = Pixels[i];
                data[item].Set_ColorClearAlpha_Int(tmp);
            }
        }
        private void CollorToGray_Click(object sender, RoutedEventArgs e)
        {
            if (_currentImage == null)
            {
                return;
            }

            int inputNumber = int.Parse(NumberInput.Text);

            Stopwatch performanceCounter = new Stopwatch();

            performanceCounter.Start();

            CanvasARGB  canvas      = Get_ProgressOrOrigInput();
            CanvasPixel canvasPixel = CanvasPixel.CreateBitmpaFromCanvas(canvas);

            ColorToGrey ctg = new ColorToGrey();

            Array2D matrix = ctg.CreateColloredMatrix(canvasPixel.Width, canvasPixel.Height, inputNumber);

            CanvasPixel resultCanvas = ctg.CreateColoredGreyScale(canvasPixel, matrix);



            _lastImage = CanvasPixel.CreateBitmpaFromCanvas(resultCanvas);



            performanceCounter.Stop();

            Helper_SetAppTitle(string.Format("{0,000} s ", performanceCounter.Elapsed.TotalSeconds));

            ShowImage(false);
        }
Beispiel #5
0
        public void RenderLines(CanvasPixel original, CanvasPixel final)
        {
            int rowIndex = 0;

            for (int y = 0; y < final.Height; y++)
            {
                int endIndex = rowIndex + final.Width;

                int currIndex = rowIndex;
                while (currIndex < endIndex)
                {
                    int   startRangeIndex = currIndex;
                    int   endRangeIndex   = startRangeIndex;
                    Pixel color           = final.Data[startRangeIndex];

                    while (endRangeIndex + 1 < endIndex && final.Data[endRangeIndex + 1].CompareTo(color) == 0)
                    {
                        endRangeIndex++;
                    }

                    int startX = startRangeIndex % final.Width;
                    int endX   = endRangeIndex % final.Width;

                    Color colorTmp = Color.FromArgb(color.CA, color.CR, color.CG, color.CB);
                    CanvasContainer.Children.Add(Create_Line(startX, y, endX + 1, y, colorTmp));


                    currIndex = endRangeIndex + 1;
                }

                rowIndex += final.Width;
            }

            //_output.WriteLine(Helper_CreateSVGLine(10,10,100,10,new Pixel() {CR=255,CG=255 }));
        }
        private void Button_Click_41(object sender, RoutedEventArgs e)
        {
            if (_currentImage == null)
            {
                return;
            }

            int inputNumber = int.Parse(NumberInput.Text);

            Stopwatch performanceCounter = new Stopwatch();

            performanceCounter.Start();

            CanvasARGB canvas = Get_ProgressOrOrigInput();

            CanvasPixel tmpCanvasPixel = CanvasPixel.CreateBitmpaFromCanvas(canvas);

            ColorReductor cr = new ColorReductor();

            cr.ReduceByMask(tmpCanvasPixel, inputNumber);


            _lastImage = CanvasPixel.CreateBitmpaFromCanvas(tmpCanvasPixel);

            performanceCounter.Stop();

            Helper_SetAppTitle(string.Format("{0,000} s    ", performanceCounter.Elapsed.TotalSeconds));

            ShowImage(false);
        }
Beispiel #7
0
        public static CanvasEdgeVO CreateEdgesFromCanvas(CanvasPixel canvasPixel)
        {
            CanvasEdgeVO result = new CanvasEdgeVO(canvasPixel.Width, canvasPixel.Height);

            EdgePoint[] dest   = result.Data;
            Pixel[]     source = canvasPixel.Data;

            Pixel[] matrix = new Pixel[9];

            for (int y = 0; y < canvasPixel.Height; y++)
            {
                for (int x = 0; x < canvasPixel.Width; x++)
                {
                    int index = y * canvasPixel.Width + x;

                    matrix[0] = CreateEdgesFromCanvas_GetPixel(canvasPixel, x, y, -1, -1, index);
                    matrix[1] = CreateEdgesFromCanvas_GetPixel(canvasPixel, x, y, 0, -1, index);
                    matrix[2] = CreateEdgesFromCanvas_GetPixel(canvasPixel, x, y, 1, -1, index);

                    matrix[3] = CreateEdgesFromCanvas_GetPixel(canvasPixel, x, y, -1, 0, index);
                    matrix[4] = CreateEdgesFromCanvas_GetPixel(canvasPixel, x, y, 0, 0, index);
                    matrix[5] = CreateEdgesFromCanvas_GetPixel(canvasPixel, x, y, 1, 0, index);

                    matrix[6] = CreateEdgesFromCanvas_GetPixel(canvasPixel, x, y, -1, 1, index);
                    matrix[7] = CreateEdgesFromCanvas_GetPixel(canvasPixel, x, y, 0, 1, index);
                    matrix[8] = CreateEdgesFromCanvas_GetPixel(canvasPixel, x, y, 1, 1, index);

                    (GradientDirection direction, int intensity)gResult = DirectionGradientBO.Detect(matrix);

                    dest[index] = new EdgePoint(gResult.direction, gResult.intensity);
                }
            }
            return(result);
        }
Beispiel #8
0
        /// <summary>
        /// slouci dva regiony
        /// dest region = k nemu jsou pridany pixely ze slucovaneho
        /// </summary>
        /// <param name="destRegion"></param>
        /// <param name="forFuseRegion"></param>
        private void FuseRegions(RegionVO destRegion, RegionVO forFuseRegion, CanvasPixel canvasPixel)
        {
            Pixel finalColor = new Pixel();

            //finalColor = destRegion.Color;
            //finalColor = Pixel.Average(destRegion.Color, forFuseRegion.Color);
            finalColor = Pixel.Average(destRegion.Color, destRegion.Pixels.Length, forFuseRegion.Color, forFuseRegion.Pixels.Length);



            foreach (var item in destRegion.Pixels)
            {
                canvasPixel.Data[item] = finalColor;
                destRegion.Color       = finalColor;
            }

            List <int> dPixels = destRegion.Pixels.ToList();

            Pixel[] cpData = canvasPixel.Data;

            foreach (var item in forFuseRegion.Pixels)
            {
                dPixels.Add(item);
                // reassign region
                _regionPixelLookup[item] = destRegion;
                // apply color
                cpData[item] = finalColor;// destRegion.Color;
            }

            dPixels.Sort();
            destRegion.Pixels = dPixels.ToArray();
            //destRegion.CreatePixelEdges(_regionPixelLookup);
            //_regionManipulator.CreatePixelEdges(destRegion);
        }
Beispiel #9
0
        private void ReduceAllRegionUnderColorTolerance(CanvasPixel canvasPixel, int maxColorDiff)
        {
            int origRegionCount = 0;

            do
            {
                HashSet <RegionVO> usedInFuseLookup = new HashSet <RegionVO>();

                List <RegionVO> tmpRegions = new List <RegionVO>(_listRegion.Count);
                //tmpRegions.Clear();
                //tmpRegions.AddRange(_listRegion);

                _listRegion = _listRegion.OrderBy(x => x.Pixels.Length).ToList();

                origRegionCount = _listRegion.Count();
                for (int i = 0; i < _listRegion.Count; i++)
                {
                    RegionVO region = _listRegion[i]; // _listRegion.FirstOrDefault(x => x.Pixels.Count < minCountPixels);

                    if (region == null)
                    {
                        break;
                    }
                    if (usedInFuseLookup.Contains(region))
                    {
                        tmpRegions.Add(_listRegion[i]);
                        continue;
                    }

                    RegionVO bestForFuse = BestRegionToFuse(region, canvasPixel, maxColorDiff, usedInFuseLookup);
                    if (bestForFuse == null)
                    {
                        usedInFuseLookup.Add(region);
                        tmpRegions.Add(region);
                        continue;
                        //throw new NotImplementedException();
                    }

                    //if (bestForFuse.Pixels.Count >= region.Pixels.Count())
                    {
                        usedInFuseLookup.Add(bestForFuse);
                        usedInFuseLookup.Add(region);

                        FuseRegions(bestForFuse, region, canvasPixel);
                    }
                    //else
                    {
                        //  tmpRegions.Add(region);
                        //  continue;
                    }
                    //else
                    //{
                    //    FuseRegions(region,bestForFuse , canvasPixel);
                    //}
                }
                //tmpRegions.CopyTo(_listRegion);

                _listRegion = tmpRegions;
            } while (origRegionCount > _listRegion.Count);
        }
Beispiel #10
0
        private void ReduceAllRegionUnderCountPixel(CanvasPixel canvasPixel, int minCountPixels)
        {
            List <RegionVO> tmpRegions = new List <RegionVO>();

            for (int i = 0; i < _listRegion.Count; i++)
            {
                if (_listRegion[i].Pixels.Length < minCountPixels)
                {
                    RegionVO region = _listRegion[i]; // _listRegion.FirstOrDefault(x => x.Pixels.Count < minCountPixels);

                    if (region == null)
                    {
                        break;
                    }

                    RegionVO bestForFuse = BestRegionToFuse(region, canvasPixel, 1024);
                    if (bestForFuse == null)
                    {
                        tmpRegions.Add(_listRegion[i]);
                        continue;
                        //throw new NotImplementedException();
                    }

                    FuseRegions(bestForFuse, region, canvasPixel);
                }
                else
                {
                    tmpRegions.Add(_listRegion[i]);
                }
            }

            _listRegion = tmpRegions;
        }
        private void FuseAllSinglePoints(List <int> singleAlonePoints, CanvasPixel canvasPixel, int tolerance)
        {
            List <int> tmpSinglePoints = new List <int>();

            int toleranceModif = 1024;

            while (singleAlonePoints.Count > 0)
            {
                tolerance += toleranceModif;

                for (int i = 0; i < singleAlonePoints.Count; i++)
                {
                    int index = singleAlonePoints[i];
                    int x     = index % canvasPixel.Width;
                    int y     = index / canvasPixel.Width;

                    CreateRegionFromStartPixel(x, y, tmpSinglePoints, canvasPixel, tolerance);
                }

                if (singleAlonePoints.Count == tmpSinglePoints.Count)
                {
                    tmpSinglePoints.Clear();
                }
                else
                {
                    singleAlonePoints = tmpSinglePoints;
                    tmpSinglePoints   = new List <int>();
                }

                toleranceModif <<= 1;
            }
        }
        private void DirectionToFile_Click(object sender, RoutedEventArgs e)
        {
            if (_currentImage == null)
            {
                return;
            }

            Stopwatch performanceCounter = new Stopwatch();

            performanceCounter.Start();

            CanvasARGB  canvas      = Get_ProgressOrOrigInput();
            CanvasPixel canvasPixel = CanvasPixel.CreateBitmpaFromCanvas(canvas);

            CanvasEdgeVO canvasEdges = CanvasEdgeVO.CreateEdgesFromCanvas(canvasPixel);

            EdgeDetector.EdgeReducer(canvasEdges, 255);

            EdgesWriteToFile(canvasEdges, "directions3.txt");

            CanvasPixel evisualise = VisualiseDetectedEdges(canvasEdges);

            _lastImage = CanvasPixel.CreateBitmpaFromCanvas(evisualise);



            performanceCounter.Stop();

            Helper_SetAppTitle(string.Format("{0,000} s ", performanceCounter.Elapsed.TotalSeconds));

            ShowImage(false);
        }
Beispiel #13
0
        public RegionManipulator(CanvasPixel originalCanvasPixel, CanvasPixel canvasPixel)
        {
            this._canvasPixel         = canvasPixel;
            this._originalCanvasPixel = originalCanvasPixel;

            this._widthPixels  = canvasPixel.Width;
            this._heightPixels = canvasPixel.Height;
        }
        private List <int> CreateRegionFromStart(CanvasPixel canvasPixel, int tolerance)
        {
            List <int> listSinglePoints = new List <int>();

            CanvasPixel cp = canvasPixel;

            Pixel[] data = cp.Data;

            //for (int y = 1; y < cp.Height - 1; y += 1)
            //    for (int i = 1; i < cp.Width - 1; i += 1)
            //    {
            //        CreateRegionFromStartPixel(i, y, listSinglePoints, canvasPixel, tolerance);
            //    }


            for (int y = 0; y < cp.Height; y += 2)
            {
                for (int i = 0; i < cp.Width; i += 2)
                {
                    CreateRegionFromStartPixel(i, y, listSinglePoints, canvasPixel, tolerance);
                }
            }

            for (int y = 1; y < cp.Height; y += 2)
            {
                for (int i = 0; i < cp.Width; i += 2)
                {
                    CreateRegionFromStartPixel(i, y, listSinglePoints, canvasPixel, tolerance);
                }
            }


            for (int y = 0; y < cp.Height; y += 2)
            {
                for (int i = 1; i < cp.Width; i += 2)
                {
                    CreateRegionFromStartPixel(i, y, listSinglePoints, canvasPixel, tolerance);
                }
            }

            for (int y = 1; y < cp.Height; y += 2)
            {
                for (int i = 1; i < cp.Width; i += 2)
                {
                    CreateRegionFromStartPixel(i, y, listSinglePoints, canvasPixel, tolerance);
                }
            }


            //for (int i = 0; i < _listRegion.Count;i++ )
            //{
            //    _listRegion[i].SetColorAsAverageToAll(canvasPixel);
            //}



            return(listSinglePoints);
        }
        private void ReduceAllRegionUnderCountPixel(CanvasPixel canvasPixel, int maxCountPixel, CanvasPixel canvasPixelOriginal)
        {
            int origRegionCount = 0;

            do
            {
                origRegionCount = _listRegion.Count;
                for (int i = 0; i < _listRegion.Count; i++)
                {
                    RegionVO region = _listRegion[i];

                    if (region == null)
                    {
                        break;
                    }
                    if (region.NotValid)
                    {
                        continue;
                    }

                    if (region.Pixels.Length <= maxCountPixel)
                    {
                        RegionVO bestForFuse = BestRegionToFuse2(region, canvasPixel, int.MaxValue, true);
                        if (bestForFuse == null)
                        {
                            continue;
                        }

                        if (bestForFuse != region)
                        {
                            //// swap for faster merge
                            if (region.Pixels.Length > bestForFuse.Pixels.Length)
                            {
                                RegionVO tmp = region;
                                region      = bestForFuse;
                                bestForFuse = tmp;
                            }

                            FuseRegions(bestForFuse, region, canvasPixel, canvasPixelOriginal);

                            region.NotValid = true;
                            region.Clear();
                        }
                    }
                }

                List <RegionVO> kk = new List <RegionVO>(_listRegion.Count);
                for (int i = 0; i < _listRegion.Count; i++)
                {
                    if (!_listRegion[i].NotValid)
                    {
                        kk.Add(_listRegion[i]);
                    }
                }

                _listRegion = kk;
            } while (origRegionCount > _listRegion.Count);
        }
        /// <summary>
        /// slouci dva regiony
        /// dest region = k nemu jsou pridany pixely ze slucovaneho
        /// </summary>
        /// <param name="destRegion"></param>
        /// <param name="forFuseRegion"></param>
        private void FuseRegions(RegionVO destRegion, RegionVO forFuseRegion, CanvasPixel canvasPixel, CanvasPixel canvasPixelOriginal)
        {
            if (destRegion == forFuseRegion)
            {
                throw new Exception();
            }



            for (int i = 0; i < forFuseRegion.Pixels.Length; i++)
            {
                int item = forFuseRegion.Pixels[i];
                // reassign region
                _regionPixelLookup[item] = destRegion;
            }

            destRegion.Pixels = MergeOrderedPixel(destRegion.Pixels, forFuseRegion.Pixels);

            //destRegion.Pixels.Sort();
            //destRegion.CreatePixelEdges(_regionPixelLookup);
            //destRegion.CreatePixelEdges();
            //_regionManipulator.CreatePixelNeighbourEdge(destRegion,_regionPixelLookup);

            // _regionManipulator.MergePixelNeighbourEdge(destRegion,forFuseRegion, _regionPixelLookup);


            //if (destRegion.Pixels.Length > 100)
            //{
            //    destRegion.SetColor_AsNearToAverageToAll(canvasPixelOriginal, canvasPixel);
            //}
            //else
            //{
            //    destRegion.SetColorAsMedinToAll(canvasPixelOriginal, canvasPixel);
            //}

            //destRegion.SetColor_AsNearToAverageToAll(canvasPixelOriginal, canvasPixel);


            //destRegion.SetColorAsFixToAll(canvasPixelOriginal, canvasPixel);
            destRegion.SetColor_AsAverageToAll(canvasPixelOriginal, canvasPixel);
            //destRegion.SetColorHSLAsAverageToAll(canvasPixelOriginal, canvasPixel);

            //List<RegionVO> neighbours = Helper_GetMergedNeighbours2(destRegion, forFuseRegion);
            //destRegion.NeighbourRegions = neighbours.ToArray();
            RegionVO[] neighbours = Helper_GetMergedNeighbours(destRegion, forFuseRegion);
            destRegion.NeighbourRegions = neighbours;

            foreach (RegionVO item in neighbours)
            {
                item.Add_NeightbourRegion(destRegion);
                item.Remove_NeightbourRegion(forFuseRegion);

                //item.Create_NeighbourRegions(_regionPixelLookup);
            }
        }
        public void Test_PolygonCustomTest()
        {
            CanvasPixel canvas = new CanvasPixel(11, 20);

            Trace.RegionManipulator rm = new Trace.RegionManipulator(canvas, canvas);

            Trace.RegionVO region = new Trace.RegionVO(new Pixel());
            region.Pixels = Helper_GetCustomPolygon(rm);

            Helper_Test_EdgeCrawler(region, rm, new Point(9, 9));
        }
Beispiel #18
0
        public CanvasPixel Detect(CanvasARGB canvas, int tolerance)
        {
            _regionPixelLookup = new RegionVO[canvas.Length];
            _listRegion        = new List <RegionVO>();

            CanvasPixel canvasPixel = CanvasPixel.CreateBitmpaFromCanvas(canvas);

            this._regionManipulator = new RegionManipulator(null, canvasPixel);
            //canvasPixel.ConvertPixelsRGBToHSL();
            //canvasPixel.ReduceNotSeenColors();
            //canvasPixel.TransformToInterleaveRGB();

            List <int> singleAlonePoints = CreateRegionFromStart(canvasPixel, 0);// tolerance);

            //List<int> singleAlonePoints = CreateRegionFromStartCicCac(canvasPixel, tolerance);



            FuseAllSinglePoints(singleAlonePoints, canvasPixel, tolerance);

            int minPixels = tolerance;

            //for (int i = 1; i <= 16; i++)
            //    ReduceAllRegionUnderCountPixel(canvasPixel, i);



            for (int i = minPixels;
                 i <= minPixels; i++)
            {
                ReduceAllRegionUnderColorTolerance(canvasPixel, i);
            }
            //ReduceAllRegionUnderCountPixel(canvasPixel, 5);

            Dictionary <int, int> groups = new Dictionary <int, int>();

            foreach (var item in _listRegion)
            {
                if (groups.ContainsKey(item.Pixels.Length))
                {
                    groups[item.Pixels.Length]++;
                }
                else
                {
                    groups.Add(item.Pixels.Length, 1);
                }
            }



            //canvasPixel.ConvertPixelsHSLToRGB();
            return(canvasPixel);
        }
Beispiel #19
0
        private static Pixel CreateEdgesFromCanvas_GetPixel(CanvasPixel canvas, int x, int y, int diffX, int diffY, int index)
        {
            x += diffX;
            y += diffY;
            bool isOutOfRange = x < 0 || y < 0 || canvas.Width <= x || canvas.Height <= y;

            if (isOutOfRange)
            {
                return(canvas.Data[index]);
            }
            else
            {
                return(canvas.Data[index + diffY * canvas.Width + diffX]);
            }
        }
        private CanvasPixel CreateCanvasFromRegions(CanvasPixel canvasPixelOriginal, List <RegionVO> regions)
        {
            CanvasPixel result = new CanvasPixel(canvasPixelOriginal.Width, canvasPixelOriginal.Height);

            foreach (var region in regions)
            {
                Pixel color = region.Color;
                for (int i = 0; i < region.Pixels.Length; i++)
                {
                    result.Data[region.Pixels[i]] = color;
                }
            }

            return(result);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (_currentImage == null)
            {
                return;
            }


            int inputNumber = int.Parse(NumberInput.Text);

            Stopwatch performanceCounter = new Stopwatch();

            performanceCounter.Start();

            CanvasARGB canvas = Get_ProgressOrOrigInput();
            //for (int i = 0; i < 28000; i += 4)
            //{
            //    canvas.Data[i] = 0;
            //    canvas.Data[i + 1] = 255;
            //    canvas.Data[i + 2] = 0;
            //    canvas.Data[i + 3] = 255;
            //}


            CanvasPixel canvasPixel = CanvasPixel.CreateBitmpaFromCanvas(canvas);

            canvasPixel.TransformToInterleaveRGB();
            BasicOperation.PixelFilter2(canvasPixel, inputNumber);
            //canvasPixel.
            //BasicOperation.BlackWhite(canvasPixel);

            _lastImage = CanvasPixel.CreateBitmpaFromCanvas(canvasPixel);



            //BitmapSource bs = CanvasARGB.CreateBitmpaFromCanvas(canvas);

            //_originalImage = bs;
            //byte [] array = BitmapToArray(_originalImage);

            performanceCounter.Stop();

            Helper_SetAppTitle(string.Format("{0,000} s", performanceCounter.Elapsed.TotalSeconds));

            ShowImage(false);
            //RenderTargetBitmap.Create( rtb
            //textBox1.Text = ofd.FileName;
        }
        private void TraceNew_Click_1(object sender, RoutedEventArgs e)
        {
            if (_currentImage == null)
            {
                return;
            }


            int inputNumber = int.Parse(NumberInput.Text);

            Stopwatch performanceCounter = new Stopwatch();

            performanceCounter.Start();

            CanvasARGB canvas = Get_ProgressOrOrigInput();


            CanvasPixel tmpCanvasPixel = CanvasPixel.CreateBitmpaFromCanvas(canvas);

            canvas = CanvasPixel.CreateBitmpaFromCanvas(tmpCanvasPixel);

            RegionDetector2_0 rd = new RegionDetector2_0(canvas);

            rd.Detect_ByColorToleranceNew(inputNumber);
            CanvasPixel cp = rd.Get_CanvasFromRegions();

            if (CheckSaveToSVG.IsChecked.Value)
            {
                rd.ConvertRegionsToSVG(Helper_GetFileName_ForSVG(this._currentOpenFilename));
            }

            // cp.TransformFromInterleaveRGB();

            _lastImage = CanvasPixel.CreateBitmpaFromCanvas(cp);

            VectorPreview window = new VectorPreview();

            //window.RenderLines( tmpCanvasPixel,cp);

            window.RenderPolygons(rd.Regions, rd.RegionManipulator);
            window.Show();

            performanceCounter.Stop();

            Helper_SetAppTitle(string.Format("{0,000} s    - regions : {1}", performanceCounter.Elapsed.TotalSeconds, rd.TotalRegions));

            ShowImage(false);
        }
Beispiel #23
0
        public void SetColorAsFixToAll(CanvasPixel originalCanvasPixel, CanvasPixel canvasPixel)
        {
            Pixel[] data     = canvasPixel.Data;
            Pixel[] origData = originalCanvasPixel.Data;

            Pixel tmpPixel = origData[Pixels[0]];

            this.Color = tmpPixel;

            int tmp = Color.Get_ColorClearAlpha_Int();

            for (int i = 0; i < Pixels.Length; i++)
            {
                int item = Pixels[i];
                data[item].Set_ColorClearAlpha_Int(tmp);
            }
        }
Beispiel #24
0
        public CanvasPixel CreateColoredGreyScale(CanvasPixel source, Array2D matrix)
        {
            CanvasPixel result = new CanvasPixel(source.Width, source.Height);

            for (int i = 0; i < source.Data.Length; i++)
            {
                if (matrix.Data[i] == 1)
                {
                    result.Data[i] = source.Data[i];
                }
                else
                {
                    result.Data[i] = ToGreyScale(source.Data[i]);
                }
            }

            return(result);
        }
        public void Detect_ByColorToleranceNew(int tolerance)
        {
            //RegionVO.ClearIdNext();
            _regionPixelLookup = new RegionVO[this._canvasPixelOriginal.Data.Length];
            _listRegion        = new List <RegionVO>();

            CanvasPixel canvasPixel         = this._canvasPixel;
            CanvasPixel canvasPixelOriginal = this._canvasPixelOriginal;

            //canvasPixel.ConvertPixelsRGBToHSL();
            //canvasPixel.ReduceNotSeenColors();
            //canvasPixel.TransformToInterleaveRGB();

            List <int> singleAlonePoints = CreateRegionFromStart(canvasPixel, 0);// tolerance);

            //List<int> singleAlonePoints = CreateRegionFromStartCicCac(canvasPixel, tolerance);



            FuseAllSinglePoints(singleAlonePoints, canvasPixel, tolerance);

            foreach (var item in _listRegion)
            {
                this._regionManipulator.Create_NeighbourRegions(item, _regionPixelLookup);
            }

            ReduceAllRegionUnderColorTolerance(canvasPixel, 0, canvasPixelOriginal);

            int colorTolerance = tolerance;
            int countMinPixel  = CONST_maxCountPixelForRemove;

            for (int i = 1; i <= countMinPixel; i++)
            {
                ReduceAllRegionUnderCountPixel(canvasPixel, i, canvasPixelOriginal);
            }


            for (int i = 0;
                 i <= colorTolerance; i++)
            {
                ReduceAllRegionUnderColorTolerance(canvasPixel, i, canvasPixelOriginal);
                //ReduceAllRegionUnderColorTolerance(canvasPixel, i);
            }
        }
        private List <int> CreateRegionFromStartCicCac(CanvasPixel canvasPixel, int tolerance)
        {
            List <int> listSinglePoints = new List <int>();

            CanvasPixel cp = canvasPixel;

            Pixel[] data = cp.Data;

            int startX = 1;
            int startY = 1;

            for (int i = 1; i < cp.Width - 1; i++)
            {
                int tmpX = startX;
                int tmpY = startY;
                while (tmpX >= 1 && tmpY < (cp.Height - 1))
                {
                    CreateRegionFromStartPixel(tmpX, tmpY, listSinglePoints, canvasPixel, tolerance);
                    tmpX--;
                    tmpY++;
                }

                startX++;
            }

            startX = cp.Width - 2;
            startY = 2;

            for (int i = 2; i < cp.Height - 1; i++)
            {
                int tmpX = startX;
                int tmpY = startY;
                while (tmpX >= 1 && tmpY < (cp.Height - 1))
                {
                    CreateRegionFromStartPixel(tmpX, tmpY, listSinglePoints, canvasPixel, tolerance);
                    tmpX--;
                    tmpY++;
                }

                startY++;
            }

            return(listSinglePoints);
        }
        private CanvasPixel VisualiseDetectedEdges(CanvasEdgeVO data)
        {
            CanvasPixel result = new CanvasPixel(data.Width, data.Height);

            for (int i = 0; i < data.Data.Length; i++)
            {
                int intesityEdge = data.Data[i].Intensity;
                if (intesityEdge > 255)
                {
                    intesityEdge = 255;
                }

                byte oneChannel = (byte)intesityEdge;

                result.Data[i] = Pixel.Create(255, oneChannel, oneChannel, oneChannel);
            }

            return(result);
        }
Beispiel #28
0
        public void AreasToSVG(CanvasPixel original, List <RegionVO> regions, RegionManipulator regMan)
        {
            Write_StartHeader(original.Width, original.Height);

            RegionVO[] regionsOrdered = regMan.GetOrderedForRendering(regions.ToArray());

            RegionToPolygonBO regionToPolygon = new RegionToPolygonBO(regMan);

            for (int i = 0; i < regionsOrdered.Length; i++)
            {
                RegionVO region = regionsOrdered[i];

                Point[] points = regionToPolygon.ToPolygon(region);

                _output.WriteLine(Helper_CreateSVGPolyLine(points, region.Color));
                // _output.WriteLine(Helper_CreateSVGPolyGone(points, region.Color));
            }


            Write_EndHeader();
        }
        /// <summary>
        /// vraci region ktery je nejlepsi k slouceni s timto
        /// </summary>
        /// <param name="region"></param>
        /// <returns></returns>
        private RegionVO BestRegionToFuse2(RegionVO region, CanvasPixel canvasPixel, int maxColorDiff, bool ignoreColorCategory = false)
        {
            int isRegionColorCategory = Helper_GetPixelColorCategory(region.Color);

            RegionVO result      = null;
            int      resultDiff  = int.MaxValue;
            int      resultCount = -1;

            foreach (var item in region.NeighbourRegions)
            {
                // int diff = BasicHelpers.FastAbs(item.Key.Color.IntClearAlpha() - region.Color.IntClearAlpha());

                //int maxDiff = Pixel.MaxDiff(item.Key.Color, region.Color);
                //if (maxDiff > (maxColorDiff / 2) + 1) continue;

                bool colorRegionEqual = true;

                if (!ignoreColorCategory)
                {
                    int isItemColorCategory = Helper_GetPixelColorCategory(item.Color);
                    colorRegionEqual = isRegionColorCategory == isItemColorCategory;
                }


                int diff = Pixel.SumAbsDiff(item.Color, region.Color);

                if (diff <= maxColorDiff && colorRegionEqual)
                {
                    if (diff < resultDiff
                        )
                    {
                        resultDiff = diff;
                        result     = item;
                    }
                }
            }

            return(result);
        }
Beispiel #30
0
        public void BasicToSVG(CanvasPixel original, CanvasPixel final)
        {
            Write_StartHeader(final.Width, final.Height);

            int rowIndex = 0;

            for (int y = 0; y < final.Height; y++)
            {
                int endIndex = rowIndex + final.Width;

                int currIndex = rowIndex;
                while (currIndex < endIndex)
                {
                    int   startRangeIndex = currIndex;
                    int   endRangeIndex   = startRangeIndex;
                    Pixel color           = final.Data[startRangeIndex];

                    while (endRangeIndex + 1 < endIndex && final.Data[endRangeIndex + 1].CompareTo(color) == 0)
                    {
                        endRangeIndex++;
                    }

                    int startX = startRangeIndex % final.Width;
                    int endX   = endRangeIndex % final.Width;


                    _output.WriteLine(Helper_CreateSVGLine(startX, y, endX + 1, y, color));

                    currIndex = endRangeIndex + 1;
                }

                rowIndex += final.Width;
            }

            //_output.WriteLine(Helper_CreateSVGLine(10,10,100,10,new Pixel() {CR=255,CG=255 }));

            Write_EndHeader();
        }