PDA

View Full Version : Image Enhancement



Bestbier
February 23, 2004, 16:30:02
I desparetely need to write software that enhances images. I already have a program that displays greyscale live video with text overlay and then saves a frame on command using IC Imaging Control v1.4.

Now I need to modify the software so that it grabs 64 or 128 frames and averages all the pixels to create 1 enhanced image and the save it with text overlay.

Can I do this quickly in VB?

I have no idea how so, any pointers/examples/help with be appreciated.

BESTBIER

Stefan Geissler
February 25, 2004, 09:46:08
Hello BESTBIER,

Yes, you can perform this operation in Visual Basic, but Visual Basic is very slow.
Declare an array of integers, that will be used as buffer to add the pixel values of the snapped images. The dimensions of the array will be specified, after the video format is selected.
Also declare a variable, that is used to determine the count of images to be added:


Dim Pixels() As Integer
Dim ImageCount As Integer ' The count of images used for the calculation


After you have set up your video capture device and video format, you must “redim” your Pixels array:


If ICImagingControl1.DeviceValid Then
ReDim Pixels(ICImagingControl1 .ImageWidth * 3, ICImagingControl1.ImageHeight)
End If

The “3” is needed, because the current color format of the images buffers is set to RGB 24

Now start your live video etc. In the image enhancement, snap a image sequence of ImageCount images:


ICImagingControl1.MemorySnapImageSequence ImageCount

Lock the image buffers image buffers immediately to avoid overwriting them:


For Image = 1 To ImageCount
ICImagingControl1.ImageBuffers.Item(Image).Lock
Next Image


Now reset you Pixels array:



' Reset the Pixels array
For y = 0 To ICImagingControl1.ImageHeight - 1
For x = 0 To ICImagingControl1.ImageWidth * 3 - 1
Pixels(x, y) = 0
Next x
Next y


Next step: Add the pixel values stored in the images buffers to the related elements in the Pixels array:


For Image = 1 To ImageCount
ImageData = ICImagingControl1.ImageBuffers.Item(Image).GetImag eData
For y = 0 To ICImagingControl1.ImageHeight - 1
For x = 0 To ICImagingControl1.ImageWidth * 3 - 1
Pixels(x, y) = Pixels(x, y) + ImageData(x, y)
Next x
Next y
ICImagingControl1.ImageBuffers.Item(Image).Release ImageData ImageData
Next Image


Calculate the average image data:


For y = 0 To ICImagingControl1.ImageHeight - 1
For x = 0 To ICImagingControl1.ImageWidth * 3 - 1
Pixels(x, y) = Pixels(x, y) / ImageCount
Next x
Next y


Now you are finished. The Pixels array contains the average of the previously capture images. You can store the result back in an image buffer, to save it as BMP file or to display it in IC Imaging Control:


ImageData = ICImagingControl1.ImageBuffers.Item(1).GetImageDat a

For y = 0 To ICImagingControl1.ImageHeight - 1
For x = 0 To ICImagingControl1.ImageWidth * 3 - 1
If Pixels(x, y) < 256 Then
ImageData(x, y) = Pixels(x, y)
Else
ImageData(x, y) = 0
End If
Next x
Next y
ICImagingControl1.ImageBuffers.Item(1).ReleaseImag eData ImageData
' Stop the live video
ICImagingControl1.LiveStop
ICImagingControl1.LiveDisplay = False ' Important, for DisplayImageBuffer method!!
' Display the result
ICImagingControl1.DisplayImageBuffer .ImageBuffers.Item(1)


At least unlock the used image buffers:



For Image = 1 To ImageCount
ICImagingControl1.ImageBuffers.Item(Image).Unlock
Next Image


A matching Visual Basic sample is attached to this post.

Bestbier
March 8, 2004, 16:42:09
You say VB will be slow. Any idea how much time it will take seconds, minute or hours?

Can I do this quickly in C++ ?

Stefan Geissler
March 8, 2004, 16:54:38
Hello,

On my machine, the calculation about 10 images with VB was about 5 to 10 seconds. I did not implement this sample in C++, but it should be up to 10 times faster, depending on the kind of implementing (integer or float mathematics)