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.
댓글 수: 2
참고 항목
카테고리
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!