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 printMultiToInterleaved(AutoTypeImage imageIn) {
    String outputName = imageIn.getInterleavedName();
    String bandName = imageIn.getSingleBandName();

    out.print(
        "\t/**\n"
            + "\t * Converts a {@link MultiSpectral} into the equivalent {@link "
            + outputName
            + "}\n"
            + "\t *\n"
            + "\t * @param input (Input) MultiSpectral image that is being converted. Not modified.\n"
            + "\t * @param output (Optional) The output image.  If null a new image is created. Modified.\n"
            + "\t * @return Converted image.\n"
            + "\t */\n"
            + "\tpublic static "
            + outputName
            + " convert( MultiSpectral<"
            + bandName
            + "> input , "
            + outputName
            + " output ) {\n"
            + "\t\tif (output == null) {\n"
            + "\t\t\toutput = new "
            + outputName
            + "(input.width, input.height,input.getNumBands());\n"
            + "\t\t} else {\n"
            + "\t\t\tInputSanityCheck.checkSameShape(input, output);\n"
            + "\t\t}\n"
            + "\n"
            + "\t\tImplConvertImage.convert(input,output);\n"
            + "\n"
            + "\t\treturn output;\n"
            + "\t}\n\n");
  }
  private void printMultiAverage(AutoTypeImage imageIn) {

    String imageName = imageIn.getSingleBandName();

    out.print(
        "\t/**\n"
            + "\t * Converts a {@link MultiSpectral} into a {@link ImageSingleBand} by computing the average value of each pixel\n"
            + "\t * across all the bands.\n"
            + "\t * \n"
            + "\t * @param input Input MultiSpectral image that is being converted. Not modified.\n"
            + "\t * @param output (Optional) The single band output image.  If null a new image is created. Modified.\n"
            + "\t * @return Converted image.\n"
            + "\t */\n"
            + "\tpublic static "
            + imageName
            + " average( MultiSpectral<"
            + imageName
            + "> input , "
            + imageName
            + " output ) {\n"
            + "\t\tif (output == null) {\n"
            + "\t\t\toutput = new "
            + imageName
            + "(input.width, input.height);\n"
            + "\t\t} else {\n"
            + "\t\t\tInputSanityCheck.checkSameShape(input, output);\n"
            + "\t\t}\n"
            + "\n"
            + "\t\tImplConvertMsToSingle.average(input, output);\n"
            + "\n"
            + "\t\treturn output;\n"
            + "\t}\n\n");
  }
  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 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 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 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");
  }
  private void printConvertSingle(AutoTypeImage imageIn, AutoTypeImage imageOut) {

    out.print(
        "\t/**\n"
            + "\t * <p>\n"
            + "\t * Converts an {@link boofcv.struct.image."
            + imageIn.getSingleBandName()
            + "} into a {@link boofcv.struct.image."
            + imageOut.getSingleBandName()
            + "}.\n"
            + "\t * </p>\n"
            + "\t *\n"
            + "\t * @param input Input image which is being converted. Not modified.\n"
            + "\t * @param output (Optional) The output image.  If null a new image is created. Modified.\n"
            + "\t * @return Converted image.\n"
            + "\t */\n"
            + "\tpublic static "
            + imageOut.getSingleBandName()
            + " convert("
            + imageIn.getSingleBandName()
            + " input, "
            + imageOut.getSingleBandName()
            + " output) {\n"
            + "\t\tif (output == null) {\n"
            + "\t\t\toutput = new "
            + imageOut.getSingleBandName()
            + "(input.width, input.height);\n"
            + "\t\t} else {\n"
            + "\t\t\tInputSanityCheck.checkSameShape(input, output);\n"
            + "\t\t}\n"
            + "\n"
            + "\t\tImplConvertImage.convert(input, output);\n"
            + "\n"
            + "\t\treturn output;\n"
            + "\t}\n\n");
  }
  private void printVerticalInverse() {
    out.print(
        "\t/**\n"
            + "\t * Performs a single level inverse wavelet transform along the vertical axis.\n"
            + "\t *\n"
            + "\t * @param inverseCoef Description of wavelet coefficients.\n"
            + "\t * @param input Transformed image. Not modified.\n"
            + "\t * @param output Reconstruction of original image. Modified\n"
            + "\t */\n"
            + "\tpublic static void verticalInverse( BorderIndex1D border , WlBorderCoef<WlCoef_"
            + genName
            + "> inverseCoef , "
            + imageIn.getSingleBandName()
            + " input , "
            + imageIn.getSingleBandName()
            + " output ) {\n"
            + "\n"
            + "\t\tUtilWavelet.checkShape(output,input);\n"
            + "\n"
            + "\t\t"
            + sumType
            + " []trends = new "
            + sumType
            + "[ output.height ];\n"
            + "\t\t"
            + sumType
            + " []details = new "
            + sumType
            + "[ output.height ];\n"
            + "\n"
            + "\t\tboolean isLarger = input.height > output.height;\n"
            + "\t\tint paddedHeight = output.height + output.height%2;\n"
            + "\n"
            + "\t\tfinal int lowerBorder = inverseCoef.getLowerLength()*2;\n"
            + "\t\tfinal int upperBorder = output.height - inverseCoef.getUpperLength()*2;\n"
            + "\n"
            + "\t\tborder.setLength(output.height+output.height%2);\n"
            + "\n");

    if (imageIn.isInteger()) {
      out.print("\t\tWlCoef_" + genName + " coefficients = inverseCoef.getInnerCoefficients();\n");
      out.print(
          "\t\tfinal int e = coefficients.denominatorScaling*2;\n"
              + "\t\tfinal int f = coefficients.denominatorWavelet*2;\n"
              + "\t\tfinal int ef = e*f;\n"
              + "\t\tfinal int ef2 = ef/2;\n");
    } else {
      out.print("\t\tWlCoef_" + genName + " coefficients;\n");
    }
    out.print("\n");
    out.print(
        "\t\tfor( int x = 0; x < output.width; x++) {\n"
            + "\n"
            + "\t\t\tfor( int i = 0; i < details.length; i++ ) {\n"
            + "\t\t\t\tdetails[i] = 0;\n"
            + "\t\t\t\ttrends[i] = 0;\n"
            + "\t\t\t}\n"
            + "\n"
            + "\t\t\tfor( int y = 0; y < output.height; y += 2 ) {\n"
            + "\t\t\t\t"
            + sumType
            + " a = input.get(x,y/2);\n"
            + "\t\t\t\t"
            + sumType
            + " d = input.get(x,y/2+input.height/2);\n"
            + "\n"
            + "\t\t\t\tif( y < lowerBorder ) {\n"
            + "\t\t\t\t\tcoefficients = inverseCoef.getBorderCoefficients(y);\n"
            + "\t\t\t\t} else if( y >= upperBorder ) {\n"
            + "\t\t\t\t\tcoefficients = inverseCoef.getBorderCoefficients(y-paddedHeight);\n"
            + "\t\t\t\t} else {\n"
            + "\t\t\t\t\tcoefficients = inverseCoef.getInnerCoefficients();\n"
            + "\t\t\t\t}\n"
            + "\n"
            + "\t\t\t\tfinal int offsetA = coefficients.offsetScaling;\n"
            + "\t\t\t\tfinal int offsetB = coefficients.offsetWavelet;\n"
            + "\t\t\t\tfinal "
            + sumType
            + "[] alpha = coefficients.scaling;\n"
            + "\t\t\t\tfinal "
            + sumType
            + "[] beta = coefficients.wavelet;\n"
            + "\n"
            + "\t\t\t\t// add the 'average' signal\n"
            + "\t\t\t\tfor( int i = 0; i < alpha.length; i++ ) {\n"
            + "\t\t\t\t\t// if an odd image don't update the outer edge\n"
            + "\t\t\t\t\tint yy = border.getIndex(y+offsetA+i);\n"
            + "\t\t\t\t\tif( isLarger && yy >= output.height )\n"
            + "\t\t\t\t\t\tcontinue;\n"
            + "\t\t\t\t\ttrends[yy] += a*alpha[i];\n"
            + "\t\t\t\t}\n"
            + "\n"
            + "\t\t\t\t// add the detail signal\n"
            + "\t\t\t\tfor( int i = 0; i < beta.length; i++ ) {\n"
            + "\t\t\t\t\tint yy = border.getIndex(y+offsetB+i);\n"
            + "\t\t\t\t\tif( isLarger && yy >= output.height )\n"
            + "\t\t\t\t\t\tcontinue;\n"
            + "\t\t\t\t\tdetails[yy] += d*beta[i];\n"
            + "\t\t\t\t}\n"
            + "\t\t\t}\n"
            + "\n"
            + "\t\t\tfor( int y = 0; y < output.height; y++ ) {\n");
    if (imageIn.isInteger()) {
      out.print("\t\t\t\toutput.set(x,y, UtilWavelet.round(trends[y]*f + details[y]*e,ef2,ef));\n");
    } else {
      out.print("\t\t\t\toutput.set(x,y, trends[y] + details[y]);\n");
    }
    out.print("\t\t\t}\n" + "\t\t}\n" + "\t}\n\n");
  }
 private void printVertical() {
   out.print(
       "\t/**\n"
           + "\t * Performs a single level wavelet transform along the vertical axis.\n"
           + "\t *\n"
           + "\t * @param coefficients Description of wavelet coefficients.\n"
           + "\t * @param input Input image which is being transform. Not modified.\n"
           + "\t * @param output where the output is written to. Modified\n"
           + "\t */\n"
           + "\tpublic static void vertical( BorderIndex1D border , WlCoef_"
           + genName
           + " coefficients ,\n"
           + "\t\t\t\t\t\t\t\t "
           + imageIn.getSingleBandName()
           + " input , "
           + imageIn.getSingleBandName()
           + " output ) {\n"
           + "\n"
           + "\t\tUtilWavelet.checkShape(input,output);\n"
           + "\n"
           + "\t\tfinal int offsetA = coefficients.offsetScaling;\n"
           + "\t\tfinal int offsetB = coefficients.offsetWavelet;\n"
           + "\t\tfinal "
           + sumType
           + "[] alpha = coefficients.scaling;\n"
           + "\t\tfinal "
           + sumType
           + "[] beta = coefficients.wavelet;\n"
           + "\n"
           + "\t\tborder.setLength(input.height+input.height%2);\n"
           + "\n"
           + "\t\tboolean isLarger = output.height > input.height;\n"
           + "\n"
           + "\t\tfor( int x = 0; x < input.width; x++) {\n"
           + "\t\t\tfor( int y = 0; y < input.height; y += 2 ) {\n"
           + "\t\t\t\t"
           + sumType
           + " scale = 0;\n"
           + "\t\t\t\t"
           + sumType
           + " wavelet = 0;\n"
           + "\n"
           + "\t\t\t\tfor( int i = 0; i < alpha.length; i++ ) {\n"
           + "\t\t\t\t\tint yy = border.getIndex(y+i+offsetA);\n"
           + "\t\t\t\t\tif( isLarger && yy >= input.height )\n"
           + "\t\t\t\t\t\tcontinue;\n"
           + "\t\t\t\t\tscale += input.get(x,yy)*alpha[i];\n"
           + "\t\t\t\t}\n"
           + "\t\t\t\tfor( int i = 0; i < beta.length; i++ ) {\n"
           + "\t\t\t\t\tint yy = border.getIndex(y+i+offsetB);\n"
           + "\t\t\t\t\tif( isLarger && yy >= input.height )\n"
           + "\t\t\t\t\t\tcontinue;\n"
           + "\t\t\t\t\twavelet += input.get(x,yy)*beta[i];\n"
           + "\t\t\t\t}\n"
           + "\n"
           + "\t\t\t\tint outY = y/2;\n"
           + "\n");
   if (imageIn.isInteger()) {
     out.print(
         "\t\t\t\tscale = 2*scale/coefficients.denominatorScaling;\n"
             + "\t\t\t\twavelet = 2*wavelet/coefficients.denominatorWavelet;\n"
             + "\n");
   }
   out.print(
       "\t\t\t\toutput.set(x , outY,scale);\n"
           + "\t\t\t\toutput.set(x , output.height/2 + outY , wavelet );\n"
           + "\t\t\t}\n"
           + "\t\t}\n"
           + "\t}\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");
  }