You are on page 1of 10

Contents

Introduction ...................................................................................................................................... 2 Rational ............................................................................................................................................. 2 Design ............................................................................................................................................... 4 Component Isolation ..................................................................................................................... 4 Bay Isolation .................................................................................................................................. 4 Testing............................................................................................................................................... 6 Noise ............................................................................................................................................. 6 Scale .............................................................................................................................................. 6 Rotation......................................................................................................................................... 7 Combination of changes ................................................................................................................ 8 Appendix ........................................................................................................................................... 9

Introduction
The purpose of this assignment was to develop a robust, fully automated and data driven matlab program to identify a particular 8 pinned electronic component in a given image. This program was to be robust to changes in noise, scale and orientation. When this component has been Identified it is to be highlighted on the original image. The matlab platform is to be used to develop this algorithm. The Vision Systems Group toolbox is used to perform various image processing functions. The solution must be automated, robust and data driven.

Rational
I began by first taking a look at the significant features within the image. The pins of the component are obviously the most relevant to this program. I determined two ways of counting the number of pins. 1. Thinning the image and then counting the limb ends. 2. Counting the number of bays for a particular component. Each method has its pros and cons. For example the thinning method has the advantage of not being effected by the breaking of one of the pins due to noise. It still counts as a limb end regardless of length. The main drawback to this image is that it breaks down very quickly due to noise. Any stray noise pixels touching the pin result in a limb when thinned. Take the following as an example.

Figure 1: Before and After Thinning

On other had the count bays options results breaks down when one of the limbs is broken. This is because the convex hull creates a convex polygon around a given blobs, meaning all angles within the polygon are less than or equal to 180 . Therefore if a limb breaks polygon will not touch all of the pins. This is shown in the image blow. The algorithm will result in a count of 7 bays rather than 8.

Figure 2: Result of broken pin

Weighing up the two options I decided that the bay count option was the more robust option as it could cope with a certain amount of noise. The program can be broken up into two distinct areas. These are isolating the various components and the processing those blobs in order to count the number of bays. To isolate the various components I used the following general algorithm. 1. 2. 3. 4. 5. Remove noise. Threshold.(Use average intensity value to ensure the solution is data driven) Remove holes from blobs which may affect count bays later. Dilate to hopefully rejoin pins. Use labeller to isolate each blob and highest grey to count.

This method for isolating blobs is very robust. Though it may capture smaller blobs of noise earlier. This means that the program is more computationally expensive because later the count bays part of the code must process more blobs. Later I include a check to see if the number of white pixels in a blob are greater than a given value. I have this value set at ten. Since a blob of 10 pixels cannot have a 8 bays I feel this is an acceptable value. The second stage of the program involves processing the blobs identified in stage one. The method chose was to count bays. The process for this was as follows: 1. Create a convex hull around blob. 2. Use process of erosion and dilation and XOR to isolate bays. Explained in design. 3. Count Number of bays contained within the image. The isolate and count bays section of the code works well but again is dependent on none of the pins being broken. None of my code should be effect by changes in orientation. Scale on its own shouldn t be a problem but scale and noise may affect it. I will deal with this in the testing phase.

Design
I will deal with the design in two seprate sections. Firstly I will deal with the isolation of components. I will then deal with the counting of bays.

Component Isolation
img1 = vsg('Median',img); img1a = vsg('LowPass',img1); threshnum = vsg('AvgIntensity',img1a); img2 = vsg('Threshold',img1a,threshnum); %Add mask to remove unwanted edge info img4 = vsg('MaskImg',img3,3); img5 = vsg('IsolateHoles',img4); img6 = vsg('XOR',img4,img5); img7 = vsg('Dilation',img6,4); img8 = vsg('Labeller',img7); img9 = vsg('Enhancer',img8); %Number of Blobs num_blobs = vsg('HighestGrey',img8);

Above is the code used for isolating the various components/blobs in the image. This method is robust to noise as an increase in noise only results in a greater number of blobs. The median filter is useful for the removal of salt and pepper noise though it does have the effect of removing some of the information from the image, though this is the case with all filters. The lowpass filter removes high frequency noise such as Gaussian. This process is robust to certain changes in scale. Obviously the dilation processes will have the effect of potentially joining components when the scale of the image is reduced. The process is data driven as the threshold used is calculated using the average intensity function. The size of the mask added to the image is determine by the size of the lowpass filter kernel. The only part that isn t fully data driven is the dilation which I set at a given value.

