Arsip: percepat proses bitmap...

 
user image
more 13 years ago

yadi

Assalamu'alaikum… mau nanya ni..gimana untuk mempercepat proses proses perhitungan pada nilai pixel gambar grayscale yaitu dilakukan proses DCT. Prosesnya agak lama apalagi kalo ukuran gambar sudah agak besar Seperti 128 x 128 pixel..... Dan pada saat proses perhitungan formnya juga kaya hang.... Kasih pencerahan ya...... Thanks....... :D
user image
more 13 years ago

yadi

eh.,,lupa..ni.. saya tuangkan rumus DCT itu ke dalam delphi jadinya,,, banyak loopingnya.... gimana nih biar proses nya cepet ga makan waktu yang lama... thanks.... :D
user image
more 13 years ago

mat_koder

kode pascal anda sebaiknya pake algoritma Fast DCT emangnya looping kode DCT anda ada berapa ?
user image
more 13 years ago

mat_koder

berikut saya kopikan code FastDCT yg pernah saya bikin ( bloknya 8x8 pixel) juga disertakan kode DCT standar - untuk memverifikasi hasil FastDCT

type TBlock = array of Integer;
type PBlock = ^TBlock;

procedure FastDCT8x8(var data:TBlock);
var
  row,col:integer;
  x0,x1,x2,x3,x4,x5,x6,x7,x8 : integer;
begin
  for row:=0 to 7 do
    begin
    x0:=data[row,0];
    x1:=data[row,1];
    x2:=data[row,2];
    x3:=data[row,3];
    x4:=data[row,4];
    x5:=data[row,5];
    x6:=data[row,6];
    x7:=data[row,7];
    // Stage 1  /
    x8:=x7+x0; x0:=x0-x7; x7:=x1+x6; x1:=x1-x6; x6:=x2+x5; x2:=x2-x5; x5:=x3+x4; x3:=x3-x4;
    // Stage 2  /
    x4:=x8+x5; x8:=x8-x5; x5:=x7+x6; x7:=x7-x6;
    x6:=c1(x1+x2); x2:=(-s1-c1) x2+x6; x1:=(s1-c1)x1+x6;
    x6:=c3 (x0+x3); x3:=(-s3-c3)x3+x6; x0:=(s3-c3) x0+x6;
    // Stage 3  /
    x6:=x4+x5; x4:=x4-x5; x5:=x0+x2; x0:=x0-x2; x2:=x3+x1; x3:=x3-x1;
    x1:=r2c6(x7+x8); x7:=(-r2s6-r2c6) x7+x1; x8:=(r2s6-r2c6)x8+x1;
    //  Stage 4 and output /
    data[row,0] := x6;   // data[row][0]=x6;
    data[row,4] := x4;  // data[row][4]=x4;
    data[row,2] := x8 div 1024; // data[row][2]=x8>>10;
    data[row,6] := x7 div 1024; // data[row][6] = x7>>10;
    data[row,7] := (x2-x5) div 1024; // data[row][7]=(x2-x5)>>10;
    data[row,1] := (x2+x5) div 1024; // data[row][1]=(x2+x5)>>10;
    data[row,3] := (x3 r2) div 131072; // data[row][3]=(x3r2)>>17;
    data[row,5] := (x0 r2) div 131072; // data[row][5]=(x0r2)>>17;
    end;
  for col:=0 to 7 do
    begin
    x0:=data[0,col];
    x1:=data[1,col];
    x2:=data[2,col];
    x3:=data[3,col];
    x4:=data[4,col];
    x5:=data[5,col];
    x6:=data[6,col];
    x7:=data[7,col];
    //  Stage 1 /
    x8:=x7+x0; x0:=x0-x7; x7:=x1+x6; x1:=x1-x6; x6:=x2+x5; x2:=x2-x5; x5:=x3+x4; x3:=x3-x4;
    //  Stage 2 /
    x4:=x8+x5; x8:=x8-x5; x5:=x7+x6; x7:=x7-x6;
    x6:=c1 (x1+x2); x2:=(-s1-c1)x2+x6; x1:=(s1-c1) x1+x6;
    x6:=c3(x0+x3); x3:=(-s3-c3) x3+x6; x0:=(s3-c3)x0+x6;
    //  Stage 3 /
    x6:=x4+x5; x4:=x4-x5; x5:=x0+x2; x0:=x0-x2; x2:=x3+x1; x3:=x3-x1;
    x1:=r2c6 (x7+x8); x7:=(-r2s6-r2c6)x7+x1; x8:=(r2s6-r2c6) x8+x1;
    // Stage 4 and output  /
    data[0,col] := (x6+16) div 32; // data[0][col]=(x6+16)>>5;
    data[4,col] := (x4+16) div 32; // data[4][col]=(x4+16)>>5;
    data[2,col] := (x8+16384) div 32768; // data[2][col]=(x8+16384)>>15;
    data[6,col] := (x7+16384) div 32768; // data[6][col]=(x7+16384)>>15;
    data[7,col] := (x2-x5+16384) div 32768; // data[7][col]=(x2-x5+16384)>>15;
    data[1,col] := (x2+x5+16384) div 32768; // data[1][col]=(x2+x5+16384)>>15;
    data[3,col] := ((x3 div 256)r2+8192) div 16384; // data[3][col]=((x3>>8) r2+8192)>>14;
    data[5,col] := ((x0 div 256)r2+8192) div 16384; // data[5][col]=((x0>>8) r2+8192)>>14;
    end;
  end;
