分享
 
 
 

基本图象处理代码(3)

王朝delphi·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

[常用滤镜效果]

这里根据角度的不同,在一个像素周围的8个像素中取不同的两个运算得到新颜色值,用这个值和它求差值实现浮雕效果。

//浮雕

procedure Emboss(SrcBmp,DestBmp:TBitmap;AzimuthChange:integer);overload;

var

i, j, Gray, Azimuthvalue, R, G, B: integer;

SrcRGB, SrcRGB1, SrcRGB2, DestRGB: pRGBTriple;

begin

for i := 0 to SrcBmp.Height - 1 do

begin

SrcRGB := SrcBmp.ScanLine[i];

DestRGB := DestBmp.ScanLine[i];

if (AzimuthChange >= -180) and (AzimuthChange < -135) then

begin

if i > 0 then

SrcRGB1 := SrcBmp.ScanLine[i-1]

else

SrcRGB1 := SrcRGB;

Inc(SrcRGB1);

SrcRGB2 := SrcRGB;

Inc(SrcRGB2);

end

else if (AzimuthChange >= -135) and (AzimuthChange < -90) then

begin

if i > 0 then

SrcRGB1 := SrcBmp.ScanLine[i-1]

else

SrcRGB1 := SrcRGB;

SrcRGB2 := SrcRGB1;

Inc(SrcRGB2);

end

else if (AzimuthChange >= -90) and (AzimuthChange < -45) then

begin

if i > 0 then

SrcRGB1 := SrcBmp.ScanLine[i-1]

else

SrcRGB1 := SrcRGB;

SrcRGB2 := SrcRGB1;

end

else if (AzimuthChange >= -45) and (AzimuthChange < 0) then

begin

SrcRGB1 := SrcRGB;

if i > 0 then

SrcRGB2 := SrcBmp.ScanLine[i-1]

else

SrcRGB2 := SrcRGB;

end

else if (AzimuthChange >= 0) and (AzimuthChange < 45) then

begin

SrcRGB2 := SrcRGB;

if (i < SrcBmp.Height - 1) then

SrcRGB1 := SrcBmp.ScanLine[i+1]

else

SrcRGB1 := SrcRGB;

end

else if (AzimuthChange >= 45) and (AzimuthChange < 90) then

begin

if (i < SrcBmp.Height - 1) then

SrcRGB1 := SrcBmp.ScanLine[i+1]

else

SrcRGB1 := SrcRGB;

SrcRGB2 := SrcRGB1;

end

else if (AzimuthChange >= 90) and (AzimuthChange < 135) then

begin

if (i < SrcBmp.Height - 1) then

SrcRGB1 := SrcBmp.ScanLine[i+1]

else

SrcRGB1 := SrcRGB;

SrcRGB2 := SrcRGB1;

Inc(SrcRGB1);

end

else if (AzimuthChange >= 135) and (AzimuthChange <= 180) then

begin

if (i < SrcBmp.Height - 1) then

SrcRGB2 := SrcBmp.ScanLine[i+1]

else

SrcRGB2 := SrcRGB;

Inc(SrcRGB2);

SrcRGB1 := SrcRGB;

Inc(SrcRGB1);

end;

for j := 0 to SrcBmp.Width - 1 do

begin

if (AzimuthChange >= -180) and (AzimuthChange < -135) then

begin

Azimuthvalue := AzimuthChange + 180;

R:=SrcRGB.rgbtRed-((SrcRGB1.rgbtRed)*Azimuthvalue div 45)-((SrcRGB2.rgbtRed)*(45-Azimuthvalue) div 45)+78;

G:=SrcRGB.rgbtGreen-((SrcRGB1.rgbtGreen)*Azimuthvalue div 45)-((SrcRGB2.rgbtGreen)*(45-Azimuthvalue) div 45)+78;

B:=SrcRGB.rgbtBlue-((SrcRGB1.rgbtBlue)*Azimuthvalue div 45)-((SrcRGB2.rgbtBlue)*(45-Azimuthvalue) div 45)+78;

end

else if (AzimuthChange >= -135) and (AzimuthChange < -90) then

begin

Azimuthvalue := AzimuthChange + 135;

