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

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

There is a newer version: 0.0.11
Show newest version
/*
 * Gray8SumGray32.java
 *   "Sum Gray8[Sub]Image to Gray32[Sub]Image".
 *   Forms integral image by summing pixels in a
 *   Gray8[Sub]Image to form a Gray32[Sub]Image.
 * The computation is O(i,j) = Sum for k<=i,l<=j of I(k,l)
 * Note output type is 32 bit because otherwise we'd get
 * truncation. With 32-bit output we can go up to 
 * 65,536 = 256x256 pixels in the input image.
 *
 * Created on July 1, 2007, 3:39 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.github.ojil.algorithm;
import com.github.ojil.core.Error;
import com.github.ojil.core.Gray32Image;
import com.github.ojil.core.Gray32OffsetImage;
import com.github.ojil.core.Gray8Image;
import com.github.ojil.core.Gray8OffsetImage;
import com.github.ojil.core.Image;
import com.github.ojil.core.PipelineStage;

/**
 * Forms integral image by summing pixels in a
 * Gray8[Sub]Image to form a Gray32[Sub]Image.
* The computation is O(i,j) = ∑k ≤ i, l ≤ j I(k,l)
* Note output type is 32 bit because otherwise we'd get * truncation. With 32-bit output we can go up to * 212× 212 = 4096 × 4096 pixels in the input image. * * @author webb */ public class Gray8SumGray32 extends PipelineStage { /** * Creates a new instance of Gray8SumGray32 */ public Gray8SumGray32() { } /** * Form the cumulative sum

* Output(i,j) = ∑k ≤ i, l ≤ j Input(k,l) * @param image input image. * @throws com.github.ojil.core.Error if the input is not a Gray8Image. */ public void push(Image image) throws com.github.ojil.core.Error { if (!(image instanceof Gray8Image)) { throw new Error( Error.PACKAGE.ALGORITHM, ErrorCodes.IMAGE_NOT_GRAY8IMAGE, image.toString(), null, null); } Gray32Image imageResult; if (image instanceof Gray8OffsetImage) { Gray8OffsetImage sub = (Gray8OffsetImage) image; imageResult = new Gray32OffsetImage(sub.getWidth(), sub.getHeight(), sub.getXOffset(), sub.getYOffset()); } else { // must be a Gray8Image imageResult = new Gray32Image(image.getWidth(), image.getHeight()); } Byte[] inData = ((Gray8Image) image).getData(); // pointer to output data area, whether Gray32Image or Gray32OffsetImage Integer[] outData = imageResult.getData(); // initialize first row int prevPixel = 0; for (int i=0; i





© 2015 - 2025 Weber Informatics LLC | Privacy Policy