Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Which is faster to convert the image to byte array or convert the image to pixel. In comparison, including
thanks for help
i developed application to controlling actions by web cam
i compared first image by second with next image
so i have slow when using pixel or byte array
byte array is not strict in check difference
if you have other way plz tell me
Thanks for any help
Posted
Updated 17-Feb-11 15:51pm
v4

Can get the byte array from the image like this..(from MSDN)

C#
// Create a new bitmap.
Bitmap bmp = new Bitmap("Flower1.jpg");

// Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData =
    bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
    bmp.PixelFormat);

// Get the address of the first line.
IntPtr ptr = bmpData.Scan0;

// Declare an array to hold the bytes of the bitmap.
// This code is specific to a bitmap with 24 bits per pixels.
int bytes = bmp.Width * bmp.Height*3 ;
byte[] rgbValues = new byte[bytes];

// Copy the RGB values into the array.
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);

Once get the array need to loop through the array and use the algorithm for comparison.

The simpler way for comparing images would be comparing the image histogram. There are ways in the frequency domain as well. Why because the same frame area taken in bright light and dim light has different pixel values, but more or less same histogram shape. For this simple fact comparing byte to byte (or pixel to pixel). There are many advance algorithms over there, some use the entropy content of the image. Though there many algorithms there is no hard and fast rules which one is better. So you need research trying those popular algorithms

You may use libraries like Accord.net or Aforge.net, they have already developed algorithms which may useful for you.

http://www.aforgenet.com/framework/[^]

http://accord-net.origo.ethz.ch/[^]
 
Share this answer
 
v3
In managed code almost certainly a byte-array. GetPixel is very, very slow.
 
Share this answer
 
Comments
Mostafa Elsadany 17-Feb-11 21:50pm    
thanks for help
i developed application to controlling actions by web cam
i compared first image by second with next image
so i have slow when using pixel or byte array
byte array is not strict in check difference
if you have other way plx tell me
Henry Minute 18-Feb-11 13:31pm    
Sorry for the delay in replying.

Do an internet search for 'c# fast image processing'
You will get lots of different methodologies to try.
There are also Several Articles here on The Code Project (Use the Articles|Search menu at the top of the page) many of them by Christian Graus are really useful.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900