AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi Zusammenhängene Pixel zählen
Thema durchsuchen
Ansicht
Themen-Optionen

Zusammenhängene Pixel zählen

Ein Thema von Eichhoernchen · begonnen am 1. Jul 2006 · letzter Beitrag vom 5. Jul 2006
 
Eichhoernchen

Registriert seit: 22. Apr 2004
Ort: Hagen
322 Beiträge
 
Turbo Delphi für Win32
 
#1

Zusammenhängene Pixel zählen

  Alt 1. Jul 2006, 23:25
Hi, ich hatte vor eine function zu schreiben, die aus einem schwarz/weiß Bild alle Stücke heraus löscht, bei denen die Anzahl der zusammenhängenden schwarzen Pixel kleiner als 100 ist.

Ich hab mir dass folgender maßen gedacht, ein array of array of TPoint;
Die 1. Array dimension gibt den Pixelbrocken an, und in die 2. Dimension werden dann alle TPoint Werte des Pixelbrockens gespeichert.

Ich habe mir jetzt folgenden Code zusammengedacht aber leider klappt es nicht jedoch weiß ich auch nicht wo ich einen Fehler gemacht hab, also bitte helft mir(ich glaube bei der Verwendung von setlength, bin aber nicht sicher)

Delphi-Quellcode:
function killsmallareas(bmp : TBitmap) : TBitmap;
var i, j, k, l : integer;
    Polygones : array of array of TPoint;
    found : boolean;
Begin
result := TBitmap.Create;
result.Width := bmp.Width;
result.Height := bmp.Height;
result.PixelFormat := bmp.PixelFormat;
SetLength(polygones, 1, 1);
 for i := 0 to bmp.Width - 1 do
  for j := 0 to bmp.Height - 1 do
   Begin
    if bmp.Canvas.Pixels[i, j] = clblack
      then Begin
            with bmp.Canvas do
             Begin
               if (Pixels[i-1, j] = clblack) or (Pixels[i-1, j-1] = clblack)
               or (Pixels[i, j-1] = clblack) or (Pixels[i+1, j-1] = clblack)
               or (Pixels[i+1, j] = clblack) or (Pixels[i+1, j+1] = clblack)
               or (Pixels[i, j+1] = clblack) or (Pixels[i-1, j+1] = clblack)
                 then Begin
                       k := 0;
                       found := false;
                       while ( k < high(polygones)) and (found = false) do
                        Begin
                         l := 0;
                         while ( l < high(polygones[k])) and ( not(PointsEqual(polygones[k, l], Point(i-1, j)))
                          or not(PointsEqual(polygones[k, l], Point(i-1, j-1))) or not(PointsEqual(polygones[k, l], Point(i, j-1)))
                          or not(PointsEqual(polygones[k, l], Point(i+1, j-1))) or not(PointsEqual(polygones[k, l], Point(i+1, j)))
                          or not(PointsEqual(polygones[k, l], Point(i+1, j+1))) or not(PointsEqual(polygones[k, l], Point(i, j+1)))
                          or not(PointsEqual(polygones[k, l], Point(i-1, j+1))) ) do inc(l);
                         if l < high(polygones[k]) then found := true;
                         inc(k);
                        end;
                        if found
                          then Begin
                                dec(k);
                                SetLength(polygones[k], high(polygones[k])+1);
                                polygones[k, high(polygones[k])] := Point(i, j);
                               end
                          else Begin
                                setlength(polygones, high(polygones)+1);
                                setlength(polygones[high(polygones)], 1);
                                polygones[high(polygones), 0] := Point(i, j);
                               end;
                      end;
             end;
           end;
   end;
   for k := 0 to High(polygones) do
     if high(polygones[k]) > 100
       then for l := 0 to high(polygones[k]) do
             result.Canvas.Pixels[polygones[k, l].X, polygones[k, l].Y] := clblack;
end;

Ich hoffe man steigt durch den Code durch.


Vielen Dank schonmal für eure Antworten!
Jan
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:30 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz