Image Processing Project - I: Bottles Label Detection (Part 2)
by Yifei Zhou
3.7 Deformed Bottles
The last and most complicated one is deformed bottles detection. For this task, the interesting area I selected is the horizontal area nearby the label. The aim is to compare the length of bottle. If the bottle was deformed, the width would be enlarged or shrunk significantly. The figure shows the binary images for normal image, shrunk bottle and enlarged bottle images respectively. Obviously, I can observe that the black and white pixels distribution has a significant difference. Therefore, I set two thresholds to judge. The code segment below shows this approach. (45<=White pixels<=110 and 630<=Black Pixels <=680) Normal. The bottle whose pixels were not in the range was reported deformed.
Figure 3.7.1 Normal Bottle Image |
Figure 3.7.2 Shrunk bottle Image | Figure 3.7.3 Enlarged bottle Image |
Normal Bottle | Shrunk Bottle | Enlarged Bottle |
The figure shows the binary images for normal image, shrunk bottle and enlarged bottle images respectively. Obviously, I can observe that the black and white pixels distribution has a significant difference. Therefore, I set two thresholds to judge. The code segment below shows this approach. (45<=White pixels<=110 and 630<=Black Pixels <=680) Normal. The bottle whose pixels were not in the range was reported deformed.
function [judge]=bottle_deformed(bin_img)
zone_area=bin_img(140:145,115:235);
%select the interesting area [counts,bins]=imhist(zone_area);
judge=0;
if (counts(1,1) >=630 & counts(1,1) <=680) & (counts(2,1) >=45 & counts(2,1)<=110) %satistics the white and black pixels distribution.(for normal bottle)
judge=0;
elseif counts(2,1) >=600 %white pixels too many, reported as under-filling
judge=0;
else %not in the range was reported deformed
judge=1;
end
end
4. Evaluation of System
4.1 Faults Detection Separately
In this section, I mainly applied those faults detection to check the accuracy. The first evaluation is faults detection separately. The code segment below illustrates this step. (Note: You need to change the file path)
Figure 4.1 Detection result for each faults |
As shown in figure 4.1 above, it shows the detection results of each fault separately. There was only one fault existing in detection of non-straight labels bottle.
4.2 Combination Faults Detection
In addition, sometimes one bottle may have more than one faults, For example, the bottle were overfilling and missing labels. This system also has ability to detect all potential faults existing in bottles. The code below segment illustrates this step.
Figure 4.2.1 Combination faults in one bottle |
The figure 4.2 shows the combination faults existing in bottle. Clearly, there were three faults existing in the bottle (Cap missing, over-filling and label missing).
Figure 4.2.2 Combination faults detection result |
4.3 Randomized Image Detection
In order to evaluate the overall accuracy and system stability, I applied all faults detection techniques into all randomized images. I moved the file path to all randomized images, and calculate the accuracy.
I labelled all testing images manually as testing set which is used to compare the result with the system prediction. I create a matrix (no of images * no of faults), and use 1 to represent fault and 0 represent normal. The figure shows the testing set.
Figure 4.3.1 manually labeled testing set |
After that, I moved my working path to randomized images folder and starts detection. (I have filtering the missing bottles images in code, the last column was as the index of each image) It will also generate the prediction matrix. Similarly, I also got a matrix like that:
Figure 4.3.2 Prediction Matrix |
In order to calculate the accuracy of each fault, I used a XOR for those two matrix (XOR means if both values are same it will return 0, otherwise it will give 1). In this case, it means the (TP+FN) [The number of cases (correctly detection) + The number of cases (No faults correctly detection)].
Figure 4.3.3.1 Result matrix | Figure 4.3.3.2 Fault Calculation |
Furtherly, I calculate the overall accuracy for each faults from the code below:
Besides, I also calculated the precision and recall rate for each fault respectively. The code below segment illustrates the process.
—- | Cap Missing | Label Missing | Lab not Straight | Blank Label | Under Filling | Over Filling | Deformed |
Accuracy | 100% | 100% | 91.4% | 100% | 100% | 100% | 98.4% |
Precision | 100% | 100% | 91.4% | 100% | 100% | 100% | 98.3% |
Recall | 100% | 100% | 99% | 100% | 100% | 100% | 100% |
From the evaluation table, I found that there existing some drawbacks in the detection of not straight label and deformed table.
5. Conclusion
In conclusion, there are still some improvement spaces for the faults detection. And the detection techniques seems more singular, I hope that I could improve the performance in the future using more flexible and complicated approaches.