Image processing glass quality control, my code isn't working good
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I am new on MATLAB and Image Processing :)
I am working on the detection of the faulty product by applying image processing techniques on the glass bottles coming from the conveyor belt, I cannot find the error after applying the threshold and im2bw codes to the picture. The bottle appears black, the background is white, as a result I don't get the error, where am I going wrong? Can anyone help?
I've MATLAB R2020a and R2021b
x=imread('bottle.jpg');
threshold_x = graythresh(x);
blackwhite = im2bw(x, threshold_x);
subplot(1,2,1),imshow(x);
subplot(1,2,2),imshow(blackwhite);
y=imread('secondbottle.jpeg');
threshold_y = graythresh(y);
bw_yimage = im2bw(y, threshold_y);
subplot(1,2,1),imshow(y);
subplot(1,2,2),imshow(bw_yimage);
[g,c,d]=size(x);
y=imresize(y,[g,c]);
subplot(1,3,1);
imshow(blackwhite);
title('No Defect');
subplot(1,3,2);
imshow(bw_yimage);
title('Image of PCB which is manufactured');
subplot(1,3,3);
imshow(x-y);
title('Error');
6 个评论
Walter Roberson
2022-4-23
The bottle appears black, the background is white, as a result I don't get the error, where am I going wrong?
Your table is white, so it is the brightest part. The bottle is darker than that, so when you use that method to calculate the threshold, the bottle comes out black.
You need a different method of thresholding. For example, experiment with thresholding by "Green > Red + some constant".
回答(2 个)
DGM
2022-4-22
I'm going to take a shot in the dark and assume that the image difference is such that the result is getting truncated. Normally you'd be looking at the absolute difference, otherwise you only see half the error. In order to do that, you'll have to recast and scale to avoid intermediate truncation.
x = imread('cameraman.tif');
threshold_x = graythresh(x);
blackwhite = im2bw(x, threshold_x);
subplot(1,2,1),imshow(x);
subplot(1,2,2),imshow(blackwhite);
y = fliplr(imread('cameraman.tif'));
threshold_y = graythresh(y);
bw_yimage = im2bw(y, threshold_y);
subplot(1,2,1),imshow(y);
subplot(1,2,2),imshow(bw_yimage);
figure
[g,c,d]=size(x);
y=imresize(y,[g,c]);
subplot(1,3,1);
imshow(blackwhite);
title('No Defect');
subplot(1,3,2);
imshow(bw_yimage);
title('Image of PCB which is manufactured');
subplot(1,3,3);
imshow(abs(im2double(x)-im2double(y)));
title('Error');
2 个评论
DGM
2022-4-23
You don't need to flip your process image. I just did that for sake of example -- so that I could re-use the same image and it would be clear how the object content of the two copies was interacting in the difference image.
You still might find that the difference image is dominated by slight inconsistencies in object location in the process image, so I'm not sure how big of a problem registration will be (or how big typical defects are).
Image Analyst
2022-4-23
Wow, so much wrong with this, where do I start? Well for starters, lower your camera and point it at the bottle so the optic axis is perpendicular to the bottle. Next, know out the specular reflections by using a polarizer in front of the lamp and another, rotatable one in front of the lens. The lighting is not optimal, to say the least. Then, your background is not uniform - half on table and half background/wall. How can that be a good thing? It's not. The background should be black, or at least uniform.
You probably don't know this but I've been looking at glass for the last 25 years - it's one of my most important image processing apps. What we do is to have a point source of light (LED spotlight) aimed at the glass at a 45 degree angle. The glass is in a completely matte light booth painted black. The camera looks at the glass with normal incidence. Any defect in the glass, or residue on the glass, scatters light into the camera and appears bright. The images are remarkably good, so I suggest you use that method. Then I use a DOG (Difference Of Gaussians) filter, that we threshold, to find spots/defects. Everything that is not a spot/defect is background/residue/film.
Do that and then we can have a discussion about how to find your defects. Until then, your images are too horrible to do anything with.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Hamamatsu Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!