end;

// proc berikut ini dipakai untuk men-cek keakuratan procedure fastDCT
procedure Slowdct8x8(var data:TBlock);
var
  output : array of double;
  i,j,x,y,n,m:integer;
begin
  for i:=0 to 7 do
     for j:=0 to 7 do
        output[i,j]:=0.0;
  for y:=0to 7 do
    for x:=0 to 7 do
      for n:=0 to 7 do
	for m:=0 to 7 do
	  output[y,x] := output[y,x] + data[n,m]
	     cos(PI   x  (2 m+1)/16.0)  cos(PI   y  (2 n+1)/16.0);
  for y:=0 to 7 do
      for x:=0 to 7 do
        begin
	if(x=0) then output[y][x] := output[y][x]/sqrt(2);
	if(y=0) then output[y][x] := output[y][x]/sqrt(2);
	data[y][x] := trunc(output[y][x]/16 + 0.5);
        end;
  end;
user image
more 13 years ago

mat_koder

hmm sorrry... kurang lengkap

procedure FastDCT8x8(var data:TBlock);
var
  row,col:integer;
  x0,x1,x2,x3,x4,x5,x6,x7,x8 : integer;
  temp : array of integer;
begin
  for row:=0 to 7 do
    begin
    x0:=data[row,0];
    x1:=data[row,1];
    x2:=data[row,2];
    x3:=data[row,3];
    x4:=data[row,4];
    x5:=data[row,5];
    x6:=data[row,6];
    x7:=data[row,7];
    // Stage 1  /
    x8:=x7+x0; x0:=x0-x7; x7:=x1+x6; x1:=x1-x6; x6:=x2+x5; x2:=x2-x5; x5:=x3+x4; x3:=x3-x4;
    // Stage 2  /
    x4:=x8+x5; x8:=x8-x5; x5:=x7+x6; x7:=x7-x6;
    x6:=c1(x1+x2); x2:=(-s1-c1) x2+x6; x1:=(s1-c1)x1+x6;
    x6:=c3 (x0+x3); x3:=(-s3-c3)x3+x6; x0:=(s3-c3) x0+x6;
    // Stage 3  /
    x6:=x4+x5; x4:=x4-x5; x5:=x0+x2; x0:=x0-x2; x2:=x3+x1; x3:=x3-x1;
    x1:=r2c6(x7+x8); x7:=(-r2s6-r2c6) x7+x1; x8:=(r2s6-r2c6)x8+x1;
    //  Stage 4 and output /
    data[row,0] := x6;   // data[row][0]=x6;
    data[row,4] := x4;  // data[row][4]=x4;
    data[row,2] := x8 div 1024; // data[row][2]=x8>>10;
    data[row,6] := x7 div 1024; // data[row][6] = x7>>10;
    data[row,7] := (x2-x5) div 1024; // data[row][7]=(x2-x5)>>10;
    data[row,1] := (x2+x5) div 1024; // data[row][1]=(x2+x5)>>10;
    data[row,3] := (x3 r2) div 131072; // data[row][3]=(x3r2)>>17;
    data[row,5] := (x0 r2) div 131072; // data[row][5]=(x0r2)>>17;
    end;
  for col:=0 to 7 do
    begin
    x0:=data[0,col];
    x1:=data[1,col];
    x2:=data[2,col];
    x3:=data[3,col];
    x4:=data[4,col];
    x5:=data[5,col];
    x6:=data[6,col];
    x7:=data[7,col];
    //  Stage 1 /
    x8:=x7+x0; x0:=x0-x7; x7:=x1+x6; x1:=x1-x6; x6:=x2+x5; x2:=x2-x5; x5:=x3+x4; x3:=x3-x4;
    //  Stage 2 /
    x4:=x8+x5; x8:=x8-x5; x5:=x7+x6; x7:=x7-x6;
    x6:=c1 (x1+x2); x2:=(-s1-c1)x2+x6; x1:=(s1-c1) x1+x6;
    x6:=c3(x0+x3); x3:=(-s3-c3) x3+x6; x0:=(s3-c3)x0+x6;
    //  Stage 3 /
    x6:=x4+x5; x4:=x4-x5; x5:=x0+x2; x0:=x0-x2; x2:=x3+x1; x3:=x3-x1;
    x1:=r2c6 (x7+x8); x7:=(-r2s6-r2c6)x7+x1; x8:=(r2s6-r2c6) x8+x1;
    // Stage 4 and output  /
    data[0,col] := (x6+16) div 32; // data[0][col]=(x6+16)>>5;
    data[4,col] := (x4+16) div 32; // data[4][col]=(x4+16)>>5;
    data[2,col] := (x8+16384) div 32768; // data[2][col]=(x8+16384)>>15;
    data[6,col] := (x7+16384) div 32768; // data[6][col]=(x7+16384)>>15;
    data[7,col] := (x2-x5+16384) div 32768; // data[7][col]=(x2-x5+16384)>>15;
    data[1,col] := (x2+x5+16384) div 32768; // data[1][col]=(x2+x5+16384)>>15;
    data[3,col] := ((x3 div 256)r2+8192) div 16384; // data[3][col]=((x3>>8) r2+8192)>>14;
    data[5,col] := ((x0 div 256)r2+8192) div 16384; // data[5][col]=((x0>>8) r2+8192)>>14;
    end;
