# Signal processing to detect "jag-iness"?  I have an industrial application where I am using a camera to measure the gap between two pieces of plastic. In the above image I have found the gap and colored it green.

I want to be able to analyze the amount of high frequency "jaggies" in this gap, so I can reject photos where the edges between the two pieces is too rough.

My first thought was to build a 1-D matrix [x1,x2,x3,....] with the number of gap pixels in each column of my image (above). Then do a DFT and use that to filter out noise.

My problem is that I do not understand the output of the Mat::dft() function and how to transform it to get the answer I want. My second (contributing) problem is that I don't really have a good conceptual framework for gauging how "jaggy" an image is, except that I know a jaggy image when I see it.

I would appreciate any suggestions for how to solve my problem.

edit retag close merge delete

Hi @shedletsky I can't understand the term "Jaggy".Is that term refers to smoothness? is it the Lower part of the edges(Green Area) are more Jaggy & Upper part are less jaggy?

Jaggies are high frequency noise, like in the bottom of the image. Big ugly chunky pixels.

Sort by » oldest newest most voted

imho, using dft for this is slightly overkill, since it sounds, you're only interested in the deviation from the straight distance between the lines (not so much the frequency distribution of that deviation), let's try a much more simple approach using a Sobel filter:

int jaggy(const String &name)
{

// might be a simple grayscale conversion, but for now:
Mat green;
extractChannel(ocv,green,1);

// threshold and invert
Mat bin;
threshold(green, bin, 0, 255, THRESH_OTSU|THRESH_BINARY_INV);
imshow(name, bin);

// 1st x/y derivative., find any non-horizontal. edge
Mat sob; Sobel(bin,sob,-1,1,1);
imshow(name + "_sob", sob);
waitKey(1);

// now they know how many holes it takes to fill the albert haaallll...
int s = countNonZero(sob);
cerr << s << endl;
return s;
}

void main()
{
int s1 = jaggy("jaggy.png");
int s2 = jaggy("smooth.png");
waitKey();
}


220
36


here's a smoothed version of your img: and the comparative output: more

That is a great idea. Thanks for the very thoughtful response.

Just for my intellectual curiosity, this solution works because the line is horizontal. How would I handle this problem in the more general case? For example, if instead of a line I had a jaggy triangle polyline?

Official site

GitHub

Wiki

Documentation