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 printPreamble() {
   out.print(CodeGeneratorUtil.copyright);
   out.print(
       "package boofcv.alg.feature.describe.impl;\n"
           + "\n"
           + "import boofcv.alg.InputSanityCheck;\n"
           + "import boofcv.alg.feature.describe.OrientationHistogram;\n"
           + "import boofcv.struct.image."
           + imageType.getImageName()
           + ";\n"
           + "\n"
           + "\n"
           + "/**\n"
           + " * <p>\n"
           + " * Implementation of {@link OrientationHistogram} for a specific image type.\n"
           + " * </p>\n"
           + " *\n"
           + " * <p>\n"
           + " * WARNING: Do not modify.  Automatically generated by {@link GenerateImplOrientationHistogram}.\n"
           + " * </p>\n"
           + " *\n"
           + " * @author Peter Abeles\n"
           + " */\n"
           + "public class "
           + className
           + " extends OrientationHistogram<"
           + imageType.getImageName()
           + "> {\n"
           + "\n"
           + "\tpublic "
           + className
           + "(int numAngles , boolean isWeighted ) {\n"
           + "\t\tsuper(numAngles,isWeighted);\n"
           + "\t}\n\n");
 }
  private void printUnweighted() {
    String type = imageType.getDataType();
    String bitWise = imageType.getBitWise();

    out.print(
        "\t@Override\n"
            + "\tprotected void computeUnweightedScore() {\n"
            + "\t\t// compute the score for each angle in the histogram\n"
            + "\t\tfor( int y = rect.y0; y < rect.y1; y++ ) {\n"
            + "\t\t\tint indexX = derivX.startIndex + derivX.stride*y + rect.x0;\n"
            + "\t\t\tint indexY = derivY.startIndex + derivY.stride*y + rect.x0;\n"
            + "\n"
            + "\t\t\tfor( int x = rect.x0; x < rect.x1; x++ , indexX++ , indexY++ ) {\n"
            + "\t\t\t\t"
            + type
            + " dx = derivX.data[indexX]"
            + bitWise
            + ";\n"
            + "\t\t\t\t"
            + type
            + " dy = derivY.data[indexY]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\t\t\tdouble angle = Math.atan2(dy,dx);\n"
            + "\t\t\t\t// compute which discretized angle it is\n"
            + "\t\t\t\tint discreteAngle = (int)((angle + angleRound)/angleDiv) % numAngles;\n"
            + "\t\t\t\t// sum up the \"score\" for this angle\n"
            + "\t\t\t\tsumDerivX[discreteAngle] += dx;\n"
            + "\t\t\t\tsumDerivY[discreteAngle] += dy;\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t}\n\n");
  }
Ejemplo n.º 4
0
  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 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 printVarious() {
   out.print(
       "\t@Override\n"
           + "\tpublic Class<"
           + imageType.getImageName()
           + "> getImageType() {\n"
           + "\t\treturn "
           + imageType.getImageName()
           + ".class;\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();
  }
Ejemplo n.º 9
0
  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 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 printClass(AutoTypeImage imageType) throws FileNotFoundException {
    this.imageType = imageType;
    className = "ImplOrientationHistogram_" + imageType.getAbbreviatedType();
    out = new PrintStream(new FileOutputStream(className + ".java"));
    printPreamble();
    printFunctions();

    out.print("}\n");
  }
Ejemplo n.º 12
0
  @Override
  public void generate() throws FileNotFoundException {
    printPreamble();

    for (AutoTypeImage in : AutoTypeImage.getSpecificTypes()) {
      for (AutoTypeImage out : AutoTypeImage.getSpecificTypes()) {
        if (in == out) continue;

        printConvertSingle(in, out);
        printConvertInterleaved(in, out);
      }
      printMultiAverage(in);
      printMultiToInterleaved(in);
      printInterleaveAverage(in);
      printInterleaveToMulti(in);
    }

    out.print("\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 printPreamble() {
   out.print(CodeGeneratorUtil.copyright);
   out.print("package boofcv.alg.interpolate.impl;\n");
   out.println();
   out.print(
       "import boofcv.alg.interpolate.InterpolateRectangle;\n"
           + "import boofcv.struct.image."
           + image.getImageName()
           + ";\n");
   if (image.getImageName().compareTo("ImageFloat32") != 0)
     out.println("import boofcv.struct.image.ImageFloat32;");
   out.println();
   out.println();
   out.print(
       "/**\n"
           + " * <p>\n"
           + " * Performs bilinear interpolation to extract values between pixels in an image.\n"
           + " * Image borders are detected and handled appropriately.\n"
           + " * </p>\n"
           + " *\n"
           + " * <p>\n"
           + " * NOTE: This code was automatically generated using {@link GenerateBilinearRectangle}.\n"
           + " * </p>\n"
           + " *\n"
           + " * @author Peter Abeles\n"
           + " */\n"
           + "public class "
           + className
           + " implements InterpolateRectangle<"
           + image.getImageName()
           + "> {\n"
           + "\n"
           + "\tprivate "
           + image.getImageName()
           + " orig;\n"
           + "\n"
           + "\tprivate "
           + image.getDataType()
           + " data[];\n"
           + "\tprivate int stride;\n"
           + "\n"
           + "\tpublic "
           + className
           + "("
           + image.getImageName()
           + " image) {\n"
           + "\t\tsetImage(image);\n"
           + "\t}\n"
           + "\n"
           + "\tpublic "
           + className
           + "() {\n"
           + "\t}\n\n");
 }
Ejemplo n.º 16
0
  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 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");
  }
 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 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");
  }
