public async Task <IActionResult> Edit(int id, [Bind("SilhouetteID,Naam")] Silhouette silhouette)
        {
            if (id != silhouette.SilhouetteID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(silhouette);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SilhouetteExists(silhouette.SilhouetteID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(silhouette));
        }
Exemplo n.º 2
0
        private void ThreadSilhouette_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            Silhouette silhouette       = new Silhouette(padroes, agrupamento);
            double     indiceSilhouette = silhouette.CalculaIndice();

            //valorIndice += "\nSilhouette Validation = " + string.Format("{0:0.###}", indiceSilhouette);
            valorIndice = "\nSilhouette Validation = " + string.Format("{0:0.##}", indiceSilhouette);
        }
        public async Task <IActionResult> Create([Bind("SilhouetteID,Naam")] Silhouette silhouette)
        {
            if (ModelState.IsValid)
            {
                _context.Add(silhouette);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(silhouette));
        }
Exemplo n.º 4
0
        public static void Init()
        {
            // init variables
            CsvReader.GetData();

            // set initial K -> K = 4 as centroids
            int k = numberOfCentroids;

            for (int i = 0; i < numberOfIterations; i++)
            {
                if (i == 0)
                {
                    //place K Randomly at first time.
                    centroids = Centroid.Initialize(k);
                }

                //eucl distance from centroid to offers / items
                Centroid.CalcCentroidDistance();

                //add data to cluster dictionary
                if (i > 0)
                {
                    Centroid.ClearPointList();
                }
                Centroid.AssignToCluster();

                //vergelijk oude sse met nieuw Sse
                Centroid.UpdateSSE();

                if (i > 0)
                {
                    //relocate centroids
                    centroids = Centroid.CalculateCentroidPosition();
                }
            }

            Silhouette.Init();
            foreach (var cluster in Centroid.sseCentroids)
            {
                var customers = cluster.Value;
                foreach (var customer in customers)
                {
                    Silhouette.CalculateSilhouette(customer.CustomerId);
                }
            }

            PrintResults();
            ExportExcel.Init();
            ExportExcel.CreateClusterWorkSheet();
            ExportExcel.CreateTopDealsWorkSheet();
            ExportExcel.CreateSilhouetteWorkSheet();
            ExportExcel.Export();
            Console.ReadLine();
        }
Exemplo n.º 5
0
    // Takes a group of contours and draws a silhouette for each contour in the group
    public SilhouetteGroup DrawSilhouettesForGroup(List <Contour> contours)
    {
        SilhouetteGroup sGroup = new SilhouetteGroup();

        foreach (Contour c in contours)
        {
            Silhouette silhouette = DrawSilhouette(c);

            RemovePixelNoise(silhouette);

            for (int i = 0; i < SilhouetteMergingIterations; i++)
            {
                MergeSilhouettePieces(silhouette);
            }

            sGroup.Silhouettes.Add(silhouette);
        }
        return(sGroup);
    }
Exemplo n.º 6
0
    // Removes silhouettes drawn from pixel noise (bug)
    public void RemovePixelNoise(Silhouette silhouette)
    {
        //Debug.Log("Silhouette size before: " + silhouette.Pieces.Count);
        foreach (SilhouettePiece sP in silhouette.Pieces)
        {
            if (sP.Points.Count < 20) // Remove the silhouette piece if it's only a few points in size (possible image noise)
            {
                sP.ShouldBeRemoved = true;
            }
        }

        for (int i = 0; i < silhouette.Pieces.Count; i++)
        {
            if (silhouette.Pieces[i].ShouldBeRemoved)
            {
                silhouette.Pieces.Remove(silhouette.Pieces[i]);
            }
        }
        //Debug.Log("Silhouette size after: " + silhouette.Pieces.Count);
    }
