There seem to be a number of smart math/cs people on this board so I thought I'd ask this here.
Lately, as a side project in my AI class, I've been trying to write a program to detect shapes in an image. I've used Canny edge detection and the Hough transform algorithm and my program identifies circles pretty well now.
Basically, my Hough algorithm starts on an edge point, finds the slope of the line perpendicular to the tangent, and traces that line across the whole image, dropping "votes" in "bins" which cover a certain number of pixels. So I store a tuple containing the x,y coordinate of the original edge point in each "bin" it crosses, so pseudocode/python:
…and again for the other side, e.g. x-=dx and y-=dx.
So I understand how to detect a circle, and my program is pretty good at that. The center will be in the bin with the most elements, and the radius can just be found with the mean of the hypotenuses. But concentric circles are proving to be a bit problematic. My first thought is to try to sort the list of radii, approximate derivatives and try to find outliers in slope. My reasoning is that the points of discontinuity will identify which "votes" belong to which circle. However, there are three problems here: 1) Background noise will show up as discontinuities, so I need to eliminate huge outliers. 2) There might not be enough data points to approximate a good derivative. However since I'm inherently looking at the bin with the most data points, I think it'll be ok. And 3) I know next to nothing about statistics because at my high school it's either calculus or statistics, and I picked calc (no regrets there). I don't have any idea what the mathematical way to identify an outlier would be.
So then, I have two questions. Is this the wrong way to do it, if so, what's a better way? And second, if it is the right way, how do I/where can I learn how to find outliers?
I have some very vague ideas on how to detect other shapes like squares or triangles, but I'm having trouble thinking of a particularly good way. Naturally nothing involving this sort of image processing is going to be 100% accurate, but being able to identify "that bit is squarish" and "that bit is kinda round" seems perfectly plausible to me.
I apologize if this entire post reeks of ignorance. If it does, please keep in mind that I'm just an ignorant high school student
Thanks in advance for the help!
Lately, as a side project in my AI class, I've been trying to write a program to detect shapes in an image. I've used Canny edge detection and the Hough transform algorithm and my program identifies circles pretty well now.
Basically, my Hough algorithm starts on an edge point, finds the slope of the line perpendicular to the tangent, and traces that line across the whole image, dropping "votes" in "bins" which cover a certain number of pixels. So I store a tuple containing the x,y coordinate of the original edge point in each "bin" it crosses, so pseudocode/python:
Code:
x, xi = [initial x]; y, yi=[initial y] theta=[angle of perp. line] dx=cos(theta); dy=sin(theta) while (x and y are within bounds): x+=dx y+=dy bins[x/binsize][y/binsize].append((x,y))
So I understand how to detect a circle, and my program is pretty good at that. The center will be in the bin with the most elements, and the radius can just be found with the mean of the hypotenuses. But concentric circles are proving to be a bit problematic. My first thought is to try to sort the list of radii, approximate derivatives and try to find outliers in slope. My reasoning is that the points of discontinuity will identify which "votes" belong to which circle. However, there are three problems here: 1) Background noise will show up as discontinuities, so I need to eliminate huge outliers. 2) There might not be enough data points to approximate a good derivative. However since I'm inherently looking at the bin with the most data points, I think it'll be ok. And 3) I know next to nothing about statistics because at my high school it's either calculus or statistics, and I picked calc (no regrets there). I don't have any idea what the mathematical way to identify an outlier would be.
So then, I have two questions. Is this the wrong way to do it, if so, what's a better way? And second, if it is the right way, how do I/where can I learn how to find outliers?
I have some very vague ideas on how to detect other shapes like squares or triangles, but I'm having trouble thinking of a particularly good way. Naturally nothing involving this sort of image processing is going to be 100% accurate, but being able to identify "that bit is squarish" and "that bit is kinda round" seems perfectly plausible to me.
I apologize if this entire post reeks of ignorance. If it does, please keep in mind that I'm just an ignorant high school student

Thanks in advance for the help!
Comment