필터 지우기
필터 지우기

Image processing glass quality control, my code isn't working good

조회 수: 7 (최근 30일)
Umut Yildiz
Umut Yildiz 2022년 4월 22일
댓글: Walter Roberson 2022년 4월 23일
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
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
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
Umut Yildiz
Umut Yildiz 2022년 4월 22일
i've this results now. If i use another bottle can i have better results with this codes?
Do I get such a result because of the shooting angle and lighting?
DGM
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
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
Umut Yildiz
Umut Yildiz 2022년 4월 23일
Thank you for your advices, i’ll do my best and after that i’ll comment here my codes and results. Firstly I’m going to start with take bottle pics.
Best Regards
Umut Yildiz
Umut Yildiz 2022년 4월 23일
편집: Umut Yildiz 2022년 4월 23일
Hello Sir
I couldn't manage to do what you said. I'm trying with another bottle but it didn't work. Is there a chance for that you can give me an example? I think i understood you wrong. I've been doing mistakes for all day. I couldn't get any results.
Could you please send me an example bottle pics which are taken with optimal lightining and angle?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by