Source Code Metode Transformasi Wavelet Haar dengan PHP |
<?php
set_time_limit(0);
class metodeWaveletHaar{
public $fid = null;
public $jenisCitra = null;
public $imageCari = null;
public $folder = null;
public $img = null;
public $imgX = null;
public $imgY = null;
public $pixelCitraRedDiambil = null;
public $pixelCitraGreenDiambil = null;
public $pixelCitraBlueDiambil = null;
public $pixelCitraGrayDiambil = null;
public $pixelCitraGanjil = null;
public $pixelCitraGenap = null;
public $jenisPixelCitraGenap = null;
public $totalImg = 0;
public $tampilkanPerhitungan = false;
public function setFolder($dir){
return $this->folder = $dir;
}
public function openFileOrFolder($dir,$typeImg,$tampil,$jenis,$imageCari){
$this->jenisCitra = $jenis;
$this->imageCari = $imageCari;
$this->tampilkanPerhitungan = $tampil;
if(empty($typeImg)){
$this->setFolder($dir); /*Mendefinisikan Lokasi Folder*/
foreach(glob($this->folder.'*.*') as $img){
$this->img = $dir;
$this->ambilPexelCitra($typeImg);
$this->totalImg++;
}
}else{
$this->img = $dir;
$this->ambilPexelCitra($typeImg);
}
}
public function total(){
return $this->totalImg; /*Banyaknya Citra pada Folder*/
}
public function ambilPexelCitra($typeImg){
switch($typeImg){
case "png" : $imgPixel = imagecreatefrompng($this->img); break;
default : $imgPixel = imagecreatefromjpeg($this->img); break;
}
$this->imgX = imagesx($imgPixel);
$this->imgY = imagesy($imgPixel);
for($x=0;$x<$this->imgX;$x++){ /*Lebar Citra*/
for($y=0;$y<$this->imgY;$y++){
$index = imagecolorat($imgPixel, $x, $y);
$rgb = imagecolorsforindex($imgPixel, $index);
$pixelCitraRed[] = $rgb['red'];
$pixelCitraGreen[] = $rgb['green'];
$pixelCitraBlue[] = $rgb['blue'];
$pixelCitraGray[] = round((array_sum($rgb)/3),4);
}
$this->pixelCitraGrayDiambil = implode(",",$pixelCitraGray);
}
}
public function tampilPexelCitra($pixelCitraDiambil){
$pixelBarisCitra = explode(",",$pixelCitraDiambil);
$p = 0; $n=-1;
for($i=0;$i<$this->imgY;$i++){
$p = $p+$this->imgX;
if($i<$this->imgY){
for($j=$p;$j<$p+$this->imgX;$j++){
$n++;
if($this->tampilkanPerhitungan==true){
echo "
<td>
{$pixelBarisCitra[$j-$this->imgX]}
</td>
";
}
if($n%2==0){
$this->pixelCitraGenap[] = $pixelBarisCitra[$j-$this->imgX];
}else{
$this->pixelCitraGanjil[] = $pixelBarisCitra[$j-$this->imgX];
}
}
}
}
echo "
</table>
";
$this->rataRataDanSelisihCitra(implode(",",$this->pixelCitraGanjil),implode(",",$this->pixelCitraGenap),$arahBaris=true,null,null);
}
public function rataRataDanSelisihCitra($pixelCitraGanjil,$pixelCitraGenap,$arahBaris,$hasilPixelKolomCitraGanjilselisihCitra,$hasilPixelKolomCitraGenapselisihCitra){
$pixelBarisGanjilCitra = explode(",",$pixelCitraGanjil);
$pixelBarisGenapCitra = explode(",",$pixelCitraGenap);
if($hasilPixelKolomCitraGanjilselisihCitra!=null AND $arahBaris!=true){
$hasilPixelKolomCitraGanjilselisihCitra = explode(",",$hasilPixelKolomCitraGanjilselisihCitra);
$hasilPixelKolomCitraGenapselisihCitra = explode(",",$hasilPixelKolomCitraGenapselisihCitra);
for($i=0;$i<COUNT($hasilPixelKolomCitraGanjilselisihCitra);$i++){
$rataRataKolomCitra[] = round(($hasilPixelKolomCitraGanjilselisihCitra[$i]+$hasilPixelKolomCitraGenapselisihCitra[$i])/sqrt(2),4);
$selisihKolomCitra[] = round(($hasilPixelKolomCitraGenapselisihCitra[$i]-$hasilPixelKolomCitraGanjilselisihCitra[$i])/sqrt(2),4);
}
$rataRataKolomCitra = implode(",",$rataRataKolomCitra);
$selisihKolomCitra = implode(",",$selisihKolomCitra);
}
for($i=0;$i<COUNT($pixelBarisGanjilCitra);$i++){
$rataRataCitra[] = round(($pixelBarisGanjilCitra[$i]+$pixelBarisGenapCitra[$i])/sqrt(2),4);
$selisihCitra[] = round(($pixelBarisGenapCitra[$i]-$pixelBarisGanjilCitra[$i])/sqrt(2),4);
}
$pixelrataRataCitra = implode(",",$rataRataCitra);
$pixelSelisihCitra = implode(",",$selisihCitra);
if($arahBaris==true){
$this->dekomposisiArahBarisCitra($pixelrataRataCitra,$pixelSelisihCitra);
}else{
$this->hasilDekomposisiCitra($pixelrataRataCitra,$pixelSelisihCitra,$rataRataKolomCitra,$selisihKolomCitra);
}
}
public function dekomposisiArahBarisCitra($rataRataCitra,$selisihCitra){
$rataRataCitra = explode(",",$rataRataCitra);
$selisihCitra = explode(",",$selisihCitra);
$p = 0; $setengahBaris = $this->imgX/2;
for($i=0;$i<$this->imgY;$i++){
$p = $p+$setengahBaris;
if($i<$this->imgY){
for($j=$p;$j<$p+$setengahBaris;$j++){
$hasilRataRataCitra[] = $rataRataCitra[$j-$setengahBaris];
}
for($j=$p;$j<$p+$setengahBaris;$j++){
$hasilSelisihCitra[] = $selisihCitra[$j-$setengahBaris];
}
}
}
$this->dekomposisiCitraArahKolom(implode(",",$hasilRataRataCitra),implode(",",$hasilSelisihCitra));
}
public function dekomposisiCitraArahKolom($hasilRataRataCitra,$hasilSelisihCitra){
$rataRataCitra = explode(",",$hasilRataRataCitra);
$selisihCitra = explode(",",$hasilSelisihCitra);
$n = 0; $setengahBaris = $this->imgX/2;
for($j=0;$j<$setengahBaris;$j+=1){
if($j<$setengahBaris){
for($i=0;$i<COUNT($rataRataCitra);$i+=$setengahBaris){
if($n%2==0){
$pixelKolomCitraGenap[] = $rataRataCitra[$i+$j];
$pixelKolomCitraGenapSelisih[] = $selisihCitra[$i+$j];
}else{
@$pixelKolomCitraGanjil[] = $rataRataCitra[$i+$j];
@$pixelKolomCitraGanjilSelisih[] = $selisihCitra[$i+$j];
}
$n++;
}
$hasilPixelKolomCitraGenap = implode(",",$pixelKolomCitraGenap);
$hasilPixelKolomCitraGanjil = implode(",",$pixelKolomCitraGanjil);
$hasilPixelKolomCitraGenapselisihCitra = implode(",",$pixelKolomCitraGenapSelisih);
$hasilPixelKolomCitraGanjilselisihCitra = implode(",",$pixelKolomCitraGanjilSelisih);
}
}
}
public function hitungEnergiCitra($energiCitra1,$energiCitra2,$energiCitra3,$energiCitra4){
$ciriCitra1 = 0;
$ciriCitra2 = 0;
$ciriCitra3 = 0;
$ciriCitra4 = 0;
$pecahEnergi1 = explode(",",$energiCitra1);
$pecahEnergi2 = explode(",",$energiCitra2);
$pecahEnergi3 = explode(",",$energiCitra3);
$pecahEnergi4 = explode(",",$energiCitra4);
for($i=0;$i<COUNT($pecahEnergi1);$i++){
$ciriCitra1 = $ciriCitra1+$pecahEnergi1[$i];
$ciriCitra2 = $ciriCitra2+$pecahEnergi2[$i];
$ciriCitra3 = $ciriCitra3+$pecahEnergi3[$i];
$ciriCitra4 = $ciriCitra4+$pecahEnergi4[$i];
}
}
}
?>
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :