mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
biasTowardsWhite was, embarassingly, not accomplishing anything mathematically. It proved to not have much value so has been removed, to simplify the code.
git-svn-id: https://zxing.googlecode.com/svn/trunk@313 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
5f1428308d
commit
7de539a67c
|
@ -83,7 +83,6 @@ final class RGBMonochromeBitmapSource implements MonochromeBitmapSource {
|
|||
int width = image.width();
|
||||
int height = image.height();
|
||||
int[] histogram = new int[LUMINANCE_BUCKETS];
|
||||
float biasTowardsWhite = 1.0f;
|
||||
if (method.equals(BlackPointEstimationMethod.TWO_D_SAMPLING)) {
|
||||
int minDimension = width < height ? width : height;
|
||||
int startI = height == minDimension ? 0 : (height - width) >> 1;
|
||||
|
@ -96,7 +95,6 @@ final class RGBMonochromeBitmapSource implements MonochromeBitmapSource {
|
|||
if (argument < 0 || argument >= height) {
|
||||
throw new IllegalArgumentException("Row is not within the image: " + argument);
|
||||
}
|
||||
biasTowardsWhite = 2.0f;
|
||||
int[] pixelRow = new int[width];
|
||||
image.getPixels(pixelRow, 0, width, 0, argument, width, 1);
|
||||
for (int x = 0; x < width; x++) {
|
||||
|
@ -105,7 +103,7 @@ final class RGBMonochromeBitmapSource implements MonochromeBitmapSource {
|
|||
} else {
|
||||
throw new IllegalArgumentException("Unknown method: " + method);
|
||||
}
|
||||
blackPoint = BlackPointEstimator.estimate(histogram, biasTowardsWhite) << LUMINANCE_SHIFT;
|
||||
blackPoint = BlackPointEstimator.estimate(histogram) << LUMINANCE_SHIFT;
|
||||
lastMethod = method;
|
||||
lastArgument = argument;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,6 @@ final class YUVMonochromeBitmapSource implements MonochromeBitmapSource {
|
|||
int width = image.width();
|
||||
int height = image.height();
|
||||
int[] histogram = new int[LUMINANCE_BUCKETS];
|
||||
float biasTowardsWhite = 1.0f;
|
||||
if (method.equals(BlackPointEstimationMethod.TWO_D_SAMPLING)) {
|
||||
int minDimension = width < height ? width : height;
|
||||
int startI = height == minDimension ? 0 : (height - width) >> 1;
|
||||
|
@ -98,7 +97,6 @@ final class YUVMonochromeBitmapSource implements MonochromeBitmapSource {
|
|||
if (argument < 0 || argument >= height) {
|
||||
throw new IllegalArgumentException("Row is not within the image: " + argument);
|
||||
}
|
||||
biasTowardsWhite = 2.0f;
|
||||
int[] pixelRow = new int[width];
|
||||
image.getPixels(pixelRow, 0, width, 0, argument, width, 1);
|
||||
for (int x = 0; x < width; x++) {
|
||||
|
@ -107,7 +105,7 @@ final class YUVMonochromeBitmapSource implements MonochromeBitmapSource {
|
|||
} else {
|
||||
throw new IllegalArgumentException("Unknown method: " + method);
|
||||
}
|
||||
blackPoint = BlackPointEstimator.estimate(histogram, biasTowardsWhite) << LUMINANCE_SHIFT;
|
||||
blackPoint = BlackPointEstimator.estimate(histogram) << LUMINANCE_SHIFT;
|
||||
lastMethod = method;
|
||||
lastArgument = argument;
|
||||
}
|
||||
|
|
|
@ -40,18 +40,11 @@ public final class BlackPointEstimator {
|
|||
* count of the brightest luminance values that should be considered "black".</p>
|
||||
*
|
||||
* @param histogram an array of <em>counts</em> of luminance values
|
||||
* @param biasTowardsWhite values higher than 1.0 suggest that a higher black point is desirable (e.g.
|
||||
* more values are considered black); less than 1.0 suggests that lower is desirable. Must be greater
|
||||
* than 0.0; 1.0 is a good "default"
|
||||
* @return index within argument of bucket corresponding to brightest values which should be
|
||||
* considered "black"
|
||||
* @throws ReaderException if "black" and "white" appear to be very close in luminance in the image
|
||||
*/
|
||||
public static int estimate(int[] histogram, float biasTowardsWhite) throws ReaderException{
|
||||
|
||||
if (Float.isNaN(biasTowardsWhite) || biasTowardsWhite <= 0.0f) {
|
||||
throw new IllegalArgumentException("Illegal biasTowardsWhite: " + biasTowardsWhite);
|
||||
}
|
||||
public static int estimate(int[] histogram) throws ReaderException{
|
||||
|
||||
int numBuckets = histogram.length;
|
||||
|
||||
|
@ -99,7 +92,7 @@ public final class BlackPointEstimator {
|
|||
int bestValley = secondPeak - 1;
|
||||
int bestValleyScore = -1;
|
||||
for (int i = secondPeak - 1; i > firstPeak; i--) {
|
||||
int fromFirst = (int) (biasTowardsWhite * (i - firstPeak));
|
||||
int fromFirst = i - firstPeak;
|
||||
// Favor a "valley" that is not too close to either peak -- especially not the black peak --
|
||||
// and that has a low value of course
|
||||
int score = fromFirst * fromFirst * (secondPeak - i) * (256 - histogram[i]);
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright 2008 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.common;
|
||||
|
||||
import com.google.zxing.ReaderException;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class BlackPointEstimationMethodTestCase extends TestCase {
|
||||
|
||||
public void testBasic() throws ReaderException {
|
||||
int[] histogram = { 0, 0, 11, 43, 37, 18, 3, 1, 0, 0, 13, 36, 24, 0, 11, 2 };
|
||||
int point = BlackPointEstimator.estimate(histogram);
|
||||
assertEquals(8, point);
|
||||
}
|
||||
|
||||
public void testTooLittleRange() {
|
||||
try {
|
||||
int[] histogram = { 0, 0, 0, 0, 0, 0, 1, 43, 48, 18, 3, 1, 0, 0, 0, 0 };
|
||||
BlackPointEstimator.estimate(histogram);
|
||||
fail("Should have thrown an exception");
|
||||
} catch (ReaderException re) {
|
||||
// good
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -81,7 +81,6 @@ public final class LCDUIImageMonochromeBitmapSource implements MonochromeBitmapS
|
|||
public void estimateBlackPoint(BlackPointEstimationMethod method, int argument) throws ReaderException {
|
||||
if (!method.equals(lastMethod) || argument != lastArgument) {
|
||||
int[] histogram = new int[LUMINANCE_BUCKETS];
|
||||
float biasTowardsWhite = 1.0f;
|
||||
if (method.equals(BlackPointEstimationMethod.TWO_D_SAMPLING)) {
|
||||
int minDimension = width < height ? width : height;
|
||||
for (int n = 0, offset = 0; n < minDimension; n++, offset += width + 1) {
|
||||
|
@ -91,7 +90,6 @@ public final class LCDUIImageMonochromeBitmapSource implements MonochromeBitmapS
|
|||
if (argument < 0 || argument >= height) {
|
||||
throw new IllegalArgumentException("Row is not within the image: " + argument);
|
||||
}
|
||||
biasTowardsWhite = 2.0f;
|
||||
int offset = argument * width;
|
||||
for (int x = 0; x < width; x++) {
|
||||
histogram[computeRGBLuminance(rgbPixels[offset + x]) >> LUMINANCE_SHIFT]++;
|
||||
|
@ -99,7 +97,7 @@ public final class LCDUIImageMonochromeBitmapSource implements MonochromeBitmapS
|
|||
} else {
|
||||
throw new IllegalArgumentException("Unknown method: " + method);
|
||||
}
|
||||
blackPoint = BlackPointEstimator.estimate(histogram, biasTowardsWhite) << LUMINANCE_SHIFT;
|
||||
blackPoint = BlackPointEstimator.estimate(histogram) << LUMINANCE_SHIFT;
|
||||
lastMethod = method;
|
||||
lastArgument = argument;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,6 @@ public final class BufferedImageMonochromeBitmapSource implements MonochromeBitm
|
|||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
int[] histogram = new int[LUMINANCE_BUCKETS];
|
||||
float biasTowardsWhite = 1.0f;
|
||||
if (method.equals(BlackPointEstimationMethod.TWO_D_SAMPLING)) {
|
||||
int minDimension = width < height ? width : height;
|
||||
int startI = height == minDimension ? 0 : (height - width) >> 1;
|
||||
|
@ -101,7 +100,6 @@ public final class BufferedImageMonochromeBitmapSource implements MonochromeBitm
|
|||
if (argument < 0 || argument >= height) {
|
||||
throw new IllegalArgumentException("Row is not within the image: " + argument);
|
||||
}
|
||||
biasTowardsWhite = 2.0f;
|
||||
int[] rgbArray = new int[width];
|
||||
image.getRGB(0, argument, width, 1, rgbArray, 0, width);
|
||||
for (int x = 0; x < width; x++) {
|
||||
|
@ -110,7 +108,7 @@ public final class BufferedImageMonochromeBitmapSource implements MonochromeBitm
|
|||
} else {
|
||||
throw new IllegalArgumentException("Unknown method: " + method);
|
||||
}
|
||||
blackPoint = BlackPointEstimator.estimate(histogram, biasTowardsWhite) << LUMINANCE_SHIFT;
|
||||
blackPoint = BlackPointEstimator.estimate(histogram) << LUMINANCE_SHIFT;
|
||||
lastMethod = method;
|
||||
lastArgument = argument;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue