1 | initial version |
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:
int jaggy(const String &name)
{
Mat ocv = imread(name);
// might be a simple grayscale conversion, but for now:
Mat green;
extractChannel(ocv,green,1);
// theshold 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(sy);
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:
2 | No.2 Revision |
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:
int jaggy(const String &name)
{
Mat ocv = imread(name);
// might be a simple grayscale conversion, but for now:
Mat green;
extractChannel(ocv,green,1);
// theshold 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(sy);
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:
3 | No.3 Revision |
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:
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(sy);
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:
4 | No.4 Revision |
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: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:
and the comparative output: