ImageEn, unit imageenproc |
|
TImageEnProc.CalcDensityHistogram
Declaration
procedure CalcDensityHistogram(VertHist, HorzHist: Pointer; VertMax, HorzMax: Integer);
Description
Calculate the vertical and horizontal density histograms. VertHist and HorzHist are an array of integer that will be filled with density values (between 0 and max values).
| Demos\ImageAnalysis\DensityAnalysis\DensityAnalysis.dpr |
| Demos\ImageEditing\EveryMethod\EveryMethod.dpr |
var
vertHist, horzHist: PIntegerArray;
vertHistHeight, horzHistWidth, vertHistWidth, horzHistHeight: integer;
i: integer;
begin
ImageEnView1.IO.LoadFromFile( ImageEnView1.io.ExecuteOpenDialog() );
// Histograms
vertHistWidth := ienVertHist.ClientWidth;
vertHistHeight := ImageEnView1.IEBitmap.Height;
horzHistWidth := ImageEnView1.IEBitmap.Width;
horzHistHeight := ienHorzHist.ClientHeight;
GetMem(vertHist, vertHistHeight * sizeof(integer));
GetMem(horzHist, horzHistWidth * sizeof(integer));
try
ImageEnView1.proc.CalcDensityHistogram( vertHist, horzHist, vertHistWidth, horzHistHeight );
// Draw horizontal histogram
ienHorzHist.IEBitmap.Allocate( horzHistWidth, horzHistHeight, ienHorzHist.Background );
ienHorzHist.IEBitmap.Canvas.Pen.Color := clBlack;
for i := 0 to horzHistWidth - 1 do
begin
ienHorzHist.IEBitmap.Canvas.MoveTo( i, horzHistHeight );
ienHorzHist.IEBitmap.Canvas.LineTo( i, horzHistHeight - horzHist[i] );
end;
ienHorzHist.Update();
// Draw vertical histogram
ienVertHist.IEBitmap.Allocate( vertHistWidth, vertHistHeight, ienVertHist.Background );
ienVertHist.IEBitmap.Canvas.Pen.Color := clBlack;
for i := 0 to vertHistHeight - 1 do
begin
ienVertHist.IEBitmap.Canvas.MoveTo( 0, i );
ienVertHist.IEBitmap.Canvas.LineTo( vertHist[i], i );
end;
ienVertHist.Update();
finally
FreeMem( vertHist );
FreeMem( horzHist );
end;
end;