R:=SrcRGB.rgbtRed-((SrcRGB1.rgbtRed)*Azimuthvalue div 45)-((SrcRGB2.rgbtRed)*(45-Azimuthvalue) div 45)+78;

G:=SrcRGB.rgbtGreen-((SrcRGB1.rgbtGreen)*Azimuthvalue div 45)-((SrcRGB2.rgbtGreen)*(45-Azimuthvalue) div 45)+78;

B:=SrcRGB.rgbtBlue-((SrcRGB1.rgbtBlue)*Azimuthvalue div 45)-((SrcRGB2.rgbtBlue)*(45-Azimuthvalue) div 45)+78;

end

else if (AzimuthChange >= -90) and (AzimuthChange < -45) then

begin

if j=1 then Dec(SrcRGB1);

Azimuthvalue := AzimuthChange + 90;

R:=SrcRGB.rgbtRed-((SrcRGB1.rgbtRed)*Azimuthvalue div 45)-((SrcRGB2.rgbtRed)*(45-Azimuthvalue) div 45)+78;

G:=SrcRGB.rgbtGreen-((SrcRGB1.rgbtGreen)*Azimuthvalue div 45)-((SrcRGB2.rgbtGreen)*(45-Azimuthvalue) div 45)+78;

B:=SrcRGB.rgbtBlue-((SrcRGB1.rgbtBlue)*Azimuthvalue div 45)-((SrcRGB2.rgbtBlue)*(45-Azimuthvalue) div 45)+78;

end

else if (AzimuthChange >= -45) and (AzimuthChange < 0) then

begin

if j=1 then

begin

Dec(SrcRGB1);

Dec(SrcRGB2);

end;

Azimuthvalue := AzimuthChange + 45;

R:=SrcRGB.rgbtRed-((SrcRGB1.rgbtRed)*Azimuthvalue div 45)-((SrcRGB2.rgbtRed)*(45-Azimuthvalue) div 45)+78;

G:=SrcRGB.rgbtGreen-((SrcRGB1.rgbtGreen)*Azimuthvalue div 45)-((SrcRGB2.rgbtGreen)*(45-Azimuthvalue) div 45)+78;

B:=SrcRGB.rgbtBlue-((SrcRGB1.rgbtBlue)*Azimuthvalue div 45)-((SrcRGB2.rgbtBlue)*(45-Azimuthvalue) div 45)+78;

end

else if (AzimuthChange >= 0) and (AzimuthChange < 45) then

begin

if j=1 then

begin

Dec(SrcRGB1);

Dec(SrcRGB2);

end;

Azimuthvalue := AzimuthChange;

R:=SrcRGB.rgbtRed-((SrcRGB1.rgbtRed)*Azimuthvalue div 45)-((SrcRGB2.rgbtRed)*(45-Azimuthvalue) div 45)+78;

G:=SrcRGB.rgbtGreen-((SrcRGB1.rgbtGreen)*Azimuthvalue div 45)-((SrcRGB2.rgbtGreen)*(45-Azimuthvalue) div 45)+78;

B:=SrcRGB.rgbtBlue-((SrcRGB1.rgbtBlue)*Azimuthvalue div 45)-((SrcRGB2.rgbtBlue)*(45-Azimuthvalue) div 45)+78;

end

else if (AzimuthChange >= 45) and (AzimuthChange < 90) then

begin

if j=1 then Dec(SrcRGB2);

Azimuthvalue := AzimuthChange - 45;

R:=SrcRGB.rgbtRed-((SrcRGB1.rgbtRed)*Azimuthvalue div 45)-((SrcRGB2.rgbtRed)*(45-Azimuthvalue) div 45)+78;

G:=SrcRGB.rgbtGreen-((SrcRGB1.rgbtGreen)*Azimuthvalue div 45)-((SrcRGB2.rgbtGreen)*(45-Azimuthvalue) div 45)+78;

B:=SrcRGB.rgbtBlue-((SrcRGB1.rgbtBlue)*Azimuthvalue div 45)-((SrcRGB2.rgbtBlue)*(45-Azimuthvalue) div 45)+78;

end

else if (AzimuthChange >= 90) and (AzimuthChange < 135) then

begin

Azimuthvalue := AzimuthChange - 90;

