001/** 002 * Copyright (c) 2011, The University of Southampton and the individual contributors. 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without modification, 006 * are permitted provided that the following conditions are met: 007 * 008 * * Redistributions of source code must retain the above copyright notice, 009 * this list of conditions and the following disclaimer. 010 * 011 * * Redistributions in binary form must reproduce the above copyright notice, 012 * this list of conditions and the following disclaimer in the documentation 013 * and/or other materials provided with the distribution. 014 * 015 * * Neither the name of the University of Southampton nor the names of its 016 * contributors may be used to endorse or promote products derived from this 017 * software without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030package org.openimaj.image.processing.convolution.filterbank; 031 032import org.openimaj.citation.annotation.Reference; 033import org.openimaj.citation.annotation.ReferenceType; 034import org.openimaj.image.processing.convolution.FConvolution; 035 036/** 037 * Base {@link FilterBank} that provides the 16 raw kernels used in Laws texture 038 * classification approach. These are used by the {@link LawsTexture} class to 039 * make 9 filters (by averaging the directional ones). 040 * <p> 041 * This class is provided as a convenience for extensions to Laws technique; in 042 * direct applications of Law's technique, you'll want to use 043 * {@link LawsTexture} instead. 044 * 045 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) 046 * 047 */ 048@Reference( 049 type = ReferenceType.Inproceedings, 050 author = { "Laws, K. I." }, 051 title = "{Rapid Texture Identification}", 052 year = "1980", 053 booktitle = "Proc. SPIE Conf. Image Processing for Missile Guidance", 054 pages = { "376", "", "380" }, 055 customData = { 056 "citeulike-article-id", "2335645", 057 "keywords", "bibtex-import", 058 "posted-at", "2008-02-05 15:32:50", 059 "priority", "2" 060 }) 061public class LawsTextureBase extends FilterBank { 062 private static final float[] L5 = { 1, 4, 6, 4, 1 }; 063 private static final float[] E5 = { -1, -2, 0, 2, 1 }; 064 private static final float[] S5 = { -1, 0, 2, 0, -1 }; 065 private static final float[] R5 = { 1, -4, 6, -4, 1 }; 066 067 protected final static int L5E5 = 0; 068 protected final static int E5L5 = 1; 069 protected final static int L5R5 = 2; 070 protected final static int R5L5 = 3; 071 protected final static int E5S5 = 4; 072 protected final static int S5E5 = 5; 073 protected final static int S5S5 = 6; 074 protected final static int R5R5 = 7; 075 protected final static int L5S5 = 8; 076 protected final static int S5L5 = 9; 077 protected final static int E5E5 = 10; 078 protected final static int E5R5 = 11; 079 protected final static int R5E5 = 12; 080 protected final static int S5R5 = 13; 081 protected final static int R5S5 = 14; 082 083 /** 084 * Default constructor 085 */ 086 public LawsTextureBase() { 087 super(makeFilters()); 088 } 089 090 private static FConvolution[] makeFilters() { 091 final FConvolution[] filters = new FConvolution[15]; 092 093 filters[L5E5] = makeFilter(L5, E5); 094 filters[E5L5] = makeFilter(E5, L5); 095 filters[L5R5] = makeFilter(L5, R5); 096 filters[R5L5] = makeFilter(R5, L5); 097 filters[E5S5] = makeFilter(E5, S5); 098 filters[S5E5] = makeFilter(S5, E5); 099 filters[S5S5] = makeFilter(S5, S5); 100 filters[R5R5] = makeFilter(R5, R5); 101 filters[L5S5] = makeFilter(L5, S5); 102 filters[S5L5] = makeFilter(S5, L5); 103 filters[E5E5] = makeFilter(E5, E5); 104 filters[E5R5] = makeFilter(E5, R5); 105 filters[R5E5] = makeFilter(R5, E5); 106 filters[S5R5] = makeFilter(S5, R5); 107 filters[R5S5] = makeFilter(R5, S5); 108 109 return filters; 110 } 111 112 private static FConvolution makeFilter(float[] l, float[] r) { 113 final float[][] f = new float[l.length][r.length]; 114 115 for (int i = 0; i < l.length; i++) 116 for (int j = 0; j < r.length; j++) 117 f[i][j] = l[i] * r[j]; 118 119 return new FConvolution(f); 120 } 121}