

山木、つくば市
function AntiBlackOut(originalBmp: TBitmap; var rinkakuBmp: TBitmap; threshold, alphaPercent: integer; decayPercent: double): Boolean; var w, h, sum, count, x, y, ix, iy: integer; alpha, decay, a: double; tmp: TBitmap; src, dst: TBmpData8; begin result := false; if originalBmp.PixelFormat <> pf24bit then exit; if rinkakuBmp.PixelFormat <> pf8bit then exit; if (threshold < 0) or (threshold > 255) then exit; if (alphaPercent < 0) or (alphaPercent > 100) then exit; w := originalBmp.Width; h := originalBmp.Height; tmp := BmpClone(originalBmp); GrayScale(tmp); alpha := alphaPercent / 100.0; decay := alpha * decayPercent / 100.0; src := TBmpData8.Create(tmp); dst := TBmpData8.Create(rinkakuBmp); for y := 0 to h-1 do for x := 0 to w-1 do begin sum := 0; count := 0; for iy := y-2 to y+2 do for ix := x-2 to x+2 do begin if (ix<0) or (ix>w-1) or (iy<0) or (iy>h-1) then continue; sum := sum + src[ix, iy]^; Inc(count); end; sum := sum div count; if (sum < threshold) then dst[x, y]^ := Min(dst[x, y]^, AdjustByte(dst[x, y]^ * (1.0 - alpha) + src[x, y]^ * alpha)) else begin if (decay < 0.00000001) then continue; a := alpha - decay * (sum - threshold); if (a > 0) then dst[x, y]^ := Min(dst[x, y]^, AdjustByte(dst[x, y]^ * (1.0 - a) + src[x, y]^ * a)); end; end; dst.Free; src.Free; tmp.Free; result := true; end;
uses VCLImageUtils, RinkakuUtils, Clipbrd; procedure TForm1.Button1Click(Sender: TObject); var bmp, tmp: TBitmap; begin bmp := LoadPng('C:\Home\ImgWork\RaceQueen.png'); if not Assigned(bmp) then exit; bmp.PixelFormat := pf24bit; tmp := BmpClone(bmp); //Median(tmp); if Rinkaku(tmp, 15) and Contrast8(tmp, 100, 0.04) and AntiBlackOut(bmp, tmp, 60, 30, 0.8) then begin Canvas.Draw(5, 35, tmp); Clipboard.Assign(tmp); end; bmp.Free; tmp.Free; end;