private void printBlockUnsafe(AutoTypeImage image) {
    String sumType = image.getSumType();
    String bitWise = image.getBitWise();

    out.print(
        "\tpublic static "
            + sumType
            + " block_unsafe( "
            + image.getSingleBandName()
            + " integral , int x0 , int y0 , int x1 , int y1 )\n"
            + "\t{\n"
            + "\t\t"
            + sumType
            + " br = integral.data[ integral.startIndex + y1*integral.stride + x1 ]"
            + bitWise
            + ";\n"
            + "\t\t"
            + sumType
            + " tr = integral.data[ integral.startIndex + y0*integral.stride + x1 ]"
            + bitWise
            + ";\n"
            + "\t\t"
            + sumType
            + " bl = integral.data[ integral.startIndex + y1*integral.stride + x0 ]"
            + bitWise
            + ";\n"
            + "\t\t"
            + sumType
            + " tl = integral.data[ integral.startIndex + y0*integral.stride + x0 ]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\treturn br-tr-bl+tl;\n"
            + "\t}\n\n");
  }
 private void printConvolveBorder(AutoTypeImage imageIn, AutoTypeImage imageOut) {
   String sumType = imageIn.getSumType();
   out.print(
       "\tpublic static void convolveBorder( "
           + imageIn.getSingleBandName()
           + " integral ,\n"
           + "\t\t\t\t\t\t\t\t\t   IntegralKernel kernel,\n"
           + "\t\t\t\t\t\t\t\t\t   "
           + imageOut.getSingleBandName()
           + " output , int borderX , int borderY )\n"
           + "\t{\n"
           + "\t\tfor( int x = 0; x < integral.width; x++ ) {\n"
           + "\t\t\tfor( int y = 0; y < borderY; y++ ) {\n"
           + "\t\t\t\t"
           + sumType
           + " total = 0;\n"
           + "\t\t\t\tfor( int i = 0; i < kernel.blocks.length; i++ ) {\n"
           + "\t\t\t\t\tImageRectangle b = kernel.blocks[i];\n"
           + "\t\t\t\t\ttotal += block_zero(integral,x+b.x0,y+b.y0,x+b.x1,y+b.y1)*kernel.scales[i];\n"
           + "\t\t\t\t}\n"
           + "\t\t\t\toutput.set(x,y,total);\n"
           + "\t\t\t}\n"
           + "\t\t\tfor( int y = integral.height-borderY; y < integral.height; y++ ) {\n"
           + "\t\t\t\t"
           + sumType
           + " total = 0;\n"
           + "\t\t\t\tfor( int i = 0; i < kernel.blocks.length; i++ ) {\n"
           + "\t\t\t\t\tImageRectangle b = kernel.blocks[i];\n"
           + "\t\t\t\t\ttotal += block_zero(integral,x+b.x0,y+b.y0,x+b.x1,y+b.y1)*kernel.scales[i];\n"
           + "\t\t\t\t}\n"
           + "\t\t\t\toutput.set(x,y,total);\n"
           + "\t\t\t}\n"
           + "\t\t}\n"
           + "\n"
           + "\t\tint endY = integral.height-borderY;\n"
           + "\t\tfor( int y = borderY; y < endY; y++ ) {\n"
           + "\t\t\tfor( int x = 0; x < borderX; x++ ) {\n"
           + "\t\t\t\t"
           + sumType
           + " total = 0;\n"
           + "\t\t\t\tfor( int i = 0; i < kernel.blocks.length; i++ ) {\n"
           + "\t\t\t\t\tImageRectangle b = kernel.blocks[i];\n"
           + "\t\t\t\t\ttotal += block_zero(integral,x+b.x0,y+b.y0,x+b.x1,y+b.y1)*kernel.scales[i];\n"
           + "\t\t\t\t}\n"
           + "\t\t\t\toutput.set(x,y,total);\n"
           + "\t\t\t}\n"
           + "\t\t\tfor( int x = integral.width-borderX; x < integral.width; x++ ) {\n"
           + "\t\t\t\t"
           + sumType
           + " total = 0;\n"
           + "\t\t\t\tfor( int i = 0; i < kernel.blocks.length; i++ ) {\n"
           + "\t\t\t\t\tImageRectangle b = kernel.blocks[i];\n"
           + "\t\t\t\t\ttotal += block_zero(integral,x+b.x0,y+b.y0,x+b.x1,y+b.y1)*kernel.scales[i];\n"
           + "\t\t\t\t}\n"
           + "\t\t\t\toutput.set(x,y,total);\n"
           + "\t\t\t}\n"
           + "\t\t}\n"
           + "\t}\n\n");
 }
  private void sharpen4(AutoTypeImage image) {
    String name = image.getSingleBandName();
    String bitwise = image.getBitWise();
    String cast = image.getTypeCastFromSum();
    String sumtype = image.getSumType();

    out.print(
        "\tpublic static void sharpenInner4( "
            + name
            + " input , "
            + name
            + " output , "
            + sumtype
            + " minValue , "
            + sumtype
            + " maxValue ) {\n"
            + "\t\tfor( int y = 1; y < input.height-1; y++ ) {\n"
            + "\t\t\tint indexIn = input.startIndex + y*input.stride + 1;\n"
            + "\t\t\tint indexOut = output.startIndex + y*output.stride + 1;\n"
            + "\n"
            + "\t\t\tfor( int x = 1; x < input.width-1; x++ , indexIn++,indexOut++) {\n"
            + "\n"
            + "\t\t\t\t"
            + sumtype
            + " a = 5*(input.data[indexIn] "
            + bitwise
            + ") - (\n"
            + "\t\t\t\t\t\t(input.data[indexIn-1] "
            + bitwise
            + ")+(input.data[indexIn+1] "
            + bitwise
            + ") +\n"
            + "\t\t\t\t\t\t\t\t(input.data[indexIn-input.stride] "
            + bitwise
            + ") + (input.data[indexIn+input.stride] "
            + bitwise
            + "));\n"
            + "\n"
            + "\t\t\t\tif( a > maxValue )\n"
            + "\t\t\t\t\ta = maxValue;\n"
            + "\t\t\t\telse if( a < minValue )\n"
            + "\t\t\t\t\ta = minValue;\n"
            + "\n"
            + "\t\t\t\toutput.data[indexOut] = "
            + cast
            + "a;\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t}\n\n");
  }
  private void printFuncs(AutoTypeImage imageIn, AutoTypeImage imageOut) {
    this.imageIn = imageIn;
    this.imageOut = imageOut;

    if (imageIn.isInteger()) genName = "I32";
    else genName = "F" + imageIn.getNumBits();
    ;

    sumType = imageIn.getSumType();

    printHorizontal();
    printVertical();
    printHorizontalInverse();
    printVerticalInverse();
  }
  private void printTransform(AutoTypeImage imageIn, AutoTypeImage imageOut) {

    String sumType = imageOut.getSumType();
    String bitWise = imageIn.getBitWise();
    String typeCast = imageOut.getTypeCastFromSum();

    out.print(
        "\tpublic static void transform( final "
            + imageIn.getSingleBandName()
            + " input , final "
            + imageOut.getSingleBandName()
            + " transformed )\n"
            + "\t{\n"
            + "\t\tint indexSrc = input.startIndex;\n"
            + "\t\tint indexDst = transformed.startIndex;\n"
            + "\t\tint end = indexSrc + input.width;\n"
            + "\n"
            + "\t\t"
            + sumType
            + " total = 0;\n"
            + "\t\tfor( ; indexSrc < end; indexSrc++ ) {\n"
            + "\t\t\ttransformed.data[indexDst++] = "
            + typeCast
            + "total += input.data[indexSrc]"
            + bitWise
            + ";\n"
            + "\t\t}\n"
            + "\n"
            + "\t\tfor( int y = 1; y < input.height; y++ ) {\n"
            + "\t\t\tindexSrc = input.startIndex + input.stride*y;\n"
            + "\t\t\tindexDst = transformed.startIndex + transformed.stride*y;\n"
            + "\t\t\tint indexPrev = indexDst - transformed.stride;\n"
            + "\n"
            + "\t\t\tend = indexSrc + input.width;\n"
            + "\n"
            + "\t\t\ttotal = 0;\n"
            + "\t\t\tfor( ; indexSrc < end; indexSrc++ ) {\n"
            + "\t\t\t\ttotal +=  input.data[indexSrc]"
            + bitWise
            + ";\n"
            + "\t\t\t\ttransformed.data[indexDst++] = transformed.data[indexPrev++] + total;\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t}\n\n");
  }
  private void printBlockZero(AutoTypeImage image) {
    String sumType = image.getSumType();
    String bitWise = image.getBitWise();

    out.print(
        "\tpublic static "
            + sumType
            + " block_zero( "
            + image.getSingleBandName()
            + " integral , int x0 , int y0 , int x1 , int y1 )\n"
            + "\t{\n"
            + "\t\tx0 = Math.min(x0,integral.width-1);\n"
            + "\t\ty0 = Math.min(y0,integral.height-1);\n"
            + "\t\tx1 = Math.min(x1,integral.width-1);\n"
            + "\t\ty1 = Math.min(y1,integral.height-1);\n"
            + "\n"
            + "\t\t"
            + sumType
            + " br=0,tr=0,bl=0,tl=0;\n"
            + "\n"
            + "\t\tif( x1 >= 0 && y1 >= 0)\n"
            + "\t\t\tbr = integral.data[ integral.startIndex + y1*integral.stride + x1 ]"
            + bitWise
            + ";\n"
            + "\t\tif( y0 >= 0 && x1 >= 0)\n"
            + "\t\t\ttr = integral.data[ integral.startIndex + y0*integral.stride + x1 ]"
            + bitWise
            + ";\n"
            + "\t\tif( x0 >= 0 && y1 >= 0)\n"
            + "\t\t\tbl = integral.data[ integral.startIndex + y1*integral.stride + x0 ]"
            + bitWise
            + ";\n"
            + "\t\tif( x0 >= 0 && y0 >= 0)\n"
            + "\t\t\ttl = integral.data[ integral.startIndex + y0*integral.stride + x0 ]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\treturn br-tr-bl+tl;\n"
            + "\t}\n\n");
  }
  private void printConvolveSparse(AutoTypeImage image) {
    String sumType = image.getSumType();

    out.print(
        "\tpublic static "
            + sumType
            + " convolveSparse( "
            + image.getSingleBandName()
            + " integral , IntegralKernel kernel , int x , int y )\n"
            + "\t{\n"
            + "\t\t"
            + sumType
            + " ret = 0;\n"
            + "\t\tint N = kernel.getNumBlocks();\n"
            + "\n"
            + "\t\tfor( int i = 0; i < N; i++ ) {\n"
            + "\t\t\tImageRectangle r = kernel.blocks[i];\n"
            + "\t\t\tret += block_zero(integral,x+r.x0,y+r.y0,x+r.x1,y+r.y1)*kernel.scales[i];\n"
            + "\t\t}\n"
            + "\n"
            + "\t\treturn ret;\n"
            + "\t}\n\n");
  }
