FloodFill Konturpunkte umwandeln zu Linien



  • Hallo Leute,
    ich bräuchte mal eure Geistige Unterstützung.
    Es geht um folgendes ich habe den Flood Fill Algorithmus implementiert und möchte jetzt gerne die Kontur der gefluteten Region zeichnen.

    Meide Idee ist ab Zeile 37 verewigt:

    stack.Push(pt);
                Point prevPoint;
                while (stack.isEmpty() == false)
                {
                    Point n = stack.pop();
                    int x = n.X;
                    int y = n.Y;
                    if (x >= 0 && x < image.getWidth() && y >= 0 && y < image.getHeight())
                    {
                        char* currentPixel = image.getRGBAAsArray(x, y);
                        if (!HasPixelSameProperty(currentPixel, rgba))
                        {
                            if (HasPixelSameProperty(currentPixel, targetColor))
                            {
                                prevPoint = n;
                                image.setRGBA(x, y, r, g, b, a);
    
                                stack.push( Point(x, y + 1));
                                stack.push( Point(x, y - 1));
                                stack.push( Point(x + 1, y));
                                stack.push( Point(x - 1, y));
                                stack.push( Point(x + 1, y + 1));
                                stack.push( Point(x + 1, y - 1));
                                stack.push( Point(x - 1, y + 1));
                                stack.push( Point(x - 1, y - 1));
                            }
                            else
                            {
    
                                pointList.push_back(prevPoint);
                            }
                        }
                    }
    
                }
                for(int i =0; i < pointList.size(); i++)
                {
                       Point p = pointList[i];
                       int x = p.X;
                       int y = p.Y;
                       image.setRGBA(x, y, 111, 156, 156, 255);
                }
    

    Pixelweise sieht das zwar gut aus, ich würde aber gerne die Punktmenge in Linien umwandeln, hat dazu jemand eine Idee bzw. einen Algorithmus Namen.

    Grüße



  • Was verstehst du unter "in Linie umwandeln"?
    Du hast eine Liste von Punkten, welche die Umrandung darstellen. Was willst du mehr?



  • Die Kontur als Polygonzug



  • ?Algo? schrieb:

    Die Kontur als Polygonzug

    such nach Chain Codes, dabei wird die Kontur angegeben als Liste von Richtungen (Norden, Nordost, ...) sowie den Längen der Polygon-Abschnitte.


Anmelden zum Antworten