com.github.ojil.algorithm.RgbMinDiff Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ojil-core Show documentation
Show all versions of ojil-core Show documentation
Open Java Imaging Library.
/*
* 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;
/**
* Compute the Gray8Image that is the minimum absolute difference in red, green,
* or blue between the RgbImage specified in the constructor and the RgbImage
* supplied to the pipeline stage. This is intended to be used as part of a
* pipeline for separating out a fixed background from the new input. Since
* the background can vary due to lighting conditions we find the maximum
* difference in any color channel and output that, making it easier to find
* objects that may match the background in one or two channels.
* @author webb
*/
public class RgbMinDiff extends PipelineStage {
private RgbImage rgbBack;
/**
* Set background image.
* @param rgbBack background RgbImage.
*/
public RgbMinDiff(RgbImage rgbBack) {
this.rgbBack = rgbBack;
}
/**
* Process a foreground RgbImage and produce a Gray8Image in which each
* pixel is the maximum of the differences between the input image and
* the background image in the three color channels.
* @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.IMAGE_NOT_RGBIMAGE,
imInput.toString(),
null,
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);
}
Integer[] wInput = ((RgbImage)imInput).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 - 2024 Weber Informatics LLC | Privacy Policy