Senin, 18 Mei 2009

Sintaks Deteksi Batas dengan Delphi

Deteksi batas adalah suatu teknik pengolahan citra yang bertujuan untuk mendapatkan obyek citra tepat pada batas obyek tersebut. Teknik ini bekerja pada citra biner dengan menjelajahi citra, misalnya dari bagian atas. Jika baris pertama paling atas semua piksel berwarna putih, maka ukuran tinggi citra dipotong pada bagian baris tersebut. Pemotongan tinggi citra berakhir bila ada ditemukan piksel berwarna hitam. Pemotongan juga dilakukan dari sisi bawah, kiri dan kanan. Gambar 2.8 berikut ini ilustrasinya (abaikan garis hitam yang membatasi lebar dan tinggi citra) :
(a)



(b)
Gambar Ilustrasi deteksi batas (a) citra awal, (b) citra hasil deteksi batas.

Berikut adalah Sintaks Deteksi Batas dengan Delphi



procedure Tform1.DeteksiBatas(Image:TBitmap);
var
x,y:Integer;
Arr:array of Boolean;
Temp,Max,TempStart,Start,TempFinish, Tempo:Integer;
begin
SetLength(Arr,Image.Height);
for y:=0 to Image.Height-1 do
begin
Arr[y]:=False;
for x:=0 to Image.Width-1 do
if Image.Canvas.Pixels[x,y]<>$ffffff then
begin
Arr[y]:=True;
end;
end;

Max:=0;
Temp:=0;
Tempo:=0;

for y:=0 to Length(Arr)-1 do
begin
if Arr[y] then
begin
if Tempo=0 then
begin
TempStart:=y;
end else
if Temp>Max then
begin
Max:=Temp;
Start:=TempStart;
TempFinish:=y;
end else if Temp=Max then
begin
Max:=Temp;
Start:=TempStart;
TempFinish:=y;
end;
inc(Tempo);
end;
inc(Temp);
end;
Temp:=TempFinish-TempStart;
Image.Canvas.Draw(0,-start,Image);
Image.Height:=Temp+1;

SetLength(Arr,Image.Width);
for x:=0 to Length(Arr)-1 do
begin
Arr[x]:=False;
for y:=0 to Image.Height-1 do if Image.Canvas.Pixels[x,y]<>$FFFFFF then
begin
Arr[x]:=True;
end;
end;
Max:=0;
Temp:=0;
Tempo:=0;

for x:=0 to Length(Arr)-1 do
begin
if Arr[x] then
begin
if Tempo=0 then
begin
TempStart:=x;
end else
if Temp>Max then
begin
Max:=Temp;
Start:=TempStart;
TempFinish:=x;
end else if Temp=Max then
begin
Max:=Temp;
Start:=TempStart;
TempFinish:=x;
end;
inc(Tempo);
end;
inc(Temp);
end;
Temp:=TempFinish-TempStart;
Image.Canvas.Draw(-Start,0,Image);
Image.Width:=Temp+1;
end;


Pass PHP Variable in Javascript Link to do Redirecting

If we using PHP GET Method, sometime we we use the URL to pass the variable. In some kind of application maybe we need a redirecting.

Below is a dynamic redirecting using PHP and Javascript. See The Source Code below



echo '<script type="text/javascript">
<!--
window.location = "barang.php
?cbogudang='.$data1[kdgudang].'&pilih=pilih"
//-->
</script>';



This kind of redirecting can be use after insert delete or update a master data. After the insert, delete, or update the data, we can direcly view the table.

This source code from dynamicdrive.com

Kamis, 14 Mei 2009

Metode Sampul dan Proyeksi pada Citra Digital

Metode sampul dan proyeksi (Envelope and Projection Profiles Method) cocok digunakan untuk pengenalan tandatangan dan tulisan tangan.

Metode sampul terdiri dari 2 yaitu sampul atas dan sampul bawah. Sampul atas adalah kurva yang menghubungkan piksel-piksel paling atas lintasan obyek atau citra, sedangkan sampul bawah menghubungkan piksel-piksel paling bawah lintasan obyek atau citra.

Metode proyeksi adalah gabungan proyeksi vertikal dan proyeksi horizontal dari citra. Ciri proyeksi vertikal didapatkan dari jumlah piksel setiap kolom panjang citra. Ciri proyeksi horizontal didapatkan dari jumlah piksel setiap baris lebar citra.

Generate Image from E-mail Text with PHP

I wonder how to generate a image from email text with PHP. Sometimes people need imaging their e-mail addres in a webpage to ensure that their e-mail address doesn't detected by bad bots or robots that can sends thousand of spams or unwanted e-mail.

One of the effective way is making a image as our e-mail address. But how we can make that..?
Here is the simple source code to generate a image from string input with PHP.



<?php
header("Content-type: image/png");
// Your email address which will be shown in the image
$email = "you@yourdomain.com";
$length = (strlen($email)*8);
$im = @ImageCreate ($length, 20)
or die ("Kann keinen neuen GD-Bild-Stream erzeugen");
$background_color = ImageColorAllocate ($im, 255, 255, 255);
// White: 255,255,255
$text_color = ImageColorAllocate ($im, 55, 103, 122);
imagestring($im, 3,5,2,$email, $text_color);
imagepng ($im);
?>



the principal code above are
  • @ImageCreate
  • imagestring and
  • imagepng.

Rabu, 13 Mei 2009

Pemrograman Client Server Winsock untuk Chatting

Pemrograman Winsock adalah pemrograman yang berbasis Client - Server. Ada yang memanfaatkan TCP (connection oriented) ataupun UDP (Connectionless).

