Ask Your Question
1

Signal processing to detect "jag-iness"?

asked 2015-09-24 15:54:17 -0600

shedletsky gravatar image

updated 2015-10-19 05:21:22 -0600

C:\fakepath\gap.png 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 flag offensive close merge delete

Comments

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?

Balaji R gravatar imageBalaji R ( 2015-09-24 22:39:13 -0600 )edit

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

shedletsky gravatar imageshedletsky ( 2015-09-29 13:19:36 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
4

answered 2015-09-24 23:58:44 -0600

berak gravatar image

updated 2015-09-25 00:16:41 -0600

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)
{
    Mat ocv = imread(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:

image description

and the comparative output: image description

edit flag offensive delete link more

Comments

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

shedletsky gravatar imageshedletsky ( 2015-09-29 13:17:59 -0600 )edit

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?

shedletsky gravatar imageshedletsky ( 2015-09-29 13:21:52 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-09-24 15:54:17 -0600

Seen: 635 times

Last updated: Sep 25 '15