FeatureComparator.java

package ac.essex.ooechs.imaging.commons.test; 
 
import ac.essex.ooechs.imaging.commons.PixelLoader; 
import ac.essex.ooechs.imaging.commons.StatisticsSolver; 
import ac.essex.ooechs.imaging.commons.Resizer; 
import ac.essex.ooechs.imaging.commons.fast.FastStatistics; 
 
import java.io.File; 
 
/** 
 * 
 * Compares the scaling issues with three different image processing 
 * techniques: 
 * Difference of sums 
 * Difference of means 
 * Differents of Std Deviations 
 * 
 * <p/> 
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 
 * of the License, or (at your option) any later version, 
 * provided that any use properly credits the author. 
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 * GNU General Public License for more details at http://www.gnu.org 
 * </p> 
 * 
 * @author Olly Oechsle, University of Essex, Date: 26-Sep-2006 
 * @version 1.0 
 */ 
public class FeatureComparator { 
 
    public static void main(String[] args) throws Exception { 
        new FeatureComparator(new PixelLoader("/home/ooechs/Desktop/test.jpg")); 
    } 
 
 
    public FeatureComparator(PixelLoader image) throws Exception { 
 
        System.out.println("Pixels, Sum, Mean, Std Dev"); 
 
 
       for (int i = 150; i > 20; i-= 10) { 
 
            File temp = new File("/tmp/tmp" + i + ".bmp"); 
 
            Resizer.resize(image.getFile(), temp, i); 
 
            process(new PixelLoader(temp)); 
 
        } 
 
 
    } 
 
    public void process(PixelLoader image) { 
 
        int pixelCount = image.getWidth() * image.getHeight(); 
 
        // cut in half 
 
        FastStatistics left = new FastStatistics(); 
        FastStatistics right = new FastStatistics(); 
 
        for (int y = 0; y < image.getHeight(); y++) { 
            int halfWidth = image.getWidth() / 2; 
            for (int x = 0; x < halfWidth; x++) { 
                left.addData(image.getGreyValue(x, y)); 
            } 
            for (int x = halfWidth; x < image.getWidth(); x++) { 
                right.addData(image.getGreyValue(x, y)); 
            } 
        } 
 
        double sumDiff = left.getTotal() - right.getTotal(); 
        double meanDiff = left.getMean() - right.getMean(); 
        double stdDeviationDiff = left.getStandardDeviation() - right.getStandardDeviation(); 
 
        System.out.print(pixelCount + ", "); 
        System.out.print(sumDiff + ", "); 
        System.out.print(meanDiff + ", "); 
        System.out.print(stdDeviationDiff + ", "); 
 
        System.out.println(); 
 
    } 
 
}