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

com.github.ojil.algorithm.RgbMaskedMaxDiff 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.
 * 
 * Copyright 2008 by Jon pA. Webb
 *     This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    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 pA PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the Lesser GNU General Public License
 *    along with this program.  If not, see .
 */

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.RgbMaskedImage;
import com.github.ojil.core.RgbVal;

/**
 * Compute the Gray8Image that is the max of absolute differences between
 * the background RgbMaskedImage specified in the constructor and the 
 * input RgbImage, in the unmasked areas only. The output in the unmasked areas
 * is Byte.MIN_VALUE.
 * @author webb
 */
public class RgbMaskedMaxDiff extends PipelineStage {
    private RgbMaskedImage rgbBack;

    /**
     * Set background image.
     * @param rgbBack background RgbImage.
     */
    public RgbMaskedMaxDiff(RgbMaskedImage rgbBack) {
        this.rgbBack = rgbBack;
    }
    
    /**
     * Process a foreground RgbMaskedImage and produce a Gray8Image in which each
     * pixel is the sum of absolute differences between the foreground and
     * background, in the masked areas. Outside the masked areas the output
     * is Byte.MIN_VALUE.
     * @param imInput input RgbImage
     * @throws com.github.ojil.core.Error if imInput is not an RgbImage or is not the same
     * size as the background image set in the constructor.
     */
    public void push(Image imInput) throws Error {
        {
        if (!(imInput instanceof RgbImage)) 
            throw new Error(
                			Error.PACKAGE.ALGORITHM,
                			ErrorCodes.OBJECT_NOT_EXPECTED_TYPE,
                			imInput.toString(),
                			"RgbMaskedImage",
                			null);
        }
        if (imInput.getWidth() != this.rgbBack.getWidth() ||
        	imInput.getHeight() != this.rgbBack.getHeight()) {
        	throw new Error(
        				Error.PACKAGE.ALGORITHM,
        				ErrorCodes.IMAGE_SIZES_DIFFER,
        				imInput.toString(),
        				this.rgbBack.toString(),
        				null);
        
        }
        RgbImage rgbInput = (RgbImage)imInput;
        Integer[] wInput = rgbInput.getData();
        Integer[] wBack = this.rgbBack.getData();
        Gray8Image grayOut = new Gray8Image(
                this.rgbBack.getWidth(), 
                this.rgbBack.getHeight());        
        Byte[] bGray = grayOut.getData();
        for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy