2744.图像效果算法设计 ——静态效果 毕业论文 相关代码.doc

上传人:小小飞 文档编号:3900173 上传时间:2019-10-09 格式:DOC 页数:21 大小:106.50KB
返回 下载 相关 举报
2744.图像效果算法设计 ——静态效果 毕业论文 相关代码.doc_第1页
第1页 / 共21页
2744.图像效果算法设计 ——静态效果 毕业论文 相关代码.doc_第2页
第2页 / 共21页
2744.图像效果算法设计 ——静态效果 毕业论文 相关代码.doc_第3页
第3页 / 共21页
2744.图像效果算法设计 ——静态效果 毕业论文 相关代码.doc_第4页
第4页 / 共21页
2744.图像效果算法设计 ——静态效果 毕业论文 相关代码.doc_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《2744.图像效果算法设计 ——静态效果 毕业论文 相关代码.doc》由会员分享,可在线阅读,更多相关《2744.图像效果算法设计 ——静态效果 毕业论文 相关代码.doc(21页珍藏版)》请在三一文库上搜索。

1、目录90度旋转2垂直旋转3水平旋转4灰度4添加噪点5彩色噪点6喷溅6马赛克6RGB调整7亮度调整9对比度调整11饱和度调整12曝光14浮雕14雕刻16模糊17锐化18霓虹19/90度旋转procedure TForm1.Rotatepicture(Bitmap: TBitmap);var aStream: TMemorystream; /内存流 header: TBITMAPINFO; dc: hDC; P: THelpRGB; x, y, b, h: Integer; RowOut: pRGBArray;begin /创建内存流 aStream := TMemoryStream.Create

2、; /设置大小,必须是4的倍数 aStream.SetSize(Bitmap.Height * Bitmap.Width * 4); with header.bmiHeader do /操作位图文件 begin biSize := SizeOf(TBITMAPINFOHEADER); /大小 biWidth := Bitmap.Width; /位图宽 biHeight := Bitmap.Height; /位图高 biPlanes := 1; biBitCount := 32; /无压缩 biCompression := 0; biSizeimage := aStream.Size; biXP

3、elsPerMeter := 1; /水平分辨率 biYPelsPerMeter := 1; /竖直分辨率 biClrUsed := 0; biClrImportant := 0; end; dc := GetDC(0); P := aStream.Memory; GetDIBits(dc, Bitmap.Handle, 0, Bitmap.Height, P, header, dib_RGB_Colors); ReleaseDC(0, dc); b := bitmap.Height; /源图高 h := bitmap.Width; /源图宽 /指定要创建的位图的大小尺寸 bitmap.Wid

4、th := b; bitmap.height := h; for y := 0 to (h - 1) do begin rowOut := Bitmap.ScanLiney; /获取新的位图信息 P := aStream.Memory; /设置文件指针 inc(p, y); /指针移位 for x := 0 to (b - 1) do begin rowoutx := p.rgb; /进行数据转移 inc(p, h); end; end; aStream.Free; /释放资源end;/垂直翻转procedure TForm1.bsSkinSpeedButton3Click(Sender: T

5、Object);var bmp1, bmp2: Tbitmap; i, j: integer; p, p1: pbyteArray;begin image1.Stretch:=true; bmp1 := Tbitmap.Create; bmp2 := Tbitmap.Create; bmp1.Assign(Self.Image1.Picture.Bitmap); bmp2.Assign(Self.image1.Picture.Bitmap); bmp1.PixelFormat := pf24bit; bmp2.PixelFormat := pf24bit; for j := 0 to Self

6、.image1.Picture.Graphic.Height - 1 do begin p := bmp1.ScanLinej; p1 := bmp2.ScanLineSelf.IMAGE1.Picture.Graphic.Height - 1 - j; for i := 0 to Self.image1.Picture.Graphic.Width - 1 do begin p3 * i := p13 * i; p3 * i + 1 := p13 * i + 1; p3 * i + 2 := p12 + 3 * i; end; end; bmp1.PixelFormat:=pf24bit; S

7、elf.Image1.Picture.Bitmap.Assign(bmp1); Self.image1.picture.Bitmap.PixelFormat := pf24bit; bmp1.Free; bmp2.Free; IsImageChanged:=true; undouse;end;/水平翻转procedure TForm1.bsSkinSpeedButton4Click(Sender: TObject);var bmp1, bmp2: TBitmap; T, P: pByteArray; X, Y: integer;begin image1.Stretch:=true; bmp1