Banyak aplikasi menggunakan aplikasi client server, dan kita tidak sadar menggunakan dalam kehidupan sehari-hari diantaranya :

  • Pembayaran Online Bank, Listrik
  • Game Online
Berikut sebuah contoh dari FreeVBCode

Server dan Client chat dalam percobaannya ada pada 1 komputer.

(Gambar 1. Server)

(Gambar 2 Client)


Selasa, 12 Mei 2009

Membuat Form berisi CAPTCHA dengan PHP

Selama kuliah, ternyata saya melewatkan pembuatan untuk modul pendaftaran yang sering dilakukan mahasiswa lain dalam pemrograman PHP..

Tapi tiada waktu terlambat buat belajar dan mencoba. Tutorial aslinya berasal dari http://www.html-form-guide.com/contact-form/html-contact-form-captcha.html

Pertama sediakan sebuah form HTML, ini hanya Sintaks HTML biasa


<HTML>
<HEAD><title>Contact Form</title></HEAD>
<BODY>
<form method="POST" name="contact_form" action="result.php">
Enter Name: <input type="text" name="name"><br>
Enter Message: <textarea name="message"></textarea><br>
<img src="captcha_code_file.php" /><br>
Enter captcha Code Here :
<input id="6_letters_code" name="6_letters_code" type="text" ><br>
<input type="submit" value="Submit"><br>
</form>
</BODY>
</HTML>

File yang diperlukan lalu letakkkan file di folder yang sama (File HTML, captcha_code_file.php, Font Pendukung dan result.php). File dapat didownload
http://www.html-form-guide.com/contact-form/html-contact-form-captcha.zip

Oh ya, rename aja html_contac_form_proc.php dengan result.php

Test setelah itu dengan melihat di Localhost hasilnya..



adapun pengolahan terdapat di file result.php

<?php
session_start();
if( $_SESSION['6_letters_code'] == $_POST['6_letters_code'] && !empty($_SESSION['6_letters_code'] ) ) {
$to = "RecipientEmail@domain.com";
$email_subject = "This is the email subject";
$name = $_POST['name'];
$message = $_POST['message'];
$email_body = "You have received a new messag from " . $name . ". Here is the message: " . $message;
mail($to, $email_subject, $email_body);
echo 'You entered the correct code. Your message is successfully emailed.';
} else {
echo "Sorry, you have provided an invalid security code.
Please <a href='contact_form_with_captcha.html'>CLICK HERE</a> to try again.";
}
?>

  • Session harus disertakan untuk mem-post karakter,
  • Sintaks email dapat diabaikan
  • jika benar, maka proses dapat dilanjutkan sebaliknya jika salah akan muncul pesan kesalahan "Sorry, you have provided an invalid security code"

Minggu, 03 Mei 2009

Grayscale Image Processing and Source Code In Delphi

Hi Friend. Do You need Source Code of Image Processing..? But I’m only have in Delphi Programming. It is easy to Follow and Understand.

Pixel in Grayscale Image Basically obtain from dividing by three the Red + Green + Blue Pixels. Or the sum of Component Red + Green + Blue Must be One (1).
Example : 0.33 * R + 0.33 G + 0.33 B


Below is Source Code for Grayscale Image Processing in Delphi.


procedure TForm1.ToolButtonGrayscaleClick(Sender: TObject);
var
i, j : integer;
Grey : Integer;
PH : PByteArray;
begin
for i:=0 to FormHasil.ImgHasil.Height-1 do
begin
PH:=FormHasil.ImgHasil.Picture.Bitmap.ScanLine[i];
for j:=0 to FormHasil.ImgHasil.Width-1 do
begin
Grey := Round ((PH[3*J] + PH[3*J+1] + PH[3*J+2] ) / 3);
PH[3*j]:= Grey;
PH[3*j+1]:= Grey;
PH[3*j+2]:= Grey;
end;
end;
FormHasil.ImgHasil.Repaint;
FormHistogram.Histogram;
end;



Please Comment If I’m Wrong. Comment are widely open…!!

Contrast Image Processing and Source Code in Delphi

Hi Friend. Do You need Source Code of Image Processing..? But I’m only have in Delphi Programming. It is easy to Follow and Understand.

Contrast manipulation is widely use in image processing. We give a value to the procedure to change the Contrast. Positive value mean increase Contrast and negative value mean decrease Contrast.

(1. Normal Image)

(2. Increase Contrast, Histogram Spread)

(3. Decrease Contrast, Histogram Collect)

Below is Source Code for Contrast Image Processing in Delphi.


Procedure TFormBright_Con.Contrast(N:integer);
var
i, j: integer;
Rcon,Gcon,Bcon : integer;
PH:PByteArray;
begin
for i := 0 to FormHasil.ImgHasil.Picture.Height-1 do
begin
PH:= FormHasil.ImgHasil.Picture.Bitmap.ScanLine[i];
for j:= 0 to FormHasil.ImgHasil.Picture.Width-1 do
begin
Rcon:= Round((PH[3*j]/255)*(255-(2*N))+ N);
Gcon:= Round((PH[3*j+1]/255)*(255-(2*N))+ N);
Bcon:= Round((PH[3*j+2]/255)*(255-(2*N))+ N);

if Rcon >255 Then Rcon:=255
else if Rcon<0 Then Rcon:=0;
if Gcon>255 then Gcon:=255
else if Gcon<0 Then Gcon:=0;
if Bcon>255 then Bcon:=255
else if Bcon<0 Then Bcon:=0;

PH[3*j] := Rcon;
PH[3*j+1] := Gcon;
PH[3*j+2] := Bcon;

end;
end;
end;




Please pass the value from SpinEdit Maybe or by TrackBar or manualy by Edit.

Example :

Contrast (TrackBar.Position);

Please Comment If I’m Wrong. Comment are widely open…!!