-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlibImageMovingObjectsRemove.php
More file actions
executable file
·121 lines (93 loc) · 2.33 KB
/
libImageMovingObjectsRemove.php
File metadata and controls
executable file
·121 lines (93 loc) · 2.33 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* @package phpPhotosMerger
* @author Bruno Trombi <bruno.trombi@gmail.com>
* @copyright 2014 Bruno Trombi
* @license http://www.gnu.org/licenses/gpl-3.0.txt
*
*this is for removing unwanted objects in a photos
*require the php module GD for pixel manipulations
**/
/*
this class is for handle rgb color space
*/
class RGB{
final function colorSet( $colorR ,$colorG ,$colorB)
{
return ( $colorR << 16 ) |( $colorG << 8 ) |( $colorB );
}
final function getRed( $colorRgb )
{
return ($colorRgb >> 16) & 0xFF;
}
final function getGreen( $colorRgb )
{
return ($colorRgb >> 8) & 0xFF;
}
final function getBlue( $colorRgb )
{
return $colorRgb & 0xFF;
}
}
/*
return the average
*/
function avg($array)
{
if (!is_array($array)) return false;
return array_sum($array)/count($array);
}
/*
imageFiles is an array of filenames of images to merge, removing the moving objects
return the $gd image.
*/
function hideMovingObjects( $imageFiles )
{
$xMax= 0;
$yMax= 0;
$images= array();
foreach( $imageFiles as $fn )
{
$images []= imagecreatefromjpeg( $fn );
$info= getimagesize( $fn );
$infoX= $info[0];
$infoY= $info[1];
$infoBits= $info[ 'bits' ];
$infoChannels= $info[ 'channels' ];
$xMax= max( $xMax, $infoX );
$yMax= max( $yMax, $infoY );
}
$colorGd = imagecreatetruecolor($xMax, $yMax);
$imagesnumber= sizeof($images);
$trimRounds= ceil( log( $imagesnumber) * log( $imagesnumber)/2 ) ;
$trimStop= $imagesnumber-$trimRounds-$trimRounds;
//for all images and all pixel
//calculate the Trimmed mean of color
for( $x=0 ;$x <$xMax ;$x++ )
{
for( $y=0; $y <$yMax ;$y++ )
{
$colorR= array();
$colorG= array();
$colorB= array();
foreach( $images as $img )
{
$colorRgb= imagecolorat( $img, $x, $y );
$colorR[]= RGB::getRed( $colorRgb );
$colorG[]= RGB::getGreen( $colorRgb );
$colorB[]= RGB::getBlue( $colorRgb );
}
sort($colorR);
sort($colorG);
sort($colorB);
$colorRed= avg( array_slice($colorR, $trimRounds, $trimStop) );
$colorGreen= avg( array_slice($colorG, $trimRounds, $trimStop) );
$colorBlue= avg( array_slice($colorB, $trimRounds, $trimStop) );
imagesetpixel( $colorGd, $x, $y, RGB::colorSet( $colorRed, $colorGreen, $colorBlue ) );
}
}
//done return the merged image!
//imagepng($colorGd, "last.jpg" );
return $colorGd;
}
?>