001package org.openimaj.picslurper.client;
002
003import java.io.File;
004import java.io.IOException;
005import java.util.ArrayList;
006import java.util.List;
007
008import org.openimaj.feature.FeatureVector;
009import org.openimaj.feature.FeatureVectorProvider;
010import org.openimaj.image.ImageUtilities;
011import org.openimaj.image.MBFImage;
012import org.openimaj.image.pixel.statistics.BlockHistogramModel;
013import org.openimaj.image.processing.resize.ResizeProcessor;
014
015public class LocalColourFeatureMode implements TrendDetectorFeatureExtractor {
016
017
018        private int blocks_x = 4;
019        private int blocks_y = 4;
020        private int[] ibins = new int[]{4,4,4};
021        private BlockHistogramModel hm;
022        public LocalColourFeatureMode() {
023                hm = new BlockHistogramModel(blocks_x , blocks_y , ibins );
024        }
025        @Override
026        public List<? extends FeatureVectorProvider<? extends FeatureVector>> extractFeatures(File imageFile) throws IOException {
027                MBFImage image = ImageUtilities.readMBF(imageFile);
028                if(image.getWidth() < 50){
029                        throw new IOException("image too small,skipping");
030                }
031                image.processInplace(new ResizeProcessor(150));
032                hm.estimateModel(image);
033
034                FeatureVectorProvider<FeatureVector> fvp = new FeatureVectorProvider<FeatureVector>() {
035
036                        @Override
037                        public FeatureVector getFeatureVector() {
038                                return hm.toSingleHistogram();
039                        }
040                };
041
042                List<FeatureVectorProvider<FeatureVector>> ret = new ArrayList<FeatureVectorProvider<FeatureVector>>();
043                ret.add(fvp);
044                return ret ;
045        }
046        @Override
047        public boolean logScale() {
048                return false;
049        }
050        @Override
051        public int nDimensions() {
052                int mult = blocks_x * blocks_y;
053                for (int bindim: ibins) {
054                        mult *= bindim;
055                }
056                return mult;
057        }
058
059}