Tesseract-android-tools  1.0
 Todo Clases Namespaces Archivos Funciones Variables
Binarize.java
Ir a la documentación de este archivo.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
00015  */
00016 
00026 package com.googlecode.leptonica.android;
00027 
00032 public class Binarize {
00033         static {
00034                 System.loadLibrary("lept");
00035         }
00036 
00037         // Otsu thresholding constants
00038 
00040         public final static int OTSU_SIZE_X = 32;
00041 
00043         public final static int OTSU_SIZE_Y = 32;
00044 
00046         public final static int OTSU_SMOOTH_X = 2;
00047 
00049         public final static int OTSU_SMOOTH_Y = 2;
00050 
00052         public final static float OTSU_SCORE_FRACTION = 0.1f;
00053 
00062         public static Pix otsuAdaptiveThreshold(Pix pixs) {
00063                 return otsuAdaptiveThreshold(pixs, OTSU_SIZE_X, OTSU_SIZE_Y,
00064                                 OTSU_SMOOTH_X, OTSU_SMOOTH_Y, OTSU_SCORE_FRACTION);
00065         }
00066 
00123         public static Pix otsuAdaptiveThreshold(Pix pixs, int sizeX, int sizeY,
00124                         int smoothX, int smoothY, float scoreFraction) {
00125                 if (pixs == null)
00126                         throw new IllegalArgumentException("Source pix must be non-null");
00127                 if (pixs.getDepth() != 8)
00128                         throw new IllegalArgumentException("Source pix depth must be 8bpp");
00129 
00130                 int nativePix = nativeOtsuAdaptiveThreshold(pixs.mNativePix, sizeX,
00131                                 sizeY, smoothX, smoothY, scoreFraction);
00132 
00133                 if (nativePix == 0)
00134                         throw new RuntimeException(
00135                                         "Failed to perform Otsu adaptive threshold on image");
00136 
00137                 return new Pix(nativePix);
00138         }
00139 
00140         // ***************
00141         // * NATIVE CODE *
00142         // ***************
00143 
00144         private static native int nativeOtsuAdaptiveThreshold(int nativePix,
00145                         int sizeX, int sizeY, int smoothX, int smoothY, float scoreFract);
00146 }
 Todo Clases Namespaces Archivos Funciones Variables