In the early days, the development tool I used was VB6, and the speed at which VB6 processed images was reflected in my imageshop software. Currently, I have switched to C # To study image algorithms. in C #, there are pointers, which make image processing more efficient. VB. NET used less than half a year at the beginning. Today, I have mastered the situation and made a simple description of VB. NET image processing.
First of all, let's talk about how to obtain data in the image pixel hours. The image classes in. NET are basically based on GDI +. Therefore, the acquisition of image data actually calls some functions of GDI +. This function is lockbits. In the Quick Acquisition of color image data in VB.net, we called marshal. COPY Copies the memory data locked by lockbits to the data, and then processes the values in the array. The main reason for this is that VB. NET does not have direct access to memory (functions such as marshal. readbyte are not suitable for large loops ). So, this leads to two bad things: first, the memory needs to be twice the size of the image data at the same time; second, the memory data is copied to the data, after processing, copying the array data will reduce the memory speed. As an improvement, we should make full use of lockbits. In lockbits, there is a mode in lockmode: imagelockmode. userinputbuffer. In this mode, the user needs to apply for memory first, and then fill the image data in the relevant format such as this memory. In this way, you can define an array and then fill the image data in this array to avoid the time required to copy back and forth. The simple sample code is as follows:
Dim BMP data as new bitmapdata stride = (BMP. width * 3 + 3) and & hfffffffc) dim pixlevalue (STRIDE * BMP. height) as byte dim hanlde as gchandle = gchandle. alloc (pixlevalue, gchandletype. pinned) BMP data. scan0 = hanlde. addrofpinnedobject () 'gets the address of the first element in the byte array in the memory, VB. net does not have the varptr function of VB6.0. stride = stride 'stide this field must also be filled, which needs to be calculated in pixel format and must be a multiple of 4 BMP. lockbits (New rectangle (0, 0, BMP. width, BMP. height), imagelockmode. readwrite or imagelockmode. userinputbuffer, pixelformat. format24bpprgb, BMP data) hanlde. free ()
In this call mode, scan0 and stride of the bitmapdata object must be calculated by the user. scan0 is the address for saving the decoded data memory. The code for retrieving the Array Memory Address in VB. NET seems to be more complex than VB6, and I am not particularly familiar with this.
After calling the above Code, pixlevalue has saved the image data.
Then we processed the image data in a variety of ways. For example, the code that we used to share the same tone of the previous day is as follows:
For y = 0 to height-1 speed = y * stride 'locate the first pixel of each scan row, to avoid data-soluble effects, for x = 0 to width-1 histgram (pixlevalue (speed) + = 1 'Blue histgram (pixlevalue (speed + 1 )) + = 1 'green histgram (pixlevalue (speed + 2 )) + = 1 'Red speed + = 3' move to the next pixel next num = 0 for Y = 0 to 255 num = num + histgram (y) 'calculation ing table LUT (y) = cbyte (math. truncate (csng (Num)/(width * height * 3) * 255 )) next for Y = 0 to height-1 speed = y * stride for x = 0 to width-1 pixlevalue (speed) = LUT (pixlevalue (speed) pixlevalue (speed + 1) = LUT (pixlevalue (speed + 1) pixlevalue (speed + 2) = LUT (pixlevalue (speed + 2) Speed + = 3 next
Execution speed comparison: For the above algorithms, we only compare the time consumed by the algorithm execution.
Test Language Test image (512*384) time-consuming test image (1024*768) time-consuming test image (4000*3000) time-consuming
VB. NET 7 ms 25 ms 178 Ms
C # pointer 4 Ms 16 Ms 100 ms
C # array 5 ms 24 Ms 139 Ms
In the above table, we can see that the pointer still has obvious advantages in speed. The only thing worth noting is that VB. net is slower than C. net, I don't know how to view the corresponding disassembly code, so I still don't know why.
Download the code for the above three schemes: http://files.cnblogs.com/Imageshop/HistgramEqualize%28VB.NETandCsharp%29.rar
It seems that VB. NET is indeed not the preferred tool for image processing.
* ************** Basically, I do not provide source code, however, I will try to use text to clearly describe the corresponding algorithm or provide the reference documentation *****************
* ************* It is your own things because of your own efforts and the effects written in practice, people must rely on their own **********************
* *********** Author: laviewpbt time: 2013.4.07 contact QQ: 33184777 retain the information of the Bank ***************