R:=SrcRGB.rgbtRed-((SrcRGB1.rgbtRed)*Azimuthvalue div 45)-((SrcRGB2.rgbtRed)*(45-Azimuthvalue) div 45)+78;

G:=SrcRGB.rgbtGreen-((SrcRGB1.rgbtGreen)*Azimuthvalue div 45)-((SrcRGB2.rgbtGreen)*(45-Azimuthvalue) div 45)+78;

B:=SrcRGB.rgbtBlue-((SrcRGB1.rgbtBlue)*Azimuthvalue div 45)-((SrcRGB2.rgbtBlue)*(45-Azimuthvalue) div 45)+78;

end

else if (AzimuthChange >= 135) and (AzimuthChange <= 180) then

begin

Azimuthvalue := AzimuthChange - 135;

R:=SrcRGB.rgbtRed-((SrcRGB1.rgbtRed)*Azimuthvalue div 45)-((SrcRGB2.rgbtRed)*(45-Azimuthvalue) div 45)+78;

G:=SrcRGB.rgbtGreen-((SrcRGB1.rgbtGreen)*Azimuthvalue div 45)-((SrcRGB2.rgbtGreen)*(45-Azimuthvalue) div 45)+78;

B:=SrcRGB.rgbtBlue-((SrcRGB1.rgbtBlue)*Azimuthvalue div 45)-((SrcRGB2.rgbtBlue)*(45-Azimuthvalue) div 45)+78;

end;

R:=Min(R,255);

R:=Max(R,0);

G:=Min(G,255);

G:=Max(G,0);

B:=Min(B,255);

B:=Max(B,0);

Gray := (R shr 2) + (R shr 4) + (G shr 1) + (G shr 4) + (B shr 3);

DestRGB.rgbtRed:=Gray;

DestRGB.rgbtGreen:=Gray;

DestRGB.rgbtBlue:=Gray;

if (j<SrcBmp.Width - 1) or not (((AzimuthChange>=-180) and (AzimuthChange<-135)) or ((AzimuthChange>=90) and (AzimuthChange<=180))) then

begin

Inc(SrcRGB1);

end;

if (j<SrcBmp.Width - 1) or not (((AzimuthChange>=135) and (AzimuthChange<180)) or ((AzimuthChange>=-180) and (AzimuthChange<=-90))) then

begin

Inc(SrcRGB2);

end;

Inc(SrcRGB);

Inc(DestRGB);

end;

end;

end;

procedure Emboss(Bmp:TBitmap;AzimuthChange:integer;ElevationChange:integer;WeightChange:integer);overload;

var

DestBmp:TBitmap;

begin

DestBmp:=TBitmap.Create;

DestBmp.Assign(Bmp);

Emboss(Bmp,DestBmp,AzimuthChange,ElevationChange,WeightChange);

Bmp.Assign(DestBmp);

end;

//反色

procedure Negative(Bmp:TBitmap);

var

i, j: Integer;

PRGB: pRGBTriple;

begin

for i := 0 to Bmp.Height - 1 do

begin

PRGB := Bmp.ScanLine[i];

for j := 0 to Bmp.Width - 1 do

begin

PRGB^.rgbtRed :=not PRGB^.rgbtRed ;

PRGB^.rgbtGreen :=not PRGB^.rgbtGreen;

PRGB^.rgbtBlue :=not PRGB^.rgbtBlue;

Inc(PRGB);

end;

end;

end;

//曝光

procedure Exposure(Bmp:TBitmap);

var

i, j: integer;

PRGB: pRGBTriple;

begin

for i := 0 to Bmp.Height - 1 do

begin

PRGB := Bmp.ScanLine[i];

for j := 0 to Bmp.Width - 1 do

begin

if PRGB^.rgbtRed<128 then

PRGB^.rgbtRed :=not PRGB^.rgbtRed ;

if PRGB^.rgbtGreen<128 then

PRGB^.rgbtGreen :=not PRGB^.rgbtGreen;

if PRGB^.rgbtBlue<128 then

PRGB^.rgbtBlue :=not PRGB^.rgbtBlue;

Inc(PRGB);

end;

end;

end;

//模糊

procedure Blur(SrcBmp:TBitmap);

var

i, j:Integer;

SrcRow:pRGBTriple;

SrcNextRow:pRGBTriple;

