.net - High-speed performance of image filtering in C# -
I have a bitmap I want to apply the average filter to my bitmap but I do not use GetPixel () and SetPixel () Because speed is a very important factor for me. I have a very fast way to do this. This may be done with the graphics.dream (image, point [], rectangle, graphics unit, image attributes).
.
After the average filter, I want to apply the binary filter to calculate each pixel glow: B = 0.299 * R + 0.5876 * G + 0.114 B, if the threshold value is less than threshold value (threshold value [0 .. .255] in my work is parameters) then the result of my pixel is 1, otherwise - 0) The speed in the binary filter is also important for me
Just got this link:
/// & lt; Summary & gt; /// A given image grayscale /// & lt; / Summary & gt; /// & lt; Param name = "image" & gt; /// image which is converted into a grayscale image /// & lt; / Param & gt; Public static zero grayscale image (bitmap image) {if (image == empty) remove new logic ("image"); // bitmap lock var data = image Lockbits (new rectangle (0, 0, image, image. Height), image lock mod. Redraw, image pixel format); {Insecure {//} Get an indicator in the data byte * footer = (byte *) data. Scan 0; // For all loops on data (int i = 0; i & lt; data. Height; i ++) {for (int j = 0; j & lt; data.Width; j ++) {// Gray Calculate the value byte Y = (byte) ((0.299 * PTR [2]) + (0.587 * PTR [1]) + (0.114 * PTR [0]); // Set Gray Value PTR [0] = PTR [1] = PTR [2] = Y; // Increasing Indicator PTR + = 3; } // Proceed to the next line Ptr + = data.Stride - data.Width * 3; }}} {} Create {// unlocked bits when done or when an exception is thrown. Image.UnlockBits (data);
Edit : See more information:
Comments
Post a Comment