Have you tried
$im = imagecreatefromjpeg('../images/celule.jpg');
imagefilter($im, IMG_FILTER_GRAYSCALE);
imagefilter($im, IMG_FILTER_CONTRAST, -1000);
header("Content-type: image/jpeg");
imagejpeg($im);
imagedestroy($im);
Emulating you matlab example
$im = imagecreatefromjpeg('../images/celule.jpg');
imagefilter($im, IMG_FILTER_GRAYSCALE);
$white = imagecolorallocate($im, 255,255,255);
$black = imagecolorallocate($im, 0,0,0);
$w = imagesx($im);
$h = imagesy($im);
for ($x=0; $x<$w; $x++) {
for ($y=0; $y<$h; $y++) {
$c = imagecolorat($im, $x, $y);
if ($c & 0xFF > 190) // blue component
imagesetpixel($im, $x, $y, $white);
else
imagesetpixel($im, $x, $y, $black);
}
}
header("Content-type: image/jpeg");
imagejpeg($im);
imagedestroy($im);
Gives an effect like this (top-left corner of image)