Thread diffrence of two images (2 answers)
Opened by mary at 2010-06-11 08:32

Gast mary
 2010-06-11 08:32
#138230 #138230
Hallo,

I have two grayscale pictures (same size (1024,768), grayscale from 0 to 255). I want to take the difference of this two pictures. (difference of the grayscale values for each pixel)
I tried something but there's an error:
gd-png: fatal libpng error: Invalid number of colors in palette
gd-png error: setjmp returns error condition

here the code:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use GD;


# create a new image
$im = new GD::Image(1024,768);


$bildin= "img/CH_IR039/05100100.039";
$bildout= "img/CH_IR039/05100100.png";

$bildin2= "img/CH_IR108/05100100.108";
$bildout2= "img/CH_IR108/05100100.png";

$befehl = "convert ".$bildin." ".$bildout;
system($befehl);
$befehl2 = "convert ".$bildin2." ".$bildout2;
system($befehl2);

$myImage = GD::Image->newFromPng($bildout);

$myImage2 = GD::Image->newFromPng($bildout2);



$k=0;
for ($x=0 ; $x<=1023; $x++) {
for ($y=0 ; $y<=767; $y++)
{
$index = $myImage->getPixel($x,$y);
$index2 = $myImage2->getPixel($x,$y);

($Image1,$dummy1,$dummy1) = $myImage->rgb($index); #Achtung evt. $red[]
($Image2,$dummy1,$dummy1) = $myImage2->rgb($index2);

$color = $Image1-$Image2;

$im->setPixel($x,$y,$color);

$k++;
}
}

open(PICTURE, ">picture.png") or die("Cannot open file for writing");


binmode PICTURE;


print PICTURE $im->png;

close PICTURE;


may be you can help me

thanks
Last edited: 2010-06-11 08:45:59 +0200 (CEST)

View full thread diffrence of two images