Example #8
0
  private void createFile(AutoTypeImage imageType) throws FileNotFoundException {
    String suffix = imageType.getAbbreviatedType();
    suffix = suffix.compareTo("S32") == 0 ? "I32" : suffix;
    className = "Kernel1D_" + suffix;

    String sumType = imageType.getSumType();

    setOutputFile(className);
    out.print(
        "/**\n"
            + " * Floating point 1D convolution kernel that extends {@link Kernel1D}.\n"
            + " *\n"
            + " * <p>\n"
            + " * WARNING: Do not modify.  Automatically generated by {@link "
            + getClass().getName()
            + "}.\n"
            + " * </p>\n"
            + " *\n"
            + " * @author Peter Abeles\n"
            + " */\n"
            + "public class "
            + className
            + " extends Kernel1D {\n"
            + "\n"
            + "\tpublic "
            + sumType
            + " data[];\n"
            + "\n"
            + "\t/**\n"
            + "\t * Creates a new kernel whose initial values are specified by data and width.  The length\n"
            + "\t * of its internal data will be width.  Data must be at least as long as width.\n"
            + "\t *\n"
            + "\t * @param data  The value of the kernel. Not modified.  Reference is not saved.\n"
            + "\t * @param width The kernels width.  Must be odd.\n"
            + "\t */\n"
            + "\tpublic "
            + className
            + "("
            + sumType
            + " data[], int width) {\n"
            + "\t\tthis(data,width/2,width);\n"
            + "\t}\n"
            + "\n"
            + "\t/**\n"
            + "\t * Creates a new kernel whose initial values are specified by data and width.  The length\n"
            + "\t * of its internal data will be width.  Data must be at least as long as width.\n"
            + "\t *\n"
            + "\t * @param data  The value of the kernel. Not modified.  Reference is not saved.\n"
            + "\t * @param width The kernels width.  Must be odd.\n"
            + "\t * @param offset Location of the origin in the array\n"
            + "\t */\n"
            + "\tpublic "
            + className
            + "("
            + sumType
            + " data[], int offset , int width) {\n"
            + "\t\tsuper(offset,width);\n"
            + "\n"
            + "\t\tthis.data = new "
            + sumType
            + "[width];\n"
            + "\t\tSystem.arraycopy(data, 0, this.data, 0, width);\n"
            + "\t}\n"
            + "\n"
            + "\t/**\n"
            + "\t * Create a kernel whose elements are all equal to zero.\n"
            + "\t *\n"
            + "\t * @param width How wide the kernel is.  Must be odd.\n"
            + "\t */\n"
            + "\tpublic "
            + className
            + "(int width) {\n"
            + "\t\tthis(width/2,width);\n"
            + "\t}\n"
            + "\n"
            + "\t/**\n"
            + "\t * Create a kernel whose elements are all equal to zero.\n"
            + "\t *\n"
            + "\t * @param width How wide the kernel is.  Must be odd.\n"
            + "\t * @param offset Location of the origin in the array\n"
            + "\t */\n"
            + "\tpublic "
            + className
            + "(int offset , int width) {\n"
            + "\t\tsuper(offset,width);\n"
            + "\t\tdata = new "
            + sumType
            + "[width];\n"
            + "\t}\n"
            + "\n"
            + "\tprotected "
            + className
            + "() {\n"
            + "\t}\n"
            + "\n"
            + "\t/**\n"
            + "\t * Creates a kernel whose elements are the specified data array and has\n"
            + "\t * the specified width.\n"
            + "\t *\n"
            + "\t * @param data  The array who will be the kernel's data.  Reference is saved.\n"
            + "\t * @param width The kernel's width.\n"
            + "\t * @return A new kernel.\n"
            + "\t */\n"
            + "\tpublic static "
            + className
            + " wrap("
            + sumType
            + " data[], int width) {\n"
            + "\t\t"
            + className
            + " ret = new "
            + className
            + "();\n"
            + "\t\tret.data = data;\n"
            + "\t\tret.width = width;\n"
            + "\t\tret.offset = width/2;\n"
            + "\n"
            + "\t\treturn ret;\n"
            + "\t}\n"
            + "\n"
            + "\t@Override\n"
            + "\tpublic boolean isInteger() {\n"
            + "\t\treturn "
            + imageType.isInteger()
            + ";\n"
            + "\t}\n"
            + "\n"
            + "\tpublic "
            + sumType
            + " get(int i) {\n"
            + "\t\treturn data[i];\n"
            + "\t}\n"
            + "\n"
            + "\tpublic "
            + sumType
            + " computeSum() {\n"
            + "\t\t"
            + sumType
            + " sum = 0;\n"
            + "\t\tfor( int i = 0; i < data.length; i++ ) {\n"
            + "\t\t\tsum += data[i];\n"
            + "\t\t}\n"
            + "\n"
            + "\t\treturn sum;\n"
            + "\t}\n"
            + "\n"
            + "\tpublic "
            + sumType
            + "[] getData() {\n"
            + "\t\treturn data;\n"
            + "\t}\n"
            + "\n"
            + "\tpublic void print() {\n"
            + "\t\tfor (int i = 0; i < width; i++) {\n");
    if (imageType.isInteger()) out.print("\t\t\tSystem.out.printf(\"%6d \", data[i]);\n");
    else if (imageType.isInteger()) out.print("\t\t\tSystem.out.printf(\"%6.3f \", data[i]);\n");

    out.print("\t\t}\n" + "\t\tSystem.out.println();\n" + "\t}\n" + "}\n\n");
  }
  private void sharpenBorder8(AutoTypeImage image) {
    String name = image.getSingleBandName();
    String cast = image.getTypeCastFromSum();
    String sumtype = image.getSumType();

    out.print(
        "\tpublic static void sharpenBorder8( "
            + name
            + " input , "
            + name
            + " output , "
            + sumtype
            + " minValue , "
            + sumtype
            + " maxValue ) {\n"
            + "\t\t"
            + sumtype
            + " value;\n"
            + "\n"
            + "\t\tint b = input.height-1;\n"
            + "\t\t"
            + sumtype
            + " a11,a12,a13,a21,a22,a23,a31,a32,a33;\n"
            + "\n"
            + "\t\tint indexTop = input.startIndex;\n"
            + "\t\tint indexBottom = input.startIndex + b*input.stride;\n"
            + "\n"
            + "\t\tfor( int x = 0; x < input.width; x++ ) {\n"
            + "\n"
            + "\t\t\ta11 = safeGet(input,x-1,-1);\n"
            + "\t\t\ta12 = safeGet(input,x  ,-1);\n"
            + "\t\t\ta13 = safeGet(input,x+1,-1);\n"
            + "\t\t\ta21 = safeGet(input,x-1, 0);\n"
            + "\t\t\ta22 = safeGet(input,x  , 0);\n"
            + "\t\t\ta23 = safeGet(input,x+1, 0);\n"
            + "\t\t\ta31 = safeGet(input,x-1, 1);\n"
            + "\t\t\ta32 = safeGet(input,x  , 1);\n"
            + "\t\t\ta33 = safeGet(input,x+1, 1);\n"
            + "\n"
            + "\t\t\tvalue = 9*a22 - (a11+a12+a13+a21+a23+a31+a32+a33);\n"
            + "\n"
            + "\t\t\tif( value > maxValue )\n"
            + "\t\t\t\tvalue = maxValue;\n"
            + "\t\t\telse if( value < minValue )\n"
            + "\t\t\t\tvalue = minValue;\n"
            + "\n"
            + "\t\t\toutput.data[indexTop++] = "
            + cast
            + "value;\n"
            + "\n"
            + "\t\t\ta11 = safeGet(input,x-1,b-1);\n"
            + "\t\t\ta12 = safeGet(input,x  ,b-1);\n"
            + "\t\t\ta13 = safeGet(input,x+1,b-1);\n"
            + "\t\t\ta21 = safeGet(input,x-1, b);\n"
            + "\t\t\ta22 = safeGet(input,x  , b);\n"
            + "\t\t\ta23 = safeGet(input,x+1, b);\n"
            + "\t\t\ta31 = safeGet(input,x-1,b+1);\n"
            + "\t\t\ta32 = safeGet(input,x  ,b+1);\n"
            + "\t\t\ta33 = safeGet(input,x+1,b+1);\n"
            + "\n"
            + "\t\t\tvalue = 9*a22 - (a11+a12+a13+a21+a23+a31+a32+a33);\n"
            + "\n"
            + "\t\t\tif( value > maxValue )\n"
            + "\t\t\t\tvalue = maxValue;\n"
            + "\t\t\telse if( value < minValue )\n"
            + "\t\t\t\tvalue = minValue;\n"
            + "\n"
            + "\t\t\toutput.data[indexBottom++] = "
            + cast
            + "value;\n"
            + "\t\t}\n"
            + "\n"
            + "\t\tb = input.width-1;\n"
            + "\t\tint indexLeft = input.startIndex + input.stride;\n"
            + "\t\tint indexRight = input.startIndex + input.stride + b;\n"
            + "\n"
            + "\t\tfor( int y = 1; y < input.height-1; y++ ) {\n"
            + "\t\t\ta11 = safeGet(input,-1,y-1);\n"
            + "\t\t\ta12 = safeGet(input, 0,y-1);\n"
            + "\t\t\ta13 = safeGet(input,+1,y-1);\n"
            + "\t\t\ta21 = safeGet(input,-1, y );\n"
            + "\t\t\ta22 = safeGet(input, 0, y );\n"
            + "\t\t\ta23 = safeGet(input,+1, y );\n"
            + "\t\t\ta31 = safeGet(input,-1,y+1);\n"
            + "\t\t\ta32 = safeGet(input, 0,y+1);\n"
            + "\t\t\ta33 = safeGet(input,+1,y+1);\n"
            + "\n"
            + "\t\t\tvalue = 9*a22 - (a11+a12+a13+a21+a23+a31+a32+a33);\n"
            + "\n"
            + "\t\t\tif( value > maxValue )\n"
            + "\t\t\t\tvalue = maxValue;\n"
            + "\t\t\telse if( value < minValue )\n"
            + "\t\t\t\tvalue = minValue;\n"
            + "\n"
            + "\t\t\toutput.data[indexLeft] = "
            + cast
            + "value;\n"
            + "\n"
            + "\t\t\ta11 = safeGet(input,b-1,y-1);\n"
            + "\t\t\ta12 = safeGet(input, b ,y-1);\n"
            + "\t\t\ta13 = safeGet(input,b+1,y-1);\n"
            + "\t\t\ta21 = safeGet(input,b-1, y );\n"
            + "\t\t\ta22 = safeGet(input, b , y );\n"
            + "\t\t\ta23 = safeGet(input,b+1, y );\n"
            + "\t\t\ta31 = safeGet(input,b-1,y+1);\n"
            + "\t\t\ta32 = safeGet(input, b ,y+1);\n"
            + "\t\t\ta33 = safeGet(input,b+1,y+1);\n"
            + "\n"
            + "\t\t\tvalue = 9*a22 - (a11+a12+a13+a21+a23+a31+a32+a33);\n"
            + "\n"
            + "\t\t\tif( value > maxValue )\n"
            + "\t\t\t\tvalue = maxValue;\n"
            + "\t\t\telse if( value < minValue )\n"
            + "\t\t\t\tvalue = minValue;\n"
            + "\n"
            + "\t\t\toutput.data[indexRight] = "
            + cast
            + "value;\n"
            + "\n"
            + "\t\t\tindexLeft += input.stride;\n"
            + "\t\t\tindexRight += input.stride;\n"
            + "\t\t}\n"
            + "\t}\n\n");
  }
  private void sharpen8(AutoTypeImage image) {
    String name = image.getSingleBandName();
    String bitwise = image.getBitWise();
    String cast = image.getTypeCastFromSum();
    String sumtype = image.getSumType();

    out.print(
        "\tpublic static void sharpenInner8( "
            + name
            + " input , "
            + name
            + " output , "
            + sumtype
            + " minValue , "
            + sumtype
            + " maxValue ) {\n"
            + "\t\tfor( int y = 1; y < input.height-1; y++ ) {\n"
            + "\t\t\tint indexIn = input.startIndex + y*input.stride + 1;\n"
            + "\t\t\tint indexOut = output.startIndex + y*output.stride + 1;\n"
            + "\n"
            + "\t\t\tfor( int x = 1; x < input.width-1; x++ , indexIn++,indexOut++) {\n"
            + "\n"
            + "\t\t\t\t"
            + sumtype
            + " a11 = input.data[indexIn-input.stride-1] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a12 = input.data[indexIn-input.stride] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a13 = input.data[indexIn-input.stride+1] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a21 = input.data[indexIn-1] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a22 = input.data[indexIn] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a23 = input.data[indexIn+1] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a31 = input.data[indexIn+input.stride-1] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a32 = input.data[indexIn+input.stride] "
            + bitwise
            + ";\n"
            + "\t\t\t\t"
            + sumtype
            + " a33 = input.data[indexIn+input.stride+1] "
            + bitwise
            + ";\n"
            + "\t\t\t\t\n"
            + "\t\t\t\t"
            + sumtype
            + " result = 9*a22 - (a11+a12+a13+a21+a23+a31+a32+a33);\n"
            + "\n"
            + "\t\t\t\tif( result > maxValue )\n"
            + "\t\t\t\t\tresult = maxValue;\n"
            + "\t\t\t\telse if( result < minValue )\n"
            + "\t\t\t\t\tresult = minValue;\n"
            + "\n"
            + "\t\t\t\toutput.data[indexOut] = "
            + cast
            + "result;\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t}\n\n");
  }
  private void sharpenBorder4(AutoTypeImage image) {

    String name = image.getSingleBandName();
    String cast = image.getTypeCastFromSum();
    String sumtype = image.getSumType();

    out.print(
        "\tpublic static void sharpenBorder4( "
            + name
            + " input , "
            + name
            + " output , "
            + sumtype
            + " minValue , "
            + sumtype
            + " maxValue ) {\n"
            + "\t\t"
            + sumtype
            + " value;\n"
            + "\n"
            + "\t\tint b = input.height-1;\n"
            + "\n"
            + "\t\tint indexTop = input.startIndex;\n"
            + "\t\tint indexBottom = input.startIndex + b*input.stride;\n"
            + "\t\t\n"
            + "\t\tfor( int x = 0; x < input.width; x++ ) {\n"
            + "\t\t\tvalue = 4*safeGet(input,x,0) - (safeGet(input,x-1,0) + safeGet(input,x+1,0) + safeGet(input,x,1));\n"
            + "\n"
            + "\t\t\tif( value > maxValue )\n"
            + "\t\t\t\tvalue = maxValue;\n"
            + "\t\t\telse if( value < minValue )\n"
            + "\t\t\t\tvalue = minValue;\n"
            + "\n"
            + "\t\t\toutput.data[indexTop++] = "
            + cast
            + "value;\n"
            + "\n"
            + "\t\t\tvalue = 4*safeGet(input,x,b) - (safeGet(input,x-1,b) + safeGet(input,x+1,b) + safeGet(input,x,b-1));\n"
            + "\n"
            + "\t\t\tif( value > maxValue )\n"
            + "\t\t\t\tvalue = maxValue;\n"
            + "\t\t\telse if( value < minValue )\n"
            + "\t\t\t\tvalue = minValue;\n"
            + "\n"
            + "\t\t\toutput.data[indexBottom++] = "
            + cast
            + "value;\n"
            + "\t\t}\n"
            + "\n"
            + "\t\tb = input.width-1;\n"
            + "\t\tint indexLeft = input.startIndex + input.stride;\n"
            + "\t\tint indexRight = input.startIndex + input.stride + b;\n"
            + "\n"
            + "\t\tfor( int y = 1; y < input.height-1; y++ ) {\n"
            + "\t\t\tvalue = 4*safeGet(input,0,y) - (safeGet(input,1,y) + safeGet(input,0,y-1) + safeGet(input,0,y+1));\n"
            + "\n"
            + "\t\t\tif( value > maxValue )\n"
            + "\t\t\t\tvalue = maxValue;\n"
            + "\t\t\telse if( value < minValue )\n"
            + "\t\t\t\tvalue = minValue;\n"
            + "\n"
            + "\t\t\toutput.data[indexLeft] = "
            + cast
            + "value;\n"
            + "\n"
            + "\t\t\tvalue = 4*safeGet(input,b,y) - (safeGet(input,b-1,y) + safeGet(input,b,y-1) + safeGet(input,b,y+1));\n"
            + "\n"
            + "\t\t\tif( value > maxValue )\n"
            + "\t\t\t\tvalue = maxValue;\n"
            + "\t\t\telse if( value < minValue )\n"
            + "\t\t\t\tvalue = minValue;\n"
            + "\n"
            + "\t\t\toutput.data[indexRight] = "
            + cast
            + "value;\n"
            + "\t\t\t\n"
            + "\t\t\tindexLeft += input.stride;\n"
            + "\t\t\tindexRight += input.stride;\n"
            + "\t\t}\n"
            + "\t}\n\n");
  }