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 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 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"); }