Bay Isolation
loop_img4 = vsg('FilledConvex',loop_img1); loop_img5 = vsg('Erosion',loop_img4,8); loop_img6 = vsg('Dilation',loop_img5,8); loop_img7 = vsg('XOR',loop_img1,loop_img6); loop_img8 =vsg('Erosion',loop_img7,8); loop_img9 =vsg('Dilation',loop_img8,8); loop_img10 =vsg('Labeller',loop_img9); loop_img10a =vsg('Enhancer',loop_img10); loop_img11 =vsg('Centroid',loop_img9);

I used the above within a for loop to isolate bays. The process of Erosion , Dilation and XOR has the effect of breaking the convex hull the where the pins come close to the hull.

Figure 3: After XOR

This results in the isolation of the bays. As mention above the inclusion of more noise results in more blobs to be processed. To address this issue I only process blobs with a greater than 10 wp. The justification for this is give above. The code is shown here.
if vsg('WPCounter',loop_img1) < 10, break, end

A check is then included to see if the desired number of bays has been counted. If it has then the loop is broken and the component is marked on the original image.

Figure 4: Component Found

Testing
During testing I looked at the effects of change in noise, scale and rotation. I then looked at a combination of these different features.

Noise
The program works well for S & P noise up to 30%. The breaking of the pins is the major issue. Above this a broken pin results in the convex hull not being near enough all pins. As a result the erosion and dilation does not break the XOR shape where it should. As shown in Figure 2 above.

Figure 5: 30% SP Noise

The algorithm worked well up to Gaussian noise of a standard deviation of 35. The low pass filter removed a lot of this noise.

Scale
My program worked well for both halve size and double size issue. For a very small image the mask would touch the edges of the components but this was unavoidable.

Figure 6: Double Size

Figure 7: Halve Size

Rotation
The algorithm worked well for changes to rotation for 90 and 180 degress. Due to the way the vsg toolbox rotates images other rotations cause the program to fail.

I m confident that my program would still work if the component was not cut in half.

Combination of changes
I found that my program works well for changes in scale noise and rotation combined. Decreasing the size means that it breaks for a lower noise level. Increasing size seems not to have that bad an effect on the effect of noise. Though it does slow down performance.

Figure 8: 90 rotation, halve size and 20 std Gaussian

Appendix
Code
% Luke Gahan IPA Assignment 2 clear;close all;

%Set Paths addpath('C:\VSG_IPA_toolbox'); addpath('C:\matlab\Image_Processing\Assignment_2') %Initilise Variables foundpart = 0; img = openimage('eparts_small.gif'); img1 = vsg('Median',img); img1a = vsg('LowPass',img1); threshnum = vsg('AvgIntensity',img1a); img2 = vsg('Threshold',img1a,threshnum); img3 = vsg('Inverse',img2); %Add mask to remove unwanted edge info img4 = vsg('MaskImg',img3,3); img5 = vsg('IsolateHoles',img4); img6 = vsg('XOR',img4,img5); img7 = vsg('Dilation',img6,4); img8 = vsg('Labeller',img7); img9 = vsg('Enhancer',img8); %Number of Blobs num_blobs = vsg('HighestGrey',img8); loop_img = img7;

%% %Testing for countbays for i = 1:num_blobs loop_img1 = vsg('BiggestBlob',loop_img); % Check Area blob. If smaller than a given size, break loop. if vsg('WPCounter',loop_img1) < 10, break, end

loop_img4 = vsg('FilledConvex',loop_img1); loop_img5 = vsg('Erosion',loop_img4,8); loop_img6 = vsg('Dilation',loop_img5,8); loop_img7 = vsg('XOR',loop_img1,loop_img6); loop_img8 =vsg('Erosion',loop_img7,8); loop_img9 =vsg('Dilation',loop_img8,8); loop_img10 =vsg('Labeller',loop_img9); loop_img10a =vsg('Enhancer',loop_img10); loop_img11 =vsg('Centroid',loop_img9); figure('Name','Bays','NumberTitle','off'),

subplot(3,1,1); imshow(uint8(loop_img1)), title('BiggestBlob'), subplot(3,1,2); imshow(uint8(loop_img10a)), title('Enhancer'), subplot(3,1,3); imshow(uint8(loop_img11)), title('Centroid'); num_bays(i) = vsg('WPCounter',loop_img11); if num_bays(i) == 8; loop_image_out = loop_img1; foundpart = 1; break; end loop_img = vsg('XOR',loop_img,loop_img1); end

%Highlight Image

if foundpart == 1, img7 = vsg('Centroid',loop_image_out); img8 = vsg('Point2Cross',img7); img9 = vsg('Add',img,img8); h = figure;image(uint8(img9));set(h,'Name','Output Image'); end

You might also like