图片灰度和二值化处理<?php
function adaptiveThreshold($file){
if(!$ex = getimagesize($file)){
return false;
}
// 打开图片
switch($ex[2]){
case IMAGETYPE_JPEG:
case IMAGETYPE_JPEG2000:
if(!$im = imageCreateFromJpeg($file)){
return false;
}
break;
case IMAGETYPE_PNG:
$im = imageCreateFromPng($file);
break;
case IMAGETYPE_GIF:
$im = imageCreateFromGif($file);
break;
case IMAGETYPE_BMP:
$im = imageCreateFromBmp($file);
break;
default :
return false;
}
$gray = array_fill(0, $ex[1],
array_fill(0, $ex[0], 0)
);
// 转为灰阶图像
foreach($gray as $y => &$row){
foreach($row as $x => &$Y){
$rgb = imagecolorat(