delphi FMX图像的直方图均衡

2017-11-26 19:06:10来源:CSDN作者:qq_38204686人点击

`//灰度化的直方图均衡 junhengprocedure junheng(b : TBitmap);var   x, y , I: Integer;   A_BMPData : TBitmapData ;   p: PByteArray;   n : array [0..255] of Integer;begin   //初始化数组 c   for I := 0 to 255 do   begin     n[i] := 0;   end;   //进行均衡 jh   if  b.Map( TMapAccess.ReadWrite, A_BMPData)  then   begin        //统计出现的次数  t        for y := 0 to A_BMPData.Height - 1 do        begin            p := A_BMPData.GetScanline(y);            for x := 0 to A_BMPData.Width - 1 do            begin               n[p[x*4]] := n[p[x*4]]+1;            end;        end;        //根据公式算出结果 s        for I := 1 to 255 do        begin            n[i] := n[i]+n[i-1];            n[i-1] := round(n[i-1]*255/b.Width/b.Height);        end;        n[255] := round(n[255]*255/b.Width/b.Height);        //给图像赋值  f        for y := 0 to A_BMPData.Height - 1 do        begin            p := A_BMPData.GetScanline(y);            for x := 0 to A_BMPData.Width - 1 do            begin               //不能这样  p[x*4]值已经改变               //p[x*4] := n[p[x*4]];               //p[x*4+1] := n[p[x*4]];               //p[x*4+2] := n[p[x*4]];               p[x*4] := n[p[x*4]];               p[x*4+1] := p[x*4];               p[x*4+2] := p[x*4];            end;        end;        b.Unmap(A_BMPData);   end;end;`