Fix bad logic black point estimator, improving threshold estimation performance ...
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 11 Jun 2008 19:59:38 +0000 (19:59 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 11 Jun 2008 19:59:38 +0000 (19:59 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@417 59b500cc-1b3d-0410-9834-0bbf25fbcc57

android/src/com/google/zxing/client/android/RGBMonochromeBitmapSource.java
core/src/com/google/zxing/common/BlackPointEstimator.java
core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java
javase/src/com/google/zxing/client/j2se/BufferedImageMonochromeBitmapSource.java

index d84a920..f6bf98b 100755 (executable)
@@ -63,7 +63,7 @@ final class RGBMonochromeBitmapSource implements MonochromeBitmapSource {
     // If the current decoder calculated the blackPoint based on one row, assume we're trying to
     // decode a 1D barcode, and apply some sharpening.
     // TODO: We may want to add a fifth parameter to request the amount of shapening to be done.
-    if (lastMethod == BlackPointEstimationMethod.ROW_SAMPLING) {
+    if (lastMethod.equals(BlackPointEstimationMethod.ROW_SAMPLING)) {
       int left = computeRGBLuminance(pixelRow[0]);
       int center = computeRGBLuminance(pixelRow[1]);
       for (int i = 1; i < getWidth - 1; i++) {
index a40a853..ecaf96c 100644 (file)
@@ -47,7 +47,7 @@ public final class BlackPointEstimator {
   public static int estimate(int[] histogram) throws ReaderException{\r
 \r
     int numBuckets = histogram.length;\r
-\r
+    int maxBucketCount = 0;\r
     // Find tallest peak in histogram\r
     int firstPeak = 0;\r
     int firstPeakSize = 0;\r
@@ -56,6 +56,9 @@ public final class BlackPointEstimator {
         firstPeak = i;\r
         firstPeakSize = histogram[i];\r
       }\r
+      if (histogram[i] > maxBucketCount) {\r
+        maxBucketCount = histogram[i];\r
+      }\r
     }\r
 \r
     // Find second-tallest peak -- well, another peak that is tall and not\r
@@ -84,7 +87,7 @@ public final class BlackPointEstimator {
     // Decoding the image/line is either pointless, or may in some cases lead to a false positive\r
     // for 1D formats, which are relatively lenient.\r
     // We arbitrarily say "close" is "<= 1/16 of the total histogram buckets apart"\r
-    if (secondPeak - firstPeak <= histogram.length >> 4) {\r
+    if (secondPeak - firstPeak <= numBuckets >> 4) {\r
       throw new ReaderException("Too little dynamic range in luminance");\r
     }\r
 \r
@@ -95,7 +98,7 @@ public final class BlackPointEstimator {
       int fromFirst = i - firstPeak;\r
       // Favor a "valley" that is not too close to either peak -- especially not the black peak --\r
       // and that has a low value of course\r
-      int score = fromFirst * fromFirst * (secondPeak - i) * (256 - histogram[i]);\r
+      int score = fromFirst * fromFirst * (secondPeak - i) * (maxBucketCount - histogram[i]);\r
       if (score > bestValleyScore) {\r
         bestValley = i;\r
         bestValleyScore = score;\r
index 7e28d88..772cf7a 100644 (file)
@@ -29,8 +29,8 @@ public final class EAN13BlackBox1TestCase extends AbstractBlackBoxTestCase {
 
   public EAN13BlackBox1TestCase() {
     super(new File("test/data/blackbox/ean13-1"), new MultiFormatReader(), BarcodeFormat.EAN_13);
-    addTest(25, 0.0f);
-    addTest(18, 180.0f);
+    addTest(26, 0.0f);
+    addTest(24, 180.0f);
   }
 
 }
\ No newline at end of file
index 77c0d5c..e8396b4 100644 (file)
@@ -120,7 +120,7 @@ public final class BufferedImageMonochromeBitmapSource implements MonochromeBitm
     // If the current decoder calculated the blackPoint based on one row, assume we're trying to
     // decode a 1D barcode, and apply some sharpening.
     // TODO: We may want to add a fifth parameter to request the amount of shapening to be done.
-    if (lastMethod == BlackPointEstimationMethod.ROW_SAMPLING) {
+    if (lastMethod.equals(BlackPointEstimationMethod.ROW_SAMPLING)) {
       int left = computeRGBLuminance(pixelRow[0]);
       int center = computeRGBLuminance(pixelRow[1]);
       for (int i = 1; i < getWidth - 1; i++) {