Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Inversion of the background color of an image in Visual Basic

Having to print an acquired image with a dark red background which color is not absolutely constant, and, aiming ink cartridge economy, I used, in Visual Basic, this code, assuming that 3 viewers are installed:
CWIMAQVision1.ColorThreshold CWIMAQViewer1.Image, CWIMAQViewer2.Image, CWIMAQColorFormatHSL,255,,,,,0,16
-
CWIMAQVision1.Add CWIMAQViewer2.Image, CWIMAQViewer1.Image, CWIMAQViewer3.Image

This code works well but is black level dependent.
Is there some more elegant solution to obtain the same result ?
0 Kudos
Message 1 of 2
(2,789 Views)
I believe that what you are trying to accomplish is to turn into white the part that corresponds to the background of the image you took. If that's the case then your approach seems to me that is a very good one unless someone else could post something better. I was at first thinking about the Fill Color function but that gives the color of the image where no pixel value has been set. If you would like some more programmatically way of doing it maybe you would like to have a histogram analysis and write some algorithm that based on the histogram will decide what value to cut the L plane off as to be white.

If there is a better way hopefully someone will post it. Good luck!

Nestor.
Nestor
0 Kudos
Message 2 of 2
(2,789 Views)