// ZIG-ZAG arrangement 
    Temp[0]:=data[0,0];
    Temp[1]:=data[0,1];
    Temp[2]:=data[1,0];
    Temp[3]:=data[2,0];
    Temp[4]:=data[1,1];
    Temp[5]:=data[0,2];
    Temp[6]:=data[0,3];
    Temp[7]:=data[1,2];
    Temp[8]:=data[2,1];
    Temp[9]:=data[3,0];
    Temp[10]:=data[4,0];
    Temp[11]:=data[3,1];
    Temp[12]:=data[2,2];
    Temp[13]:=data[1,3];
    Temp[14]:=data[0,4];
    Temp[15]:=data[0,5];
    Temp[16]:=data[1,4];
    Temp[17]:=data[2,3];
    Temp[18]:=data[3,2];
    Temp[19]:=data[4,1];
    Temp[20]:=data[5,0];
    Temp[21]:=data[6,0];
    Temp[22]:=data[5,1];
    Temp[23]:=data[4,2];
    Temp[24]:=data[3,3];
    Temp[25]:=data[2,4];
    Temp[26]:=data[1,5];
    Temp[27]:=data[0,6];
    Temp[28]:=data[0,7];
    Temp[29]:=data[1,6];
    Temp[30]:=data[2,5];
    Temp[31]:=data[3,4];
    Temp[32]:=data[4,3];
    Temp[33]:=data[5,2];
    Temp[34]:=data[6,1];
    Temp[35]:=data[7,0];
    Temp[36]:=data[7,1];
    Temp[37]:=data[6,2];
    Temp[38]:=data[5,3];
    Temp[39]:=data[4,4];
    Temp[40]:=data[3,5];
    Temp[41]:=data[2,6];
    Temp[42]:=data[1,7];
    Temp[43]:=data[2,7];
    Temp[44]:=data[3,6];
    Temp[45]:=data[4,5];
    Temp[46]:=data[5,4];
    Temp[47]:=data[6,3];
    Temp[48]:=data[7,2];
    Temp[49]:=data[7,3];
    Temp[50]:=data[6,4];
    Temp[51]:=data[5,5];
    Temp[52]:=data[4,6];
    Temp[53]:=data[3,7];
    Temp[54]:=data[4,7];
    Temp[55]:=data[5,6];
    Temp[56]:=data[6,5];
    Temp[57]:=data[7,4];
    Temp[58]:=data[7,5];
    Temp[59]:=data[6,6];
    Temp[60]:=data[5,7];
    Temp[61]:=data[6,7];
    Temp[62]:=data[7,6];
    Temp[63]:=data[7,7];
    MoveMemory(@data[0,0],@temp[0],64);
  end;
