Einzelnen Beitrag anzeigen

Flips

Registriert seit: 17. Feb 2005
Ort: Sankt Wendel
491 Beiträge
 
Delphi 7 Professional
 
#1

Pixels vs. Scanline. Seltsames Ergebnis...

  Alt 9. Nov 2005, 15:34
Hi @ all.

Bin an nem Programm welches Bilder vergleicht. In sehr vielen Thread´s und Post´s wird erwähnt das die Scanline Methode sehr viel schneller sei als die Pixels[x,y] Methode. Allerdings habe ich ein erstaunliches Ergebnis. Hier die Zeiten für den Vergleich von:

Bildergröße: 160*120 Pixel = 19600 Pixel

Zitat:
Scanline

Zeit/ms Unterschiede/Pixel
453 5355
453 5332
453 5538
469 5738

Pixels

Zeit/ms Unterschiede/Pixel
94 5595
78 5572
78 5560
79 5468
Irgendwie ist die Canvas.Pixels Methode um Meilen schneller als Scanline. Hier der Code:

Delphi-Quellcode:
//Scanline
procedure CompareImagesWithScanline(Image1,Image2:TBitmap);
var line1,line2 : PByteArray;
    x,y : integer;
    differents : integer;
const max = 3;
begin
Zeit1 := GetTickCount;
differents := 0;
 for y := 0 to Image1.Height -1 do
 begin
  line1 := Image1.ScanLine[y];
  line2 := Image2.ScanLine[y];
   for x := 0 to Image1.Width -1 do
     if abs(line1[x]-line2[x]) > max then
     inc(differents);
 end;

Zeit2 := GetTickCount;
Form1.ListBox1.Items.Add(IntToStr(Zeit2-Zeit1));
Form1.ListBox2.Items.Add(IntToStr(differents));
end;


//Pixels
procedure CompareImagesWithPixels(Image1,Image2:TBitmap);
var x,y: integer;
Pixel1, Pixel2: Byte;
differents: integer;

const max = 3;
begin
Zeit1 := GetTickCount;
differents := 0;
 for y := 0 to Image1.Height -1 do
   for x := 0 to Image1.Width -1 do
    begin
    Pixel1 := Image1.Canvas.Pixels[x,y];
    Pixel2 := Image2.Canvas.Pixels[x,y];
     if abs(Pixel2-Pixel1) > max then
     inc(differents);
    end;
Zeit2 := GetTickCount;
Form1.ListBox1.Items.Add(IntToStr(Zeit2-Zeit1));
Form1.ListBox2.Items.Add(IntToStr(differents))
end;
Wisst ihr wieso das so ist???
Bin jetzt vollkommen verwirrt.

Mfg Flips
Philipp F.
  Mit Zitat antworten Zitat