Ejemplo n.º 21
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 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 createType(AutoTypeImage type) throws FileNotFoundException {
    className = "BilinearRectangle_" + type.name();
    image = type;

    createFile();
  }
  private void printTheRest() {

    String bitWise = image.getBitWise();

    out.print(
        "\t@Override\n"
            + "\tpublic void setImage("
            + image.getImageName()
            + " image) {\n"
            + "\t\tthis.orig = image;\n"
            + "\t\tthis.data = orig.data;\n"
            + "\t\tthis.stride = orig.getStride();\n"
            + "\t}\n"
            + "\n"
            + "\t@Override\n"
            + "\tpublic "
            + image.getImageName()
            + " getImage() {\n"
            + "\t\treturn orig;\n"
            + "\t}\n"
            + "\n"
            + "\t@Override\n"
            + "\tpublic void region(float tl_x, float tl_y, ImageFloat32 output ) {\n"
            + "\t\tint xt = (int) tl_x;\n"
            + "\t\tint yt = (int) tl_y;\n"
            + "\t\tfloat ax = tl_x - xt;\n"
            + "\t\tfloat ay = tl_y - yt;\n"
            + "\n"
            + "\t\tfloat bx = 1.0f - ax;\n"
            + "\t\tfloat by = 1.0f - ay;\n"
            + "\n"
            + "\t\tfloat a0 = bx * by;\n"
            + "\t\tfloat a1 = ax * by;\n"
            + "\t\tfloat a2 = ax * ay;\n"
            + "\t\tfloat a3 = bx * ay;\n"
            + "\n"
            + "\t\tint regWidth = output.width;\n"
            + "\t\tint regHeight = output.height;\n"
            + "\t\tfinal float results[] = output.data;\n"
            + "\t\tboolean borderRight = false;\n"
            + "\t\tboolean borderBottom = false;\n"
            + "\n"
            + "\t\t// make sure it is in bounds or if its right on the image border\n"
            + "\t\tif (xt + regWidth >= orig.width || yt + regHeight >= orig.height) {\n"
            + "\t\t\tif( (xt + regWidth > orig.width || yt + regHeight > orig.height) )\n"
            + "\t\t\t\tthrow new IllegalArgumentException(\"requested region is out of bounds\");\n"
            + "\t\t\tif( xt+regWidth == orig.width ) {\n"
            + "\t\t\t\tregWidth--;\n"
            + "\t\t\t\tborderRight = true;\n"
            + "\t\t\t}\n"
            + "\t\t\tif( yt+regHeight == orig.height ) {\n"
            + "\t\t\t\tregHeight--;\n"
            + "\t\t\t\tborderBottom = true;\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\n"
            + "\t\t// perform the interpolation while reducing the number of times the image needs to be accessed\n"
            + "\t\tfor (int i = 0; i < regHeight; i++) {\n"
            + "\t\t\tint index = orig.startIndex + (yt + i) * stride + xt;\n"
            + "\t\t\tint indexResults = output.startIndex + i*output.stride;\n"
            + "\n"
            + "\t\t\tfloat XY = data[index]"
            + bitWise
            + ";\n"
            + "\t\t\tfloat Xy = data[index + stride]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\t\tint indexEnd = index + regWidth;\n"
            + "\t\t\t// for( int j = 0; j < regWidth; j++, index++ ) {\n"
            + "\t\t\tfor (; index < indexEnd; index++) {\n"
            + "\t\t\t\tfloat xY = data[index + 1]"
            + bitWise
            + ";\n"
            + "\t\t\t\tfloat xy = data[index + stride + 1]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\t\t\tfloat val = a0 * XY + a1 * xY + a2 * xy + a3 * Xy;\n"
            + "\n"
            + "\t\t\t\tresults[indexResults++] = val;\n"
            + "\t\t\t\tXY = xY;\n"
            + "\t\t\t\tXy = xy;\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t\t\n"
            + "\t\t// if touching the image border handle the special case\n"
            + "\t\tif( borderBottom || borderRight )\n"
            + "\t\t\thandleBorder(output, xt, yt, ax, ay, bx, by, regWidth, regHeight, results, borderRight, borderBottom);\n"
            + "\t}\n"
            + "\n"
            + "\tprivate void handleBorder( ImageFloat32 output,\n"
            + "\t\t\t\t\t\t\t  int xt, int yt,\n"
            + "\t\t\t\t\t\t\t  float ax, float ay, float bx, float by,\n"
            + "\t\t\t\t\t\t\t  int regWidth, int regHeight, float[] results,\n"
            + "\t\t\t\t\t\t\t  boolean borderRight, boolean borderBottom) {\n"
            + "\n"
            + "\t\tif( borderRight ) {\n"
            + "\t\t\tfor( int y = 0; y < regHeight; y++ ) {\n"
            + "\t\t\t\tint index = orig.startIndex + (yt + y) * stride + xt + regWidth;\n"
            + "\t\t\t\tint indexResults = output.startIndex + y*output.stride + regWidth;\n"
            + "\n"
            + "\t\t\t\tfloat XY = data[index]"
            + bitWise
            + ";\n"
            + "\t\t\t\tfloat Xy = data[index + stride]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\t\t\tresults[indexResults] = by*XY + ay*Xy;\n"
            + "\t\t\t}\n"
            + "\n"
            + "\t\t\tif( borderBottom ) {\n"
            + "\t\t\t\toutput.set(regWidth,regHeight, orig.get(xt+ regWidth,yt+regHeight));\n"
            + "\t\t\t} else {\n"
            + "\t\t\t\tfloat XY = orig.get(xt+ regWidth,yt+regHeight-1);\n"
            + "\t\t\t\tfloat Xy = orig.get(xt+ regWidth,yt+regHeight);\n"
            + "\n"
            + "\t\t\t\toutput.set(regWidth,regHeight-1, by*XY + ay*Xy);\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t\tif( borderBottom ) {\n"
            + "\t\t\tfor( int x = 0; x < regWidth; x++ ) {\n"
            + "\t\t\t\tint index = orig.startIndex + (yt + regHeight) * stride + xt + x;\n"
            + "\t\t\t\tint indexResults = output.startIndex + regHeight *output.stride + x;\n"
            + "\n"
            + "\t\t\t\tfloat XY = data[index]"
            + bitWise
            + ";\n"
            + "\t\t\t\tfloat Xy = data[index + 1]"
            + bitWise
            + ";\n"
            + "\n"
            + "\t\t\t\tresults[indexResults] = bx*XY + ax*Xy;\n"
            + "\t\t\t}\n"
            + "\n"
            + "\t\t\tif( !borderRight ) {\n"
            + "\t\t\t\tfloat XY = orig.get(xt+regWidth-1,yt+ regHeight);\n"
            + "\t\t\t\tfloat Xy = orig.get(xt+regWidth, regHeight);\n"
            + "\n"
            + "\t\t\t\toutput.set(regWidth-1, regHeight, by*XY + ay*Xy);\n"
            + "\t\t\t}\n"
            + "\t\t}\n"
            + "\t}\n");
  }