All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.ojil.algorithm.RgbMultiVecThresh Maven / Gradle / Ivy

There is a newer version: 0.0.11
Show newest version
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.github.ojil.algorithm;

import com.github.ojil.core.Error;
import com.github.ojil.core.Gray8Image;
import com.github.ojil.core.Image;
import com.github.ojil.core.PipelineStage;
import com.github.ojil.core.RgbImage;
import com.github.ojil.core.RgbVal;

/**
 * Thresholds an RgbImage against a number of input colors.
 * @author webb
 */
public class RgbMultiVecThresh extends PipelineStage {
    /**
     * Simplify lookup of color values in array.
     */
    private final int R = 0;
    private final int G = 1;
    private final int B = 2;
    
    private Integer[][] nRgbVals;
    /**
     * Input color values, unpacked.
     */
    private Integer[][] nRgbVecs;
    /**
     * Input threshold value.
     */
    private int nThreshold;
    /**
     * Thresholds an RgbImage against a number of input colors.
     * Each color is described using a target value (rgbVal) and
     * a vector (rgbVec). The idea is that a pixel matches a target
     * value if its difference from the target value, projected
     * on the vector, is less than the threshold. One threshold
     * is used for all colors and the minimum absolute value of
     * all color distances is compared with the threshold. Since
     * the vectors can be unnormalized the relative importance of
     * each target color value can be adjusted. 
* One way to use this is to set the target color to the mean * Rgb value of a region and the target vector to the standard * deviation. The threshold would then be the standard deviation * squared. Pixels further away than one standard deviation would * be rejected. * @param rgbVals packed arry of target Rgb values * @param rgbVecs packed array of target Rgb vectors * @param nThreshold threshold value * @throws Error if the input Rgb vectors are not the same * length. */ public RgbMultiVecThresh(Integer[] rgbVals, Integer[] rgbVecs, int nThreshold) throws Error { if (rgbVals.length != rgbVecs.length) { throw new Error( Error.PACKAGE.ALGORITHM, ErrorCodes.PARAMETER_SIZES_DIFFER, rgbVals.toString(), rgbVals.toString(), null); } this.nRgbVecs = new Integer[rgbVecs.length][3]; this.nRgbVals = new Integer[rgbVecs.length][3]; for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy