PHPシャープ画像
2688 ワード
簡単な検証コードの識別手順は、白黒、シャープ化、分割、モデリングです.
どのようにシャープ化するかについては、ネット上でC#バージョンを見つけました.
ネット上には多くの画像処理類があり、いわゆる「鋭化」は本当の効果を発揮できない.jpgなど圧縮された画像については,拡大すると,空白領域に多くの雑点が見られる.次の関数で簡単にできます.
上の関数はphpから来ています.Netオンラインマニュアルコメント.
はっきりした、干渉点のない画像があれば、残りのことは簡単です.
どのようにシャープ化するかについては、ネット上でC#バージョンを見つけました.
//hsb: 0 1
public static Bitmap BitmapTo1Bpp(Bitmap img,Double hsb)
{
int w = img.Width;
int h = img.Height;
Bitmap bmp = new Bitmap(w, h, PixelFormat.Format1bppIndexed);
BitmapData data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed);
for (int y = 0; y < h; y++)
{
byte[] scan = new byte[(w + 7) / 8];
for (int x = 0; x < w; x++)
{
Color c = img.GetPixel(x, y);
//Console.WriteLine(c.GetBrightness().ToString());
if (c.GetBrightness() >= hsb ) scan[x / 8] |= (byte)(0x80 >> (x % 8));
}
Marshal.Copy(scan, 0, (IntPtr)((int)data.Scan0 + data.Stride * y), scan.Length);
}
bmp.UnlockBits(data);
return bmp;
}
ネット上には多くの画像処理類があり、いわゆる「鋭化」は本当の効果を発揮できない.jpgなど圧縮された画像については,拡大すると,空白領域に多くの雑点が見られる.次の関数で簡単にできます.
function imagelightnessat($img, $x, $y) {
if(!is_resource($img)) {
trigger_error("imagelightnessat(): supplied argument is not a valid "
. "Image resource", E_USER_WARNING);
return 0.0;
}
$c = @imagecolorat($img, $x, $y);
if($c === false) return false;
if(imageistruecolor($img))
{
$red = ($c >> 16) & 0xFF;
$green = ($c >> 8) & 0xFF;
$blue = $c & 0xFF;
}
else
{
$i = imagecolorsforindex($img, $c);
$red = $i['red'];
$green = $i['green'];
$blue = $i['blue'];
}
$m = min($red, $green, $blue);
$n = max($red, $green, $blue);
/* Because RGB isn't normalized in GD, we divide by 510 here.
* Lightness = (Max(RGB) + Min(RGB)) / 2
* But that's assuming red, green, and blue are 0 through 1 inclusive.
* Red, green, and blue are actually 0-255 (255 + 255 = 510).
*/
$lightness = (double)(($m + $n) / 510.0);
return($lightness);
}
上の関数はphpから来ています.Netオンラインマニュアルコメント.
はっきりした、干渉点のない画像があれば、残りのことは簡単です.