Created
December 14, 2015 15:56
-
-
Save jellyninjadev/ed9a18d3af03a33f5e8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function dct1D($in){ | |
$results = array(); | |
$N = count($in); | |
for($k = 0; $k < $N; $k++){ | |
$sum = 0; | |
for($n = 0; $n < $N; $n++){ | |
$sum += $in[$n] * cos($k * pi() * ($n + 0.5) / ($N)); | |
} | |
$sum *= sqrt(2 / $N); | |
if($k == 0){ | |
$sum *= 1 / sqrt(2); | |
} | |
$results[$k] = $sum; | |
} | |
return $results; | |
} | |
function optimizedImgDTC($img){ | |
$results = array(); | |
$N1 = imagesx($img); | |
$N2 = imagesy($img); | |
$rows = array(); | |
$row = array(); | |
for($j = 0; $j < $N2; $j++){ | |
for($i = 0; $i < $N1; $i++) | |
$row[$i] = imagecolorat($img, $i, $j); | |
$rows[$j] = dct1D($row); | |
} | |
for($i = 0; $i < $N1; $i++){ | |
for($j = 0; $j < $N2; $j++) | |
$col[$j] = $rows[$j][$i]; | |
$results[$i] = dct1D($col); | |
} | |
return $results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment