4zmy

Transformasi Citra Logaritma

May 5th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.10 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, Math, StdCtrls, Buttons, ExtCtrls, ExtDlgs;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Panel1: TPanel;
  12.     gb1: TImage;
  13.     Label1: TLabel;
  14.     gb2: TImage;
  15.     Label2: TLabel;
  16.     BitBtn1: TBitBtn;
  17.     BitBtn2: TBitBtn;
  18.     Label3: TLabel;
  19.     Label4: TLabel;
  20.     Edit1: TEdit;
  21.     Edit2: TEdit;
  22.     opd: TOpenPictureDialog;
  23.     procedure BitBtn1Click(Sender: TObject);
  24.     procedure BitBtn2Click(Sender: TObject);
  25.     procedure FormShow(Sender: TObject);
  26.   private
  27.     { Private declarations }
  28.   public
  29.     { Public declarations }
  30.   end;
  31.  
  32. var
  33.   Form1: TForm1;
  34.  
  35. implementation
  36.  
  37. {$R *.dfm}
  38.  
  39. procedure TForm1.BitBtn1Click(Sender: TObject);
  40. begin
  41.   if (opd.Execute) then
  42.   gb1.Picture.LoadFromFile(opd.FileName);
  43.   gb2.Picture.LoadFromFile(opd.FileName);
  44. end;
  45.  
  46. procedure TForm1.BitBtn2Click(Sender: TObject);
  47. var
  48.   br,kl, min, max : Integer;
  49.   temp, xmin, xmax, x, c, p: Real;
  50.   dbaris1, dbaris2 : PByteArray;
  51. begin
  52.   min :=0; max :=0;
  53.   c:=StrToFloat(Edit1.Text);
  54.   p:=StrToFloat(Edit2.Text);
  55.   for br := 0 to gb1.Height-1 do
  56.   begin
  57.     for kl := 0 to gb1.Width-1 do
  58.     begin
  59.       dbaris1:= gb1.Picture.Bitmap.ScanLine[br];
  60.       dbaris2:= gb2.Picture.Bitmap.ScanLine[br];
  61.       if (Form1.gb1.Picture.Bitmap.PixelFormat= pf8bit) then
  62.       begin
  63.       if (dbaris1[kl] < min ) then min:=dbaris1[kl];
  64.       if (dbaris1[kl] > max ) then max:=dbaris1[kl];
  65.     end;
  66.     end;
  67.   end;
  68.  
  69.   xmin:= c * Power(min,p);
  70.   xmax:=  Power(max,p);
  71.   for br := 0 to gb1.Height-1 do
  72.   begin
  73.     for kl := 0 to gb1.Width-1 do
  74.     begin
  75.       dbaris1 := gb1.Picture.Bitmap.ScanLine[br];
  76.       dbaris2 := gb2.Picture.Bitmap.ScanLine[br];
  77.  
  78.       if (Form1.gb1.Picture.Bitmap.PixelFormat = pf8bit) then
  79.       begin
  80.         x:= c * Power(dbaris1[kl],p);
  81.         temp:=Round((x-xmin)*(255/xmax));
  82.         if (temp > 255) then dbaris2[kl]:=255;
  83.         if (temp < 0 ) then dbaris2[kl]:=0;
  84.         dbaris2[kl]:=Round(temp);
  85.       end;
  86.     end;
  87.   end;
  88.   gb2.Repaint;
  89. end;
  90.  
  91. end.
Advertisement
Add Comment
Please, Sign In to add comment