14
Labview Vision – Processing an Image Use LabView Vision Builder to create an edge detection script to determine pallet relative processing and position settings for use with an edge detection vi. Image Capture o Make sure your Microsoft LifeCam camera is plugged into a USB port. o Open Vision Assistant o Pin to the Start Menu (right click) Start\All Programs\National Instruments\Vision\Vision Assistant

Vision Lab Image Processing 112013 Gjm

Embed Size (px)

DESCRIPTION

Vision Lab Read Before Lab 3/6/1968

Citation preview

Labview Vision Processing an ImageUse LabView Vision Builder to create an edge detection script to determine pallet relative processing and position settings for use with an edge detection vi. Image Capture Make sure your Microsoft LifeCam camera is plugged into a USB port. Open Vision Assistant Pin to the Start Menu (right click) Start\All Programs\National Instruments\Vision\Vision Assistant

Select Acquire Image when the following dialog appears.

You will see the flowing window.

Select Acquire Image (1394) The Devices list should include the Lifecam (this make take a few moments) Press the arrow button to start a continuous capture. Place a pin pallet in the imaging area of the camera. Place the largest size pin in the middle of the pallet. Adjust the pallet position until the pins appear to be directly under the centerline of the camera. Center the scroll bars of the image window. In continuous capture the picture will be overly bright. That is ok. Once you have the pallet centered in your image, capture a single frame. Select the close button. A new picture can be taken later if this one does not prove adequate. Click OK on the dialog box that appears. The image will be placed in the image browser. Dont move the pallet! Later settings will be based upon this pallet position. If the pallet position does change, either capture a new image now or come back later, capture a new image, and make adjustments to the position-dependent settings. With the pallet position stable, save this image. File->Save Image. Choose any name, but place in a meaningful location, such as c:\temp. The file type should be PNG (portable network graphics) The brightness of the captured image may decrease from that seen while using the continuous image acquisition. Grayscale, Filtering, Processing In the upper right of the capture screen select Process Image The screen will look something like the following. The first processing step will be to change the file from RGB (color) to grayscale. Select Processing Functions: Color -> Color Plane Extraction. Select HSL-Luminance Plane and then press OK. This changes the image from color to grayscale. The image should now be grayscale. The script line will appear as follows, with an icon added for each step of the process.

Depending upon the ambient lighting, the illumination on the top of the large pin will be uneven, leading to a range of grayscale values. Leaving the top as a range will greatly complicate the thresholding step, determining where the grayscale range should be divided into values of only black and white, known as binarization. A median filter provides a way of evening out these variations. Select Processing Functions: Grayscale ->Filters. This filter evaluates all the pixels in some region about a central pixel, determines the median grey value (brightness), and applies this median value to the center pixel. Select Smoothing - Median Adjust the Filter Size X and Y values until a uniform gray region displays on the top of the pin. Dont over do it. The maximum filter size in either direction should probably be no more than 9. Record the X and Y filter values. Note the effect of the Median Filter. Prior to the median filter the tutorial image appeared as follows. After filtering (size of 9 each direction) the image had the following appearance. Select OK. The next step involves adjusting the brightness, contrast, and gamma in order to obtain a black and white image (thresholding). Select Processing Functions: Image->Brightness Individually adjust the Brightness, Contrast, and Gamma using the sliders. Note the effect of increasing and decreasing the values. Adjust them in some combination so that the top of the pin becomes a solid-white circle. For example, the tutorial images final settings were: Brightness: 0 Contrast: 89.0 Gamma: 0.88 Record your Brightness, Contrast, and Gamma values. These will be needed to setup the edge detection VI later. If these adjustments do not produce a well-defined circle, either: Readjust the smoothing filter size (click on that icon in the script and readjust) and then readjust the Brightness sliders. Or, obtain a new image with more uniform lighting. Select the Acquire Image Button at the top of the page, then Continuous Acquire. Adjust the lighting to be more uniform by: Using a sheet of paper to either shield or bounce some light about the region of the pin Repositioning the camera and pallet. Snap a picture, save and then return to the script building in the Processing Window. All of your setting will remain. Readjust as needed.The last step, not always required, but one that will make the preparation sequence more robust, applies a closing filter (morphology). This removes small voids in the middle of the image or small dendrites extending outward. The closing filter scans the image, moving left to right, top to bottom. The first step in a closing operation involves adding a white pixel of width to each black-white transition (edge) detected. This tends to expand the white region. The second step is to remove a pixel-width from the white area at its edge, to reduce the region. Select Processing Functions: Grayscale->Gray Morphology Adjust the Structuring Element. If the pin top is already a well-defined, homogenous region this have much effect; select a size of 5. If the region includes small holes, pick large enough value to fill the voids. Record the size value.Edge Detection and Size MeasurementThe last step in the process is to detect the edges of the pin. A line probe will be used to detect the diameter endpoints of the pin. The results will be returned in units of pixels. These can be modified if the image scale happens to be in different units, such as MM. Select Processing Functions: Machine Vision->Edge Detector Adjust the Edge Detector settings to match the example. Then create a detector by drawing a line through the diameter of the pin. Click and hold the left mouse button and note the coordinates. Record them. Release the mouse. From the Results table, read the edge coordinates and use them to determine the pin size in pixel units. The green boxes in the image show the detected edge locations. Adjust settings to see how they affect the results. The Edge Detection VI is now ready for use! PART 2Use a provided LabVIEW VI to measure pins of differing sizes and under different lighting conditions. Explore how the associated settings of the VI differentiate each of different size pallet pins and how changes in lighting may affect results. In the directory of the class share, \\power2.coe.montana.edu\ime471$, browse to the EIND 371\Vision folder and copy the three files to your computer. Double click on the file EdgeDetect-ImageCapture.vi that uses the USB camera to capture images saved in .png format. Use the Vision Builder to capturing images of various configurations, including pins of different sizes and varied lighting conditions, for use outside of lab. Make sure you know the coordinates of the edge detector line. (i.e. they will change if the pallet moves or the pin location changes.) In the front panel of the VI, enter the values recorded. Put the VI in Continuous Run Mode The VI should display as shown. If cam0 appears in the Camera indicator, then device function has been confirmed. For each of the pin sizes available, snap a picture and record the edge coordinates. Use the snipping tool to capture a picture of the original image and the detection image with the green detection line visible. Change the lighting without moving the pallet. Make the lighting uneven, by introducing shadows, or try to improve the uniformity of the lighting. Capture a new image, record the edge coordinates coordinates. Try to modify the lighting to such an extent that you no longer can detect the smallest pin, or so that the smallest pin are indistinguishable. Explain the results.