Thanks for the code fix. The white boarders around the image are vanished, but an Opening of a 1 Bit picture and of a 24 Bit picture does not come to the same result. How is that?
First I have a binarized picture. With
proc.ConvertTo24Bit;
proc.Opening(3);
I get a different result as with just
proc.Opening(3);
Curiously the opening (binarized picture) makes a white dot bigger instead of removing it (which is working on the 24 Bit picture).
This is the code you sent me:
procedure IEmorph1bit(Bitmap:TIEBitmap; nIter:integer; opType:integer; size:integer; invertFlag:boolean; fOnProgress: TIEProgressEvent; Sender: TObject);
var
width, height:integer;
sizeD2:integer;
sum:integer;
sumAll:integer;
x, y, i, j, n, xx, yy:integer;
imgI:TIEBitmap;
imgO:TIEBitmap;
per1: double;
begin
sizeD2 := size div 2;
height := Bitmap.Height;
width := Bitmap.Width;
imgI := Bitmap;
imgO := TIEBitmap.Create();
try
imgO.Allocate(width, height, ie1g);
if (invertFlag) then
_Negative1BitEx(imgI);
imgO.AssignImage(imgI);
sumAll := size * size;
per1 := 100 / (height);
for n := 0 to nIter-1 do
begin
for y := 0 to height-1 do
begin
for x := 0 to width-1 do
begin
sum := 0;
for i := -sizeD2 to sizeD2 do
begin
yy := y + i;
if yy < 0 then
yy := 0
else if yy >= height then
yy := height-1;
for j := -sizeD2 to sizeD2 do
begin
xx := x + j;
if xx < 0 then
xx := 0
else if xx >= width then
xx := width-1;
if imgI.Pixels_ie1g[xx, yy] then
inc(sum);
end;
end;
case (opType) of
1: // dilation
if (sum > 0) then
imgO.pixels_ie1g[x, y] := true;
2: // erosion
if (sum < sumAll) then
imgO.Pixels_ie1g[x, y] := false;
3: // dilation-erosion
if (sum > 0) then
imgO.Pixels_ie1g[x, y] := true;
4: // erosion-dilation
if (sum < sumAll) then
imgO.Pixels_ie1g[x, y] := false;
end;
end;
if assigned(fOnProgress) then
fOnProgress(Sender, trunc(per1 * y));
end;
imgI.AssignImage( imgO );
if (opType = 4) then
opType := 3
else if (opType = 3) then
opType := 4;
end;
if (invertFlag) then
_Negative1BitEx(imgO);
Bitmap.AssignImage(imgO);
finally
FreeAndNil(imgO);
end;
end;
Thank you.