1

Using the following code I can get the DCT of an image in PHP. Then I need to convert this back in to the compressed image. How can I achieve that?

<?php

$results = array();
$image1 = "baboon.jpg";
$ima = ImageCreateFromJPEG($image1);
$N1 = imagesx($ima);
$N2 = imagesy($ima);

$rows = array();
$row = array();
for ($j = 0; $j < $N2; $j++) {
    for ($i = 0; $i < $N1; $i++)
        $row[$i] = imagecolorat($ima, $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);
}

print_r($results);

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;
}

?>

Also I need to know how can I add some extra details like another message to this image too.. (image steganography). Please help. Thanks

Abdul Hoque Nuri
  • 1,105
  • 1
  • 9
  • 18
  • You should narrow down your questions to one. IDCT is what you need to apply to convert the coefficients back to an image. What you're probably trying to do also requires to do DCT on blocks of only 8x8 pixels and then quantise the coefficients. – Reti43 Jan 05 '19 at 10:25
  • @Reti43 i'm not clear about above. what actually I wanted to do was to create an image stenography algorithm using DCT. – Vimukthi Saranga Jan 05 '19 at 10:28
  • I figured so, but any paper I've read about that requires you to pretty much follow the jpeg compression steps until you compute the quantised dct coefficients of 8x8 blocks. Do you intend to save your stego image as jpeg, or bpm/png? – Reti43 Jan 05 '19 at 10:46
  • @Reti43 I'm planning to save output as a jpeg. could you please help me to resolve this, or to find any sample code please :) – Vimukthi Saranga Jan 08 '19 at 16:05
  • 1
    [This answer](https://stackoverflow.com/questions/35396977/lsb-dct-based-image-steganography) explains conceptually what you should do and [this](https://stackoverflow.com/questions/29677726/steganography-in-lossy-compression-java) has an example in java. – Reti43 Jan 08 '19 at 18:17
  • thank you very much – Vimukthi Saranga Jan 09 '19 at 15:55

0 Answers0