8、:= TBitmap.Create; bmp2 := TBitmap.Create; bmp2.Assign(image1.Picture.Bitmap); bmp1.Assign(image1.Picture.Bitmap); for Y := 0 to bmp2.Height - 1 do begin T := bmp2.ScanLineY; P := bmp1.ScanLineY; for X := 0 to bmp2.Width - 1 do begin P3 * X + 2 := T3 * (bmp2.Width - 1 - X) + 2; P3 * X + 1 := T3 * (b

9、mp2.Width - 1 - X) + 1; P3 * X := T3 * (bmp2.Width - 1 - X); end; end; image1.Picture.Bitmap.Assign(bmp1); bmp1.Free; bmp2.Free; IsImageChanged:=true; undouse;end;/函数Function IntToByte(i: Integer): Byte;Begin If i 255 Then Result := 255 Else If i 240 then avg := 240; Pixel.rgbtRed := avg; Pixel.rgbt

10、Green := avg; Pixel.rgbtBlue := avg; Inc(Pixel); end; end;end;/添加噪点Procedure AddMonoNoise(srcbmp: tbitmap; Amount: Integer);Var p0: pbytearray; x, y, a, r, g, b: Integer;Begin For y := 0 To srcbmp.Height - 1 Do Begin p0 := srcbmp.scanliney; For x := 0 To srcbmp.Width - 1 Do Begin a := Random(Amount)

11、 - (Amount Shr 1); r := p0x * 3 + a; g := p0x * 3 + 1 + a; b := p0x * 3 + 2 + a; p0x * 3 := IntToByte(r); p0x * 3 + 1 := IntToByte(g); p0x * 3 + 2 := IntToByte(b); End; End;End;/添加彩色噪点Procedure AddColorNoise(srcbmp: tbitmap; Amount: Integer);Var p0: pbytearray; x, y, r, g, b: Integer;Begin For y :=

12、0 To srcbmp.Height - 1 Do Begin p0 := srcbmp.ScanLiney; For x := 0 To srcbmp.Width - 1 Do Begin r := p0x * 3 + (Random(Amount) - (Amount Shr 1); g := p0x * 3 + 1 + (Random(Amount) - (Amount Shr 1); b := p0x * 3 + 2 + (Random(Amount) - (Amount Shr 1); p0x * 3 := IntToByte(r); p0x * 3 + 1 := IntToByte

13、(g); p0x * 3 + 2 := IntToByte(b); End; End;End;/喷溅Procedure Spray(srcbmp: tbitmap; Amount: Integer);Var i, j, x, y, w, h, Val: Integer;Begin h := srcbmp.height; w := srcbmp.Width; For i := 0 To w - 1 Do For j := 0 To h - 1 Do Begin Val := Random(Amount); x := i + Val - Random(Val * 2); y := j + Val

14、- Random(Val * 2); If (x -1) And (x -1) And (y = srcbmp.width) Or (i size); Until x = srcbmp.width; inc(j); inc(y);/加1 Until (y = srcbmp.height) Or (j size); Until (y = srcbmp.height) Or (x = srcbmp.width); Until y = srcbmp.height;End;/调整RGB,SrcBmp输入,DestBmp输出procedure RGBChange(SrcBmp,DestBmp:Tbitm

15、ap;RedChange,GreenChange,BlueChange:integer);var / R,G,B:integer; SrcRow, DestRow:pRGBArray; i,j:integer;begin for i := 0 to SrcBmp.Height- 1 do begin SrcRow := SrcBmp.ScanLinei; DestRow :=DestBmp.ScanLinei; for j := 0 to SrcBmp.Width - 1 do begin / add brightness value to pixels RGB values if RedCh

16、ange 0 then DestRowj.rgbtRed := Min(255, SrcRowj.rgbtRed + RedChange) else DestRowj.rgbtRed := Max(0, SrcRowj.rgbtRed + RedChange); if GreenChange 0 then DestRowj.rgbtGreen := Min(255, SrcRowj.rgbtGreen +GreenChange) else DestRowj.rgbtGreen := Max(0, SrcRowj.rgbtGreen +GreenChange); if BlueChange 0

17、then DestRowj.rgbtBlue := Min(255, SrcRowj.rgbtBlue +BlueChange) else DestRowj.rgbtBlue := Max(0, SrcRowj.rgbtBlue +BlueChange); end; end;end;/调整RGB,SrcBmp同时为输入输出procedure RGBChange(SrcBmp:Tbitmap;RedChange,GreenChange,BlueChange:integer;AProgressBar:TProgressBar); overload;var / R,G,B:integer; SrcR

18、ow :pRGBArray; i,j:integer;begin AProgressBar.Max:=SrcBmp.Height- 1; for i := 0 to SrcBmp.Height- 1 do begin SrcRow := SrcBmp.ScanLinei; / DestRow :=DestBmp.ScanLinei; for j := 0 to SrcBmp.Width - 1 do begin / add brightness value to pixels RGB values if RedChange 0 then SrcRowj.rgbtRed := Min(255,

19、SrcRowj.rgbtRed + RedChange) else SrcRowj.rgbtRed := Max(0, SrcRowj.rgbtRed + RedChange); if GreenChange 0 then SrcRowj.rgbtGreen := Min(255, SrcRowj.rgbtGreen +GreenChange) else SrcRowj.rgbtGreen := Max(0, SrcRowj.rgbtGreen +GreenChange); if BlueChange 0 then SrcRowj.rgbtBlue := Min(255, SrcRowj.rg

20、btBlue +BlueChange) else SrcRowj.rgbtBlue := Max(0, SrcRowj.rgbtBlue +BlueChange); end; AProgressBar.Position:=i; end;end;/调整亮度,SrcBmp输入,DestBmp输出procedure BrightnessChange(SrcBmp,DestBmp:Tbitmap;ValueChange:integer);var i, j: integer; SrcRow, DestRow: pRGBArray;begin / get brightness increment valu

21、e / for each row of pixels for i := 0 to SrcBmp.Height - 1 do begin SrcRow := SrcBmp.ScanLinei; DestRow := DestBmp.ScanLinei; / for each pixel in row for j := 0 to SrcBmp.Width - 1 do begin / add brightness value to pixels RGB values if ValueChange 0 then begin / RGB values must be less than 256 Des

22、tRowj.rgbtRed := Min(255, SrcRowj.rgbtRed +ValueChange); DestRowj.rgbtGreen := Min(255, SrcRowj.rgbtGreen + ValueChange); DestRowj.rgbtBlue := Min(255, SrcRowj.rgbtBlue +ValueChange); end else begin / RGB values must be greater or equal than 0 DestRowj.rgbtRed := Max(0, SrcRowj.rgbtRed +ValueChange)

23、; DestRowj.rgbtGreen := Max(0, SrcRowj.rgbtGreen +ValueChange); DestRowj.rgbtBlue := Max(0, SrcRowj.rgbtBlue +ValueChange); end; end; end;end;/调整亮度,SrcBmp同时为输入输出procedure BrightnessChange(SrcBmp:Tbitmap;ValueChange:integer;AProgressBar:TProgressBar);var i, j: integer; SrcRow: pRGBArray;begin AProgre

24、ssBar.Max:=SrcBmp.Height- 1; for i := 0 to SrcBmp.Height - 1 do begin SrcRow := SrcBmp.ScanLinei; /DestRow := DestBmp.ScanLinei; / for each pixel in row for j := 0 to SrcBmp.Width - 1 do begin / add brightness value to pixels RGB values if ValueChange 0 then begin / RGB values must be less than 256

25、SrcRowj.rgbtRed := Min(255, SrcRowj.rgbtRed +ValueChange); SrcRowj.rgbtGreen := Min(255, SrcRowj.rgbtGreen + ValueChange); SrcRowj.rgbtBlue := Min(255, SrcRowj.rgbtBlue +ValueChange); end else begin / RGB values must be greater or equal than 0 SrcRowj.rgbtRed := Max(0, SrcRowj.rgbtRed +ValueChange);

26、 SrcRowj.rgbtGreen := Max(0, SrcRowj.rgbtGreen +ValueChange); SrcRowj.rgbtBlue := Max(0, SrcRowj.rgbtBlue +ValueChange); end; end; AProgressBar.Position:=i; end;end;/调整对比度 procedure ContrastChange(SrcBmp:Tbitmap;Amount:integer);/ Amount: -255255var / X, Y: Integer;/ I: Byte;/ ColorTable: array0.255

27、of TRGBTriple; SrcRow: pRGBArray; /pRGB: PRGBColor; themode:integer; p0: pbytearray; /themode:=1时候用 rg, gg, bg, r, g, b, x, y: Integer;beginif Amount0 then themode:=0 else themode:=1; case themode of 0: begin for Y := 0 to SrcBmp.Height - 1 do begin SrcRow := SrcBmp.ScanLineY; for X := 0 to SrcBmp.W

28、idth - 1 do begin if SrcRowx.rgbtRed=128 then SrcRowx.rgbtRed:=min(255,SrcRowx.rgbtRed+Amount div 2) else SrcRowx.rgbtRed:=max(0,SrcRowx.rgbtRed-Amount div 2); if SrcRowx.rgbtGreen=128 then SrcRowx.rgbtGreen:=min(255,SrcRowx.rgbtGreen+Amount div 2) else SrcRowx.rgbtGreen:=max(0,SrcRowx.rgbtGreen-Amo

29、unt div 2); if SrcRowx.rgbtBlue=128 then SrcRowx.rgbtBlue:=min(255,SrcRowx.rgbtBlue+Amount div 2) else SrcRowx.rgbtBlue:=max(0,SrcRowx.rgbtBlue-Amount div 2); end; end; end; 1: Begin For y := 0 To srcbmp.Height - 1 Do Begin p0 := srcbmp.scanliney; For x := 0 To srcbmp.Width - 1 Do Begin r := p0x * 3

30、; g := p0x * 3 + 1; b := p0x * 3 + 2; rg := (Abs(127 - r) * Amount) Div 255; gg := (Abs(127 - g) * Amount) Div 255; bg := (Abs(127 - b) * Amount) Div 255; If r 127 Then r := r + rg Else r := r - rg; If g 127 Then g := g + gg Else g := g - gg; If b 127 Then b := b + bg Else b := b - bg; p0x * 3 := In

31、tToByte(r); p0x * 3 + 1 := IntToByte(g); p0x * 3 + 2 := IntToByte(b); End; End;End; end; /end caseend;/调整饱和度procedure Saturation(SrcBmp: TBitmap; Amount: Integer;AProgressBar:TProgressBar);overload; / Amount: 0510var Grays: array0.767 of Integer; Alpha: array0.255 of Word; Gray, X, Y: Integer; SrcRo

32、w: pRGBArray; I: Byte;begin for I := 0 to 255 do AlphaI := (I * Amount) shr 8; x := 0; for I := 0 to 255 do begin Gray := I - AlphaI; GraysX := Gray; Inc(X); GraysX := Gray; Inc(X); GraysX := Gray; Inc(X); end; AProgressBar.Position:=0; AProgressBar.Max:=SrcBmp.Height - 1; for Y := 0 to SrcBmp.Heigh

33、t - 1 do begin SrcRow:= SrcBmp.ScanLineY; for X := 0 to SrcBmp.Width - 1 do begin Gray := GraysSrcRowx.rgbtRed +SrcRowx.rgbtGreen+SrcRowx.rgbtBlue; SrcRowx.rgbtRed:= Byte(Gray + AlphaSrcRowx.rgbtRed); SrcRowx.rgbtGreen:= Byte(Gray + AlphaSrcRowx.rgbtGreen); SrcRowx.rgbtBlue := Byte(Gray + AlphaSrcRo

34、wx.rgbtBlue); end; AProgressBar.Position:=y; end;end;procedure Saturation(SrcBmp,DestBmp: TBitmap; Amount: Integer);overload;var Grays: array0.767 of Integer; Alpha: array0.255 of Word; Gray, X, Y: Integer; SrcRow,DestRow: pRGBArray; I: Byte;begin for I := 0 to 255 do AlphaI := (I * Amount) shr 8; x

35、 := 0; for I := 0 to 255 do begin Gray := I - AlphaI; GraysX := Gray; Inc(X); GraysX := Gray; Inc(X); GraysX := Gray; Inc(X); end; for Y := 0 to SrcBmp.Height - 1 do begin SrcRow:= SrcBmp.ScanLineY; DestRow:= DestBmp.ScanLineY; for X := 0 to SrcBmp.Width - 1 do begin Gray := GraysSrcRowx.rgbtRed +SrcRowx.rgbtGreen+SrcRowx.rgbtBlue; DestRowx.rgbtRed:=

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1