user image
more 13 years ago

yadi

thank's ya...mas @mat_koder wah banyak nih..dapet hal2 yang baru... btw ini dah hasil ku wat DCT in delphi.....he..he.. ada comment ga nih.. ta tunggu ya....

unit UnitDCT2;
interface
uses Unitutama,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
     Dialogs, ExtCtrls, ComCtrls, Buttons, StdCtrls, ExtDlgs;
function HDCT(A : PMatrik): PMatrik;
implementation
function HDCT(A : PMatrik): PMatrik;
var
u,v,x,y,baris,kolom : integer;
c1, c2, jumlah : real;
DCT : PMatrik;
begin
setlength(DCT,length(A),length(A[0]));
   for u := 0 to length(A) - 1 do
    begin
     for v := 0 to length(A[0])-1 do
      begin
       DCT[u,v] := 0;
      end;
    end;
baris := length(A);
kolom := length(A[0]);
jumlah := 0;
for u := 0 to baris -1 do
 begin
  for v := 0 to kolom - 1 do
   begin
    for x := 0 to baris  - 1 do
     begin
      for y := 0 to kolom - 1 do
       begin
        if u = 0 then
        begin
           c1 := 1/sqrt(baris)
        end
        else
        begin
           c1 := sqrt(2/baris);
        end ;
        if v = 0 then
        begin
           c2 := 1/sqrt(kolom)
        end
        else
        begin
          c2 := sqrt(2/kolom);
        end;
               jumlah:=jumlah + c1c2 A[x,y]cos((2 x+1)pi u/(2baris)) cos((2y+1) piv/(2 kolom));
       end;
     end;
     DCT[u,v] := jumlah;
     jumlah := 0;
    end;
 end;
 HDCT := DCT;
end;
end.
:D
user image
more 13 years ago

mat_koder

- pantesan waktu eksekusi anda lama......... pake kode yg diturunin langsung dari rumus matematik sih... coba baca-baca artikel mengenai Fast DCT . Kelebihan Fast DCT terhadap standar DCT dalam hal kecepatan eksekusi adalah : - Fast DCT menggunakan integer operation sedangkan DCt menggunakan floating point. - Fast DCT mengeliminasi banyaknya looping yg diperlukan ( banyak operasi simetris dapat direduksi menjadi lebih sedikit).
user image
more 13 years ago

yadi

mas @mat_koder boleh nanya lagi nih,, kalo untuk optimasi atao untuk mempercepat proses dari fungsi DCT2 diatas itu biar ga banyak looping tapi hasilnya akhirnya benar bisa ga??? atau ada ga cara lain untuk mempercepat proses eksekusinya...maklum aku newbie sih.. mohon pencerahannya ya... di tunggu nih.. thanks.......
user image
more 13 years ago

mat_koder

cari di rumah Oom Google artikel mengenai optimasi DCT... tapi emang banyaknya dlm bhs Inggris sih...
more ...
  • Pages:
  • 1
Share to
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com