PDA

View Full Version : Imaging processing by using C#



Unregistered
December 15, 2004, 18:06:12
Hi, I am using IC2.1 with Windows Visual c#. I just want to the procedures for grabing a image and how to access the grabed data. I don't know whether I am right:
1 device.LiveStart()
2 declare variable: byte* buffer
3 device.memorysnapimage()
4 Then where did the memorysanpimage snap the image to?

If you have a complete sample that does grabing and simple imaging processing, that would be great.
tedcanada@gmail.com

Thanks a lot.

Stefan Geissler
December 16, 2004, 13:46:57
Hello,

With IC Imaging Control comes an image processing C# sample.

After you have called MemorySnapImage, you can access the image data as follows:



TIS.Imaging.ImageBuffer ImgBuffer;
int x, y;
int BytesPerLine;

ImgBuffer = icImagingControl1.ImageActiveBuffer;

unsafe
{
byte* pDatabyte = ImgBuffer.GetImageData();
}

The pointer in pDatabyte points to the first byte of the first pixel of the image in the lower left corner. If you use an RGB 24 sinktype, which is the default one, pDatabyte points to the blue value of the first pixel.
You can access the value by writing
int blue = (int)*pDatabyte;
or
int blue = (int)pDatabyte[0];

To access the next byte, you can simply write
pDatabyte++;
or
pDatabyte[1];

The ++ method is faster, because only the pointer is incremented by one.

ewatson
January 21, 2005, 01:59:20
What is the best method for GetPixel on a 24bit RGB image?

Stefan Geissler
January 21, 2005, 08:30:55
Hello,

As i wrote in my last post, you retrieve the pointer to the image data as shown in the code snippet.
If you want to access the pixel by col/row coordinates, you may calculate the index in the byte stream of the RGB24 image as follows:


index = (row * imagewidth + col) * 3

blue = (int)pDatabyte[index];
green = (int)pDatabyte[index+1];
red = (int)pDatabyte[index+2];

the “3” is used, because we have 3 bytes per pixel. This is the way, i would access the pixels.