correction of rough edges for image detection

I am working on code to detect the edges of printed capacitors that we print in my lab.
I have little (honestly almost none) knowledge about image processing. I have been able to write some code that I can find the edges of a capacitor in an image and label those edges with markers. This code right now only works with a test image I made in paint. However when I try to run it on a real image I find broken, false or non-dectected lines.
I do not have any idea how to improve this. I have looked through and played with all the functions in the image processing tool box. Some made minor improvements but I am still not able to get the correct detection.
I have read that you can blur the edges then re-detect them. I was not sure however if this will change the length or position of the line/edge. If this is true this method will not work for me since I need as precise measurements as I can get.
I have attached the simple paint image I made, a real image of a printed capacitor, and the code.
If anyone has any suggestions I would be deeply appreciative. Thank you all for your help.

6 Comments

Most likely I would not use edge detection. I'd probably just use thresholding and then do something (though I don't know what the something is).
Tell me what you really want to do. You've said that basically edge detection is the final output, but I highly doubt that. Let's say that you had the edges. What would you do then? Just quit? I doubt it. What do you really want? The average spacing between the electrodes? Number of defects in the electrode bars? Something else? I assume the real image is an ideal case. What does a defective/bad image look like? What do you really want to detect? If the image is good or not? Exactly what defines good and not good? Thickness of bars? Thickness of the spacing between bars? Darkness of the bars?
HI
Correct, that is not the last step.
So that real image is a typical image of our printing. If the quality of the print is worse than what is shown we just will not use it, we will re-print.
So the first use would be that we are using those electrodes as the souce and drain for a transistor. So what I would do is find the total path length between the fingers and then the distance between the fingers. (in the code I attached to the original post, what I did was edge detection. Then looked at the length of that edge. Then had the user define the path and add up all the edge length to give the total length. This was the only way I could think to do it.) This would then be the transistor channel length and the channel width. I then feed this info into to some fitting software I wrote in matlab to help extract other parameters.
If you have any other suggestions towards a better way to do this, that would be great. This may be a terrible method, I could just not think of a different way.
Thanks for the help.
What I'd do is to threshold the image then call bwdist() and bwmorph(bw, ''skel', inf) to get the Euclidean distance transform and the skeleton. If you multiply those two images together you get the thickness of the "in between" part, or the thickness of the electrodes, depending on what's being represented by the binary image. Something like (untested)
binaryImage = grayImage > someThreshold;
edtImage = bwdist(~binaryImage);
skelImage = bwmorph(binaryImage, 'skel', inf);
distanceImage = edtImage .* skelImage;
[skelRows, skelColumns] = find(skelImage);
From that, you can get the min distance, max distance, thickness, and means or distributions of any of those.
minThickness = min(edtImage(skelImage));
maxThickness = max(distanceImage);
etc.
It's just a few lines of code so see if you can do it over the next half hour or so. Post your code. I'll check back later this morning.
I wrote some code based on your suggestion. I had looked at some of these before but was not sure how to implement them together.
I am not exactly sure how to extract the info from what you said.
I tried looking at just the min and max thickness. So min is always 1, which makes sense because of the skel transform. while max does give values that look correct I am not sure how to get the actual value for channel length. I tried a bunch of stuff. I took the sum of maxthickness, this did not give the correct answer. Then I tried the look at differences in distanceImage and take the sum.
Can you take a look and see if I have done something stupid.
Hi Image
If you have a chance could you look at the latest code I have uploaded and see if I made a mistake. I followed what you outlined but I do not think I am getting the correct answer.
No - lots of problems with your code. Just see my attached code.
0000 Screenshot.png
0001 Screenshot.png

Sign in to comment.

Answers (0)

Asked:

on 19 Jan 2019

Commented:

on 7 Feb 2019

Community Treasure Hunt

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

Start Hunting!