Cita:
Empezado por coso
hola,
Código Delphi [-]
function TForm1.Lluminositat(c : TColor): integer;
var
r,g,b : integer;
act : integer;
begin
r := Red(c);
g := Green(c);
b := Blue(c);
act := r+g+b;
Lluminositat := act div 3;
end;
function TForm1.Red(c : TColor) : integer;
begin
Red := c and $FF;
end;
function TForm1.Green(c : TColor) : integer;
begin
Green := (c and $FF00) div $100;
end;
function TForm1.Blue(c : TColor) : integer;
begin
Blue := (c and $FF0000) div $10000;
end;
si haces algo como
Código Delphi [-]
procedure filtro_de_contraste(cn : TCanvas);
var
i,j : integer;
begin
for i := 0 to cn.Width do
for j := 0 to cn.Height do
begin
if Lluminositat(cn.Pixels[i,j]) > 128 then cn.Pixels[i,j] := clWhite
else cn.Pixels[i,j] := clBlack;
end;
end;
tendras un filtro de contraste bastante aproximado. Solo hara falta aplicarlo antes. Si lo que quieres son deducir la direccion de degradado del color, puedes hacerlo tambien buscando el punto de maximo brillo (mediante lluminositat), restar con la luminosidad de los adyacentes, y aquel donde la diferencia (el gradiente) sea maximo, es el mas proximo al borde, aunque no creo que lo necesites.
|
procedure Comic(Img: TPicture; Umbral: Integer);
var
Bitmap: TBitmap;
P1,P2,P3,P4: PByte;
i,j: Integer;
begin
Bitmap:= TBitmap.Create;
try
Bitmap.Width:= Img.Width;
Bitmap.Height:= Img.Height;
Bitmap.Canvas.Draw(0,0,Img.Graphic);
if not (Img.Graphic is TBitmap) then
Img.Assign(Bitmap);
Img.Bitmap.PixelFormat:= pf24bit;
Bitmap.PixelFormat:= pf24bit;
for j:= -1 to Bitmap.Height - 2 do
begin
// Ajustamos el borde superior
if j < 0 then
P1:= Bitmap.ScanLine[0]
else
P1:= Bitmap.ScanLine[j];
P2:= Bitmap.ScanLine[j+1];
// Ajustamos el borde inferior
if j > Bitmap.Height - 3 then
P3:= Bitmap.ScanLine[Bitmap.Height - 1]
else
P3:= Bitmap.ScanLine[j+2];
P4:= Img.Bitmap.ScanLine[j+1];
// Primera columna
PFila(P4)[1]:=
Calcular(PFila(P1),PFila(P2),PFila(P3),1,2,Umbral);
for i:= 0 to Bitmap.Width - 3 do
begin
PFila(P4)[2]:=
Calcular(PFila(P1),PFila(P2),PFila(P3),2,3,Umbral);
inc(P1,Sizeof(TRGB));
inc(P2,Sizeof(TRGB));
inc(P3,Sizeof(TRGB));
inc(P4,Sizeof(TRGB));
end;
// Ultima columna
PFila(P4)[2]:=
Calcular(PFila(P1),PFila(P2),PFila(P3),2,2,Umbral);
end;
finally
Bitmap.Free;
end;
end;
Esto que fue postado aqui da un resultado mui bueno, e intentado trabajar con el primer algoritmo que me passaste pero no logre exito con el, tbm é intentado el recursivo pero tampoco me dio resultados, cae que parece simples, pero ya veo q no lo es tanto