SrcPreRow:pRGBTriple;

Value:Integer;

procedure IncRow;

begin

Inc(SrcPreRow);

Inc(SrcRow);

Inc(SrcNextRow);

end;

procedure DecRow;

begin

Dec(SrcPreRow);

Dec(SrcRow);

Dec(SrcNextRow);

end;

begin

for i := 0 to SrcBmp.Height - 1 do

begin

if i > 0 then

SrcPreRow:=SrcBmp.ScanLine[i-1]

else

SrcPreRow := SrcBmp.ScanLine[i];

SrcRow := SrcBmp.ScanLine[i];

if i < SrcBmp.Height - 1 then

SrcNextRow:=SrcBmp.ScanLine[i+1]

else

SrcNextRow:=SrcBmp.ScanLine[i];

for j := 0 to SrcBmp.Width - 1 do

begin

if j > 0 then DecRow;

Value:=SrcPreRow.rgbtRed+SrcRow.rgbtRed+SrcNextRow.rgbtRed;

if j > 0 then IncRow;

Value:=Value+SrcPreRow.rgbtRed+SrcRow.rgbtRed+SrcNextRow.rgbtRed;

if j < SrcBmp.Width - 1 then IncRow;

Value:=(Value+SrcPreRow.rgbtRed+SrcRow.rgbtRed+SrcNextRow.rgbtRed) div 9;

if j < SrcBmp.Width - 1 then DecRow;

SrcRow.rgbtRed:=value;

if j > 0 then DecRow;

Value:=SrcPreRow.rgbtGreen+SrcRow.rgbtGreen+SrcNextRow.rgbtGreen;

if j > 0 then IncRow;

Value:=Value+SrcPreRow.rgbtGreen+SrcRow.rgbtGreen+SrcNextRow.rgbtGreen;

if j < SrcBmp.Width - 1 then IncRow;

Value:=(Value+SrcPreRow.rgbtGreen+SrcRow.rgbtGreen+SrcNextRow.rgbtGreen) div 9;

if j < SrcBmp.Width - 1 then DecRow;

SrcRow.rgbtGreen:=value;

if j > 0 then DecRow;

Value:=SrcPreRow.rgbtBlue+SrcRow.rgbtBlue+SrcNextRow.rgbtBlue;

if j > 0 then IncRow;

Value:=Value+SrcPreRow.rgbtBlue+SrcRow.rgbtBlue+SrcNextRow.rgbtBlue;

if j < SrcBmp.Width - 1 then IncRow;

Value:=(Value+SrcPreRow.rgbtBlue+SrcRow.rgbtBlue+SrcNextRow.rgbtBlue) div 9;

if j < SrcBmp.Width - 1 then DecRow;

SrcRow.rgbtBlue:=value;

IncRow;

end;

end;

end;

//锐化

procedure Sharpen(SrcBmp:TBitmap);

var

i, j: integer;

SrcRGB: pRGBTriple;

SrcPreRGB: pRGBTriple;

Value: integer;

begin

for i := 0 to SrcBmp.Height - 1 do

begin

SrcRGB := SrcBmp.ScanLine[i];

if i > 0 then

SrcPreRGB:=SrcBmp.ScanLine[i-1]

else

SrcPreRGB:=SrcBmp.ScanLine[i];

for j := 0 to SrcBmp.Width - 1 do

begin

if j = 1 then Dec(SrcPreRGB);

Value:=SrcRGB.rgbtRed+(SrcRGB.rgbtRed-SrcPreRGB.rgbtRed) div 2;

Value:=Max(0,Value);

Value:=Min(255,Value);

SrcRGB.rgbtRed:=value;

Value:=SrcRGB.rgbtGreen+(SrcRGB.rgbtGreen-SrcPreRGB.rgbtGreen) div 2;

Value:=Max(0,Value);

Value:=Min(255,Value);

SrcRGB.rgbtGreen:=value;

Value:=SrcRGB.rgbtBlue+(SrcRGB.rgbtBlue-SrcPreRGB.rgbtBlue) div 2;

Value:=Max(0,Value);

Value:=Min(255,Value);

SrcRGB.rgbtBlue:=value;

Inc(SrcRGB);

Inc(SrcPreRGB);

end;

end;

end;

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有