Exemplo n.º 7
0
    // Merges all pieces in a silhouette that have neighboring end points with each other
    public void MergeSilhouettePieces(Silhouette silhouette)
    {
        int threshold = SilhouetteMergingThreshold; // Maximum distance between two piece endpoints

        for (int i = 0; i < silhouette.Pieces.Count - 1; i++)
        {
            for (int j = i + 1; j < silhouette.Pieces.Count; j++)
            {
                SilhouettePiece sp1 = silhouette.Pieces[i];
                SilhouettePiece sp2 = silhouette.Pieces[j];

                LinkedListNode <ContourPixel>[] neighbors = VectorUtils.NeighboringStartOrEndPoints(sp1, sp2, threshold);
                if (neighbors[1] != null)
                {
                    //Debug.Log("Merging...");
                    silhouette.Pieces.Remove(sp1);
                    silhouette.Pieces.Remove(sp2);

                    SilhouettePiece mergedPiece = new SilhouettePiece();

                    LinkedListNode <ContourPixel> currentNode;
                    LinkedListNode <ContourPixel> nodeCopy;

                    if (neighbors[0].Next == null)
                    {
                        //Debug.Log("First piece 1");
                        currentNode = sp1.Points.First;
                        while (currentNode.Value != neighbors[0].Value) // Add all points up to first connecting point
                        {
                            nodeCopy = new LinkedListNode <ContourPixel>(currentNode.Value);
                            mergedPiece.Points.AddLast(nodeCopy);
                            currentNode = currentNode.Next;
                        }
                        nodeCopy = new LinkedListNode <ContourPixel>(neighbors[0].Value);
                        mergedPiece.Points.AddLast(nodeCopy); // Add first connecting point
                        currentNode = currentNode.Next;

                        nodeCopy = new LinkedListNode <ContourPixel>(neighbors[1].Value);
                        mergedPiece.Points.AddLast(nodeCopy); // Add second connecting point

                        if (neighbors[1].Next == null)
                        {
                            //Debug.Log("Second piece 1");
                            currentNode = sp2.Points.Last;
                            while (currentNode != null) // Add the rest of the points in the other piece
                            {
                                nodeCopy = new LinkedListNode <ContourPixel>(currentNode.Value);
                                mergedPiece.Points.AddLast(nodeCopy);
                                currentNode = currentNode.Previous;
                            }
                        }
                        else // neighbors[1].Previous == null
                        {
                            //Debug.Log("Second piece 1");
                            currentNode = sp2.Points.First;
                            while (currentNode != null) // Add the rest of the points in the other piece
                            {
                                nodeCopy = new LinkedListNode <ContourPixel>(currentNode.Value);
                                mergedPiece.Points.AddLast(nodeCopy);
                                currentNode = currentNode.Next;
                            }
                        }
                    }
                    else // (n.previous == null)
                    {
                        //Debug.Log("First piece 2");
                        currentNode = sp1.Points.Last;
                        while (currentNode.Value != neighbors[0].Value) // Add all points up to first connecting point
                        {
                            nodeCopy = new LinkedListNode <ContourPixel>(currentNode.Value);
                            mergedPiece.Points.AddLast(nodeCopy);
                            currentNode = currentNode.Previous;
                        }
                        nodeCopy = new LinkedListNode <ContourPixel>(neighbors[0].Value);
                        mergedPiece.Points.AddLast(nodeCopy); // Add first connecting point
                        currentNode = currentNode.Previous;

                        nodeCopy = new LinkedListNode <ContourPixel>(neighbors[1].Value);
                        mergedPiece.Points.AddLast(nodeCopy); // Add second connecting point

                        if (neighbors[1].Next == null)
                        {
                            //Debug.Log("Second piece 2");
                            currentNode = sp2.Points.Last;
                            while (currentNode != null) // Add the rest of the points in the other piece
                            {
                                nodeCopy = new LinkedListNode <ContourPixel>(currentNode.Value);
                                mergedPiece.Points.AddLast(nodeCopy);
                                currentNode = currentNode.Previous;
                            }
                        }
                        else // neighbors[1].Previous == null
                        {
                            //Debug.Log("Second piece 2");
                            currentNode = sp2.Points.First;
                            while (currentNode != null) // Add the rest of the points in the other piece
                            {
                                nodeCopy = new LinkedListNode <ContourPixel>(currentNode.Value);
                                mergedPiece.Points.AddLast(nodeCopy);
                                currentNode = currentNode.Next;
                            }
                        }
                    }
                    //Debug.Log("Added");
                    silhouette.Pieces.Add(mergedPiece);
                }
            }
        }
    }
Exemplo n.º 8
0
    // Takes a contour and draws its silhouette
    public Silhouette DrawSilhouette(Contour contour)
    {
        Silhouette silhouette = new Silhouette(contour.Color);

        int pixelCount = 0;

        ContourPixel dummyPixel = new ContourPixel
        {
            IsDummy = true
        };

        int sX, sY, nX, nY;

        ContourPixel startPixel = FindNextStartPixel(contour, dummyPixel);
        ContourPixel nextPixel  = startPixel;

        bool started;

        //try
        //{

        while (startPixel != null && pixelCount != contour.NumberOfPixels)
        {
            started = false;

            // Add the first pixel of the new silhouette piece
            SilhouettePiece silhouettePiece = new SilhouettePiece();
            silhouettePiece.Points.AddFirst(startPixel);

            sX = startPixel.XCoord;
            sY = startPixel.YCoord;

            nX = startPixel.XCoord;
            nY = startPixel.YCoord;

            // Check if outside window
            //---------------------------------------------------------------------------------------------
            if (VectorUtils.AdjustIteration(contour, nX, nY) == "go-left-or-right")
            {
                //Debug.Log("Over eller under");
                if ((contour.Pixels[nX - 1, nY] != null) && !contour.Pixels[nX - 1, nY].Visited)
                {
                    nX = nX - 1;
                }
                else if ((contour.Pixels[nX + 1, nY] != null) && !contour.Pixels[nX + 1, nY].Visited)
                {
                    nX = nX + 1;
                }
            }
            else if (VectorUtils.AdjustIteration(contour, nX, nY) == "go-up-or-right")
            {
                //Debug.Log("Venstre");
                if ((contour.Pixels[nX, nY + 1] != null) && !contour.Pixels[nX, nY + 1].Visited)
                {
                    nY = nY + 1;
                }
                else if ((contour.Pixels[nX + 1, nY] != null) && !contour.Pixels[nX + 1, nY].Visited)
                {
                    nX = nX + 1;
                }
            }
            else if (VectorUtils.AdjustIteration(contour, nX, nY) == "go-up-or-left")
            {
                //Debug.Log("Høyre");
                if ((contour.Pixels[nX, nY + 1] != null) && !contour.Pixels[nX, nY + 1].Visited)
                {
                    nY = nY + 1;
                }
                else if ((contour.Pixels[nX - 1, nY] != null) && !contour.Pixels[nX - 1, nY].Visited)
                {
                    nX = nX - 1;
                }
            }
            //---------------------------------------------------------------------------------------------

            while (VectorUtils.MoreToDraw(contour, nX, nY) && (!(nX == sX && nY == sY) || !started))
            {
                //previousPixel = nextPixel;

                nextPixel = StepToNextPixel(contour, nX, nY, nextPixel);

                nX = nextPixel.XCoord;
                nY = nextPixel.YCoord;
                pixelCount++;

                silhouettePiece.Points.AddLast(nextPixel);

                started = true;
            }

            startPixel = FindNextStartPixel(contour, startPixel);
            silhouette.Pieces.Add(silhouettePiece);
        }

        /*} catch (Exception e)
         * {
         *  return silhouettes;
         * }*/

        return(silhouette);
    }