Nadesłany przez Tomasz Lubiński, 07 września 2005 01:00
Kod przedstawiony poniżej przedstawia główną część rozwiązania problemu.Pobierz pełne rozwiązanie.
Jeżeli nie odpowiada Ci sposób formatowania kodu przez autora skorzystaj z pretty printer'a i dostosuj go automatycznie do siebie.
sin - Delphi/Unit1.pas:
//Tomasz Lubiński (C)2005 //www.algorytm.org //Modulowanie progu sygnalem szumu unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls; type TForm1 = class(TForm) Image1: TImage; Label1: TLabel; Image2: TImage; Image3: TImage; Label2: TLabel; Label3: TLabel; Label4: TLabel; Edit1: TEdit; Button1: TButton; UpDown1: TUpDown; GroupBox1: TGroupBox; Label7: TLabel; Label5: TLabel; Label6: TLabel; Label8: TLabel; RadioButton1: TRadioButton; RadioButton2: TRadioButton; Edit4: TEdit; Edit3: TEdit; Edit2: TEdit; Edit5: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); var i,j,p,zakres: Integer; color: TColor; alfa, beta, A: Real; begin Randomize(); p := StrToInt(Form1.Edit1.Text); alfa := StrToFloat(Form1.Edit2.Text); beta := StrToFloat(Form1.Edit3.Text); A := StrToFloat(Form1.Edit4.Text); zakres := StrToInt(Form1.Edit5.Text); //zwykle progowe for j:=0 to 229 do for i:=0 to 247 do begin color := Form1.Image1.Canvas.Pixels[i,j]; if (p>GetRValue(color)) then Form1.Image2.Canvas.Pixels[i,j] := clBlack else Form1.Image2.Canvas.Pixels[i,j] := clWhite; end; //modulowanie progu sygnalem szumu if RadioButton1.Checked then begin for j:=0 to 229 do for i:=0 to 247 do begin color := Form1.Image1.Canvas.Pixels[i,j]; if ((p+A*sin(3.14*alfa*i/180)*sin(3.14*beta*j/180))>GetRValue(color)) then Form1.Image3.Canvas.Pixels[i,j] := clBlack else Form1.Image3.Canvas.Pixels[i,j] := clWhite; end; end else begin for j:=0 to 229 do for i:=0 to 247 do begin color := Form1.Image1.Canvas.Pixels[i,j]; if ((p+random(2*zakres)-zakres)>GetRValue(color)) then Form1.Image3.Canvas.Pixels[i,j] := clBlack else Form1.Image3.Canvas.Pixels[i,j] := clWhite; end; end; end; end.