Here it is
Code: Select all
<?php
//-Arne OOG's Firefly Filter------------//
//-Written by Arne OOG------------------//
//-Copyright 2007, Arne OOG-------------//
//--------------------------------------//
//-DESCRIPTION: ------------------------//
//--This Firefly script uses a median---//
//--filter to determin the color of-----//
//--pixels that the script finds--------//
//--brighter than the surrounding pixels//
//--------------------------------------//
//VARIABLES
$filename = (!$_GET[i]) ? "test001.jpg" : $_GET[i];
$y = 0;
$x = 0;
$radius = 1;
$threshold = (!$_GET[t]) ? 1.1 : $_GET[t];
//INITIALIZE
list($width, $height) = getimagesize($filename);
$image = imagecreatefromjpeg($filename);
//THE DESPECKLE FILTER
for($i = 0; $i < ($width * $height); $i++){
if($x >= $width){
$y++;
$x = 0;
}
$x++;
//GET CURRENT PIXEL
$cur_pixel_color = imagecolorat($image, $x, $y);
$pixel_color = imagecolorsforindex($image, $cur_pixel_color);
$current_color = imagecolorallocate($image, $pixel_color['red'], $pixel_color['green'], $pixel_color['blue']);
//GET THE MEDIAN OF THE PIXELS AROUND
$pixel_color1 = imagecolorat($image, ($x + 0), ($y - 1));
$pixel_color2 = imagecolorat($image, ($x - 1), ($y + 0));
$pixel_color3 = imagecolorat($image, ($x + 0), ($y + 1));
$pixel_color4 = imagecolorat($image, ($x + 1), ($y + 0));
$color_median1 = imagecolorsforindex($image, $pixel_color1);
$color_median2 = imagecolorsforindex($image, $pixel_color2);
$color_median3 = imagecolorsforindex($image, $pixel_color3);
$color_median4 = imagecolorsforindex($image, $pixel_color4);
$color_red = ($color_median1['red'] + $color_median2['red'] + $color_median3['red'] + $color_median4['red']) / 4;
$color_gre = ($color_median1['green'] + $color_median2['green'] + $color_median3['green'] + $color_median4['green']) / 4;
$color_blu = ($color_median1['blue'] + $color_median2['blue'] + $color_median3['blue'] + $color_median4['blue']) / 4;
$avarage_color = imagecolorallocate($image, $color_red, $color_gre, $color_blu);
//DETERMINE IF THE PIXEL SHOULD BE REPLACED
$red_thres = ($pixel_color['red'] + 1) / ($color_red + 1);
$gre_thres = ($pixel_color['green'] + 1) / ($color_gre + 1);
$blu_thres = ($pixel_color['blue'] + 1) / ($color_blu + 1);
$col_thres = ($red_thres + $gre_thres + $blu_thres) / 3;
if($col_thres >= $threshold){
imagesetpixel($image, $x, $y, $avarage_color);
}
}
//OUTPUT
header('Content-type: image/jpeg');
imagejpeg($image, null, 100);
?>