use of boofcv.struct.image.GrayI in project BoofCV by lessthanoptimal.
the class TestImplEnhanceHistogram method equalizeLocalNaive.
/**
* Validate naive algorithm by comparing it against to the full image equalization that has been passed
* sub-images.
*/
@Test
void equalizeLocalNaive() {
int numFound = 0;
Method[] methods = ImplEnhanceHistogram.class.getMethods();
for (Method method : methods) {
if (method.getName().compareTo("equalizeLocalNaive") != 0)
continue;
numFound++;
Class imageType = method.getParameterTypes()[0];
GrayI input = (GrayI) GeneralizedImageOps.createSingleBand(imageType, width, height);
GrayI output = (GrayI) GeneralizedImageOps.createSingleBand(imageType, width, height);
equalizeLocalNaive(input, output);
BoofTesting.checkSubImage(this, "equalizeLocalNaive", true, input, output);
}
assertEquals(2, numFound);
}
use of boofcv.struct.image.GrayI in project BoofCV by lessthanoptimal.
the class TestImplEnhanceHistogram method equalizeLocalNaive.
public void equalizeLocalNaive(GrayI input, GrayI output) {
GrayI tmp = GeneralizedImageOps.createSingleBand(input.getClass(), input.width, input.height);
GrowArray<DogArray_I32> workArrays = new GrowArray<>(DogArray_I32::new);
GImageMiscOps.fillUniform(input, rand, 0, 9);
for (int radius = 1; radius < 11; radius++) {
BoofTesting.callStaticMethod(ImplEnhanceHistogram.class, "equalizeLocalNaive", input, radius, histogramLength, output, workArrays);
int width = 2 * radius + 1;
for (int y = 0; y < height; y++) {
int y0 = y - radius;
int y1 = y + radius + 1;
if (y0 < 0) {
y0 = 0;
y1 = y0 + width;
if (y1 > input.height)
y1 = input.height;
} else if (y1 > input.height) {
y1 = input.height;
y0 = y1 - width;
if (y0 < 0)
y0 = 0;
}
for (int x = 0; x < input.width; x++) {
int x0 = x - radius;
int x1 = x + radius + 1;
if (x0 < 0) {
x0 = 0;
x1 = x0 + width;
if (x1 > input.width)
x1 = input.width;
} else if (x1 > input.width) {
x1 = input.width;
x0 = x1 - width;
if (x0 < 0)
x0 = 0;
}
// use the full image algorithm
int[] histogram = new int[10];
int[] transform = new int[10];
GrayI subIn = (GrayI) input.subimage(x0, y0, x1, y1, null);
GrayI subOut = (GrayI) tmp.subimage(x0, y0, x1, y1, null);
GImageStatistics.histogram(subIn, 0, histogram);
EnhanceImageOps.equalize(histogram, transform);
GEnhanceImageOps.applyTransform(subIn, transform, 0, subOut);
int expected = subOut.get(x - x0, y - y0);
int found = output.get(x, y);
assertEquals(expected, found, x + " " + y);
}
}
}
}
use of boofcv.struct.image.GrayI in project BoofCV by lessthanoptimal.
the class TestImplEnhanceHistogram method equalizeLocalInner.
public void equalizeLocalInner(GrayI input, GrayI found) {
GrayI expected = GeneralizedImageOps.createSingleBand(input.getClass(), input.width, input.height);
GrowArray<DogArray_I32> workArrays = new GrowArray<>(DogArray_I32::new);
GImageMiscOps.fillUniform(input, rand, 0, 9);
for (int radius = 1; radius < 6; radius++) {
// fill with zeros so it can be tested using checkBorderZero
GImageMiscOps.fill(found, 0);
BoofTesting.callStaticMethod(ImplEnhanceHistogram.class, "equalizeLocalNaive", input, radius, histogramLength, expected, workArrays);
BoofTesting.callStaticMethod(ImplEnhanceHistogram.class, "equalizeLocalInner", input, radius, histogramLength, found, workArrays);
BoofTesting.assertEqualsInner(expected, found, 1e-10, radius, radius, false);
BoofTesting.checkBorderZero(found, radius);
}
}
use of boofcv.struct.image.GrayI in project BoofCV by lessthanoptimal.
the class TestImplEnhanceHistogram method equalizeLocalRow.
@Test
void equalizeLocalRow() {
int numFound = 0;
Method[] methods = ImplEnhanceHistogram.class.getMethods();
for (Method method : methods) {
if (method.getName().compareTo("equalizeLocalRow") != 0)
continue;
numFound++;
Class imageType = method.getParameterTypes()[0];
GrayI input = (GrayI) GeneralizedImageOps.createSingleBand(imageType, width, height);
GrayI output = (GrayI) GeneralizedImageOps.createSingleBand(imageType, width, height);
equalizeLocalRow(input, output);
BoofTesting.checkSubImage(this, "equalizeLocalRow", true, input, output);
}
assertEquals(2, numFound);
}
use of boofcv.struct.image.GrayI in project BoofCV by lessthanoptimal.
the class TestImplEnhanceHistogram method equalizeLocalCol.
public void equalizeLocalCol(GrayI input, GrayI found) {
GrayI expected = GeneralizedImageOps.createSingleBand(input.getClass(), input.width, input.height);
GrowArray<DogArray_I32> workArrays = new GrowArray<>(DogArray_I32::new);
GImageMiscOps.fillUniform(input, rand, 1, 9);
// check the left column
for (int radius = 1; radius < 6; radius++) {
// fill with zeros so it can be tested using checkBorderZero
GImageMiscOps.fill(found, 0);
BoofTesting.callStaticMethod(ImplEnhanceHistogram.class, "equalizeLocalNaive", input, radius, histogramLength, expected, workArrays);
BoofTesting.callStaticMethod(ImplEnhanceHistogram.class, "equalizeLocalCol", input, radius, histogramLength, 0, found, workArrays);
GrayI subExpected = (GrayI) expected.subimage(0, radius, radius, height - radius - 1, null);
GrayI subFound = (GrayI) found.subimage(0, radius, radius, height - radius - 1, null);
// check solution
BoofTesting.assertEquals(subExpected, subFound, 1e-10);
checkZeroOutsideColumns(found, 0, radius, radius);
}
// check the right column
for (int radius = 1; radius < 6; radius++) {
// fill with zeros so it can be tested using checkBorderZero
GImageMiscOps.fill(found, 0);
int start = input.width - radius;
BoofTesting.callStaticMethod(ImplEnhanceHistogram.class, "equalizeLocalNaive", input, radius, histogramLength, expected, workArrays);
BoofTesting.callStaticMethod(ImplEnhanceHistogram.class, "equalizeLocalCol", input, radius, histogramLength, start, found, workArrays);
GrayI subExpected = (GrayI) expected.subimage(start, radius, width, height - radius - 1, null);
GrayI subFound = (GrayI) found.subimage(start, radius, width, height - radius - 1, null);
// check solution
BoofTesting.assertEquals(subExpected, subFound, 1e-10);
checkZeroOutsideColumns(found, start, width, radius);
}
}
Aggregations