Delphi_ConvolFilter

所属分类:图形图像处理
开发工具:Delphi
文件大小:6615KB
下载次数:13
上传日期:2008-09-23 21:59:46
上 传 者zamjam
说明:  delphi图像处理 It was developed using Delphi 5 Pro, but it should work OK with D4 or even D3. It uses 24-bit bitmaps and scanline for speed. I have included the text version of the two forms, hopefully it will enable people with D3 or D4 to use this example.
(delphi image processing It was developed using Delphi 5 Pro, but it should work OK with D4 or even D3. It uses 24-bit bitmaps and scanline for speed. I have included the text version of the two forms, hopefully it will enable people with D3 or D4 to use this example.)

文件列表:
ConvolFilter\ DSC01974.bmp (15116598, 2007-06-13)
ConvolFilter\Pathes.dcu (3238, 2007-04-02)
ConvolFilter\Pathes.pas (2852, 2000-11-09)
ConvolFilter\Project1.dpr (188, 2001-10-08)
ConvolFilter\Project1.exe (621056, 2007-04-02)
ConvolFilter\Project1.res (876, 2002-02-14)
ConvolFilter\Unit1.dcu (20756, 2007-04-02)
ConvolFilter\Unit1.ddp (51, 2007-04-02)
ConvolFilter\Unit1.dfm (4034, 2007-04-02)
ConvolFilter\Unit1.pas (30943, 2002-02-14)
ConvolFilter\Unit1.~dfm (4032, 2002-02-13)
ConvolFilter\Unit1.~pas (30943, 2002-02-14)
ConvolFilter (0, 2007-06-13)

Harm's 3 x 3 Convolution Filter Example (TURN ON WORD WRAP FOR BEST VIEWING OF THIS FILE) http://www.users.uswest.net/~sharman1/ sharman1@uswest.net This example illustrates the use of a 3 x 3 filter to alter images. It was developed using Delphi 5 Pro, but it should work OK with D4 or even D3. It uses 24-bit bitmaps and scanline for speed. I have included the text version of the two forms, hopefully it will enable people with D3 or D4 to use this example. The 3 x 3 convolve can be pictured as a matrix: P P P P Ps P P P P Each P represents a pixel in the image. My example uses two 24-bit bitmaps - one has the source, and one has the altered image. The pixel in the center is the 'Source Origin'. Each pixel from the source image is copied to the altered image, after making changes based on the filter values and the source pixel values of its neighbors. The pixel color values are multiplied by filter values, summed, and then divided by another value. Here's a desk-check example of a 'Soften' filter. 3 x 3 area of an image, rgb values as follows: r g b r g b r g b 255 000 000 255 000 000 255 000 000 Each row is 3 pixels 255 000 000 000 000 000 255 128 128 128 128 128 255 000 128 255 255 255 I'll number the pixels sequentially, 1 through 9, starting with the upper left and going right. So, pixel 1 has an rgb value of 255,0,0, pixel 6 has an rgb value of 255,128,128, and pixel 9 has an rgb value of 255,255,255. The Soften Filter (well, the one for this example) has the values: 2 2 2 2 0 2 2 2 2 Divisor: 16 I'll call these FilterValue 1 through 9, with the same sequence as the pixels. The calculations go something like: New Red value = pixel_1 red value * FilterValue_1 + pixel_2 red value * FilterValue_2 + pixel_3 red value * FilterValue_3 + pixel_4 red value * FilterValue_4 + pixel_5 red value * FilterValue_5 + pixel_6 red value * FilterValue_6 + pixel_7 red value * FilterValue_7 + pixel_8 red value * FilterValue_8 + pixel_9 red value * FilterValue_9; New Red value = New Red Value / Divisor Then, repeat the same thing for the green and blue values. A check is made on the final result to see if the value exceeds 255 or is less than 0. These are the limits for rgb values, so the result is changed so that it does not go outside these limits. In the example, the center pixel is black, surrounded by mostly red pixels, with one gray and one white pixel in the bunch. All these calculations are determining the color of ONE pixel in the output image. By doing the math, the new red value is: (255 * 2) + (255 * 2) + (255 * 2) + (255 * 2) + (000 * 0) + (255 * 2) + (128 * 2) + (255 * 2) + (255 * 2) / 16 Or, 510 + 510 + 510 + 510 + 000 + 510 + 256 + 510 + 510 / 16 Or, 3826 / 16 = 239 <- New Red Value The same formula for the green values gives a result of ***, and the same formula for the blue values results in 80. So, the rgb values for our new pixel are 239,***,80. As you can see, the soften filter tends to blend colors together from neighboring pixels to create the new color. The source pixel was black, but in the altered image, it's a mostly red color. By changing the values in the Filter matrix, the results will be quite different. I have included several different filters in this example, but you can experiment with different values to find new filters. I find that it works best to keep the filter values such that when their sum is divided by the divisor, the result is absolute 1. The soften example has this property, the matrix has eight 2's and one 0 which adds up to 16, which is the divisor value. You could change the matrix values to be eight 3's and one 0, and change the divisor to 24. There are other types of convolves, you could extend this to a 5 x 5 matrix fairly easily, but it would slow it down a bit. There are variations like the triangle or box, which can be achieved using this example by making the 'middles' or the 'corners' 0. Some of my examples reflect these types.

近期下载者

相关文件


收藏者