delphi FMX图像的局部直方图均衡

来源:互联网 发布:navicat linux 安装 编辑:程序博客网 时间:2024/05/19 22:03
//局部直方图均衡 jubu 3x3procedure jubu(b : TBitmap);var   b_read : TBitmap;   x, y , I: Integer;   wdata , rdata : TBitmapData ;   p0,p,p1,pw: PByteArray;   n : array [0..255] of Integer;begin   b_read := TBitmap.Create;   b_read.Assign(b);   //进行局部均衡  不考虑最外一层像素  jbjh   if  b.Map( TMapAccess.ReadWrite, wdata)and b_read.Map( TMapAccess.Read,rdata)  then   begin        //3x3的小窗口    3x3        for y := 1 to rdata.Height - 2 do        begin            p0:= rdata.GetScanline(y-1);            p := rdata.GetScanline(y);            p1:= rdata.GetScanline(y+1);            pw := wdata.GetScanline(y);            //3x3            for x := 1 to rdata.Width - 2 do            begin               //初始化数组 c               for I := 0 to 255 do               begin                 n[i] := 0;               end;               //第一行的三个像素 p0               n[p0[x*4-4]] := n[p0[x*4-4]]+1;               n[p0[x*4]] := n[p0[x*4]]+1;               n[p0[x*4+4]] := n[p0[x*4+4]]+1;               //中间行的三个像素  p               n[p[x*4-4]] := n[p[x*4-4]]+1;               n[p[x*4]] := n[p[x*4]]+1;               n[p[x*4+4]] := n[p[x*4+4]]+1;               //第三行的三个像素  p1               n[p1[x*4-4]] := n[p1[x*4-4]]+1;               n[p1[x*4]] := n[p1[x*4]]+1;               n[p1[x*4+4]] := n[p1[x*4+4]]+1;               //根据公式算出结果 直方图均衡  s              for I := 1 to 255 do              begin                  n[i] := n[i]+n[i-1];                  n[i-1] := round(n[i-1]*255/9);              end;              n[255] := round(n[255]*255/9);              //给中心像素赋值  f              pw[x*4] :=  n[p[x*4]];              pw[x*4+1] := pw[x*4];              pw[x*4+2] := pw[x*4];            end;        end;        b.Unmap(wdata);        b_read.Unmap(rdata);   end;end;