Java Code Examples for ij.process.ImageProcessor#setf()

The following examples show how to use ij.process.ImageProcessor#setf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NeighborLabelsPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new image containing only the specified labels.
 * 
 * @param image
 *            a planar image of labels
 * @param labels
 *            the list of values to keep
 * @return a new binary image containing 255 only for pixels with values
 *         belonging to the list of labels.
 */
private static final ImageProcessor selectedLabelsToMask(ImageProcessor image, int[] labels) 
{
    int sizeX = image.getWidth();
    int sizeY = image.getHeight();
    
    ImageProcessor result = image.createProcessor(sizeX,  sizeY);
    
    TreeSet<Integer> labelSet = new TreeSet<Integer>();
    for (int i = 0; i < labels.length; i++) 
    {
        labelSet.add(labels[i]);
    }
    
    for (int y = 0; y < sizeY; y++) 
    {
        for (int x = 0; x < sizeX; x++)
        {
            int value = (int) image.getf(x, y); 
            if (labelSet.contains(value)) 
                result.setf(x, y, 255);
        }
    }
    
    return result;
}
 
Example 2
Source File: GrayscaleAttributeFilteringPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void resetPreview()
{
	ImageProcessor image = this.imagePlus.getProcessor();
	if (image instanceof FloatProcessor)
	{
		for (int i = 0; i < image.getPixelCount(); i++)
			image.setf(i, this.baseImage.getf(i));
	}
	else
	{
		for (int i = 0; i < image.getPixelCount(); i++)
			image.set(i, this.baseImage.get(i));
	}
	image.resetMinAndMax();
	imagePlus.updateAndDraw();
}
 
Example 3
Source File: Distortion_Correction.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
ImageProcessor getGradientSobel(final ImageProcessor ip){
	final ImageProcessor ipGrad = ip.duplicate();
	ipGrad.max(0.0);

	for (int i=1; i<ipGrad.getWidth()-1; i++){
		for (int j=1; j<ipGrad.getHeight()-1; j++){
			if(ip.get(i-1,j-1)==0 || ip.get(i-1,j)==0 || ip.get(i-1,j+1)==0 ||
					ip.get(i,j-1)==0 || ip.get(i,j)==0 || ip.get(i,j+1)==0 ||
					ip.get(i+1,j-1)==0 || ip.get(i+1,j)==0 || ip.get(i+1,j+1)==0 )
				continue;

			final double gradX = (double) -ip.get(i-1, j-1) - 2* ip.get(i-1,j) - ip.get(i-1,j+1)
			+ip.get(i+1, j-1) + 2* ip.get(i+1,j) + ip.get(i+1,j+1);

			final double gradY = (double) -ip.get(i-1, j-1) - 2* ip.get(i,j-1) - ip.get(i+1,j-1)
			+ip.get(i-1, j+1) + 2* ip.get(i,j+1) + ip.get(i+1,j+1);

			final double mag = Math.sqrt(gradX*gradX + gradY*gradY);
			ipGrad.setf(i,j,(float) mag);
		}
	}
	return ipGrad;
}
 
Example 4
Source File: Reconstruction.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Fills the holes in the input image, by (1) inverting the image, (2) 
 * performing a morphological reconstruction initialized with inverted image
 * boundary and (3) by inverting the result.
 * 
 * @see #killBorders(ImageProcessor)
 * 
 * @param image the image to process
 * @return a new image with holes filled
 */
public final static ImageProcessor fillHoles(ImageProcessor image) 
{
	// Image size
	int width = image.getWidth();
	int height = image.getHeight();

	// Initialize marker image with white everywhere except at borders
	ImageProcessor markers = image.duplicate();
	for (int y = 1; y < height-1; y++) 
	{
		for (int x = 1; x < width-1; x++) 
		{
			markers.setf(x, y, Float.MAX_VALUE);
		}
	}
	
	// Reconstruct image from borders to find touching structures
	return reconstructByErosion(markers, image);
}
 
Example 5
Source File: LabelImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new image containing only the specified labels.
 * 
 * @param image
 *            a planar label image
 * @param labels
 *            the list of values to keep
 * @return a new label image containing only the specified labels
 */
public static final ImageProcessor keepLabels(ImageProcessor image, int[] labels)
{
	int sizeX = image.getWidth();
	int sizeY = image.getHeight();
	
	ImageProcessor result = image.createProcessor(sizeX,  sizeY);
	
	TreeSet<Integer> labelSet = new TreeSet<Integer>();
	for (int i = 0; i < labels.length; i++) 
	{
		labelSet.add(labels[i]);
	}
	
	for (int y = 0; y < sizeY; y++) 
	{
		for (int x = 0; x < sizeX; x++)
		{
			int value = (int) image.getf(x, y); 
			if (value == 0)
				continue;
			if (labelSet.contains(value)) 
				result.setf(x, y, value);
		}
	}
	
	return result;
}
 
Example 6
Source File: Turn.java    From 3Dscript with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static ImagePlus toZY(ImagePlus image) {
	int w = image.getWidth();
	int h = image.getHeight();
	int d = image.getNSlices();

	ImageProcessor[] slices = new ImageProcessor[d];
	for(int z = 0; z < d; z++) {
		int idx = image.getStackIndex(image.getC(), z + 1, image.getT());
		slices[z] = image.getStack().getProcessor(idx);
	}

	// x = z, y = y, z = -x
	int neww = d, newh = h, newd = w;
	ImageStack stack = new ImageStack(neww, newh);
	for(int z = 0; z < newd; z++) {
		int oldX = newd - z - 1;
		ImageProcessor ip = image.getProcessor().createProcessor(neww, newh);
		for(int y = 0; y < newh; y++) {
			int oldY = y;
			for(int x = 0; x < neww; x++) {
				int oldZ = x;
				ip.setf(x, y, slices[oldZ].getf(oldX, oldY));
			}
		}
		stack.addSlice(ip);
	}
	ImagePlus ret = new ImagePlus(image.getTitle(), stack);
	Calibration cal0 = image.getCalibration();
	Calibration cal1 = cal0.copy();
	cal1.pixelWidth  = cal0.pixelDepth;
	cal1.pixelHeight = cal0.pixelHeight;
	cal1.pixelDepth  = cal0.pixelWidth;
	ret.setCalibration(cal1);
	return ret;
}
 
Example 7
Source File: LargestInscribedCircleTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static final void fillRect(ImageProcessor image, int xmin,
		int xmax, int ymin, int ymax, double value)
{
	for (int y = ymin; y <= ymax; y++)
	{
		for (int x = xmin; x <= xmax; x++) 
		{
			image.setf(x, y, (float) value);
		}
	}
	
}
 
Example 8
Source File: MorphologicalFilterPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void run(ImageProcessor image)
{
	// Create structuring element of the given size
	Strel strel = shape.fromRadius(radius);
	
	// add some listeners
	DefaultAlgoListener.monitor(strel);
	
	// Eventually display the structuring element used for processing 
	if (showStrel) 
	{
		showStrelImage(strel);
	}
	
	// Execute core of the plugin on the original image
	result = op.apply(this.baseImage, strel);
	if (!(result instanceof ColorProcessor))
		result.setLut(this.baseImage.getLut());

   	if (previewing) 
   	{
   		// Fill up the values of original image with values of the result
   		for (int i = 0; i < image.getPixelCount(); i++)
   		{
   			image.setf(i, result.getf(i));
   		}
   		image.resetMinAndMax();
       }
}
 
Example 9
Source File: LinearHorizontalStrel.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void inPlaceDilationFloat(ImageProcessor image) {
	// get image size
	int width = image.getWidth(); 
	int height = image.getHeight();
		
	// shifts between reference position and last position
	int shift = this.size - this.offset - 1;
	
	// create local histogram instance
	LocalExtremumBufferDouble localMax = new LocalExtremumBufferDouble(size,
			LocalExtremum.Type.MAXIMUM);
	
	// Iterate on image rows
	for (int y = 0; y < height; y++) {
		fireProgressChanged(this, y, height);
		
		// init local histogram with background values
		localMax.fill(Float.NEGATIVE_INFINITY);
		
		// add neighbor values
		for (int x = 0; x < Math.min(shift, width); x++) {
			localMax.add(image.getf(x, y));
		}
		
		// iterate along "middle" values
		for (int x = 0; x < width - shift; x++) {
			localMax.add(image.getf(x + shift, y));
			image.setf(x, y, (float) localMax.getMax());
		}
		
		// process pixels at the end of the line
		for (int x = Math.max(0, width - shift); x < width; x++) {
			localMax.add(Float.NEGATIVE_INFINITY);
			image.setf(x, y, (float) localMax.getMax());
		}
	}
	
	// clear the progress bar
	fireProgressChanged(this, height, height);
}
 
Example 10
Source File: OrientedLineStrel.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ImageProcessor dilation(ImageProcessor image)
{
	// Allocate memory for result
	ImageProcessor result = image.duplicate();

	BorderManager bm = new MirroringBorder(image);

	// Iterate on image pixels
	for (int y = 0; y < image.getHeight(); y++)
	{
		for (int x = 0; x < image.getWidth(); x++)
		{
			// reset accumulator
			double res = Double.MIN_VALUE;

			// iterate on neighbors
			for (int i = 0; i < shifts.length; i++) 
			{
				double value = bm.getf(x + shifts[i][0], y + shifts[i][1]);
				res = Math.max(res, value);
			}
			
			// compute result
			result.setf(x, y, (float) res);
		}			
	}
	
	return result;
}
 
Example 11
Source File: DirectionalFilter.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Computes the average value among the neighbors.
 * @param image input image
 * @param strel structuring element
 * @return result image
 */
public static ImageProcessor mean(ImageProcessor image, Strel strel) {
	// Allocate memory for result
	ImageProcessor result = image.duplicate();
	
	BorderManager bm = new MirroringBorder(image);
	
	int[][] shifts = strel.getShifts();
	double accum;
	
	// Iterate on image pixels
	for (int y = 0; y < image.getHeight(); y++) {
		for (int x = 0; x < image.getWidth(); x++) {
			// reset accumulator
			accum = 0;
			
			// iterate on neighbors
			for (int i = 0; i < shifts.length; i++) {
				accum += bm.getf(x + shifts[i][0], y + shifts[i][1]);
			}
			
			// compute result
			double res = accum / shifts.length;
			result.setf(x, y, (float) res);
		}			
	}
	
	return result;
}
 
Example 12
Source File: FloodFill.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Fill in the horizontal line define by y-coordinate and the two x 
 * coordinate extremities (inclusive), with the specified integer value.
 * the value x1 must be lower than or equal the value x2. 
 */
private final static void fillLine(ImageProcessor ip, int y, int x1,
		int x2, float value)
{
	for (int x = x1; x <= x2; x++)
		ip.setf(x, y, value);
}
 
Example 13
Source File: MorphologicalFilterPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void resetPreview()
{
	ImageProcessor image = this.imagePlus.getProcessor();
	if (image instanceof FloatProcessor)
	{
		for (int i = 0; i < image.getPixelCount(); i++)
			image.setf(i, this.baseImage.getf(i));
	}
	else
	{
		for (int i = 0; i < image.getPixelCount(); i++)
			image.set(i, this.baseImage.get(i));
	}
	imagePlus.updateAndDraw();
}
 
Example 14
Source File: ASHRendering.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void drawPoint(double x, double y, double z, double dx, double dz) {
    if (isInBounds(x, y)) {
        int u = (int) ((x - xmin) / resolution);
        int v = (int) ((y - ymin) / resolution);
        int w = 0;
        if (threeDimensions) {
            if (z == zTo) {
                w = zSlices - 1;
            } else {
                w = ((int) ((z - zFrom) / zStep));
            }
        }
        for (int k = -zShifts + 1; k < zShifts; k++) {
            if (w + k < zSlices && w + k >= 0) {
                ImageProcessor img = slices[w + k];
                for (int i = -shifts + 1; i < shifts; i++) {
                    for (int j = -shifts + 1; j < shifts; j++) {
                        if (u + i < imSizeX && u + i >= 0 && v + j < imSizeY && v + j >= 0) {
                            img.setf(u + i, v + j, img.getf(u + i, v + j) + (shifts - Math.abs(i)) * (shifts - Math.abs(j)) * (zShifts - Math.abs(k)));
                        }
                    }
                }
            }
        }
    }
}
 
Example 15
Source File: DirectionalFilter.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Apply directional filter with current settings to the specified image.
 * 
 * @param image
 *            a grayscale image
 * @return the result of directional filter
 */
public ImageProcessor process(ImageProcessor image)
{
	// determine the sign of min/max computation
	int sign = this.type == Type.MAX ? 1 : -1;
	
	// initialize result
	ImageProcessor result = image.duplicate();
	if (this.type == Type.MAX)
	{
		result.setValue(0);
	}
	else
	{
		result.setValue(Integer.MAX_VALUE);
	}
	result.fill();
	
	int sizeX = image.getWidth();
	int sizeY = image.getHeight();
	
	fireStatusChanged(this, "Directional Filter...");

	// Iterate over the set of directions
	for (int i = 0; i < nDirections; i++)
	{
		fireProgressChanged(this, i, nDirections);
		
		// Create the structuring element for current orientation
		double theta = ((double) i) * 180.0 / nDirections;
		Strel strel = this.strelFactory.createStrel(theta);

		// Apply oriented filter
		ImageProcessor oriented = this.operation.apply(image, strel);

		// combine current result with global result
		for (int y = 0; y < sizeY; y++)
		{
			for (int x = 0; x < sizeX; x++)
			{
				float value = oriented.getf(x, y);
				if (value * sign > result.getf(x, y) * sign)
				{
					result.setf(x, y, value);
				}
			}
		}
	}
	
	fireProgressChanged(this, 1, 1);
	
	// return the min or max value computed over all orientations
	return result;
}
 
Example 16
Source File: GeodesicReconstructionScanningTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link ijt.filter.morphology.GeodesicReconstruction#reconstructByErosion()}.
 */
@Test
public void testReconstructByErosion_FloatC4() {
	float BG = -42;
	float FG = 2500;
	float[][] data = new float[][]{
			{BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG},   
			{BG, FG, FG, BG, FG, FG, BG, FG, FG, FG, FG, FG, FG, FG, FG, BG},
			{BG, FG, FG, BG, FG, FG, BG, FG, FG, FG, FG, FG, FG, FG, FG, BG},
			{BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, BG, BG, BG, FG, FG, BG},
			{BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG},
			{BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG},
			{BG, FG, FG, BG, BG, BG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG},
			{BG, FG, FG, FG, FG, FG, FG, FG, FG, BG, FG, FG, BG, FG, FG, BG},
			{BG, FG, FG, FG, FG, FG, FG, FG, FG, BG, FG, FG, BG, FG, FG, BG},
			{BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG},
	};
	int height = data.length;
	int width = data[0].length;
	ImageProcessor mask = new FloatProcessor(width, height);
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			if (data[y][x] == FG)
				mask.setf(x, y, BG);
			else
				mask.setf(x, y, FG);
		}
	}
	
	ImageProcessor marker = new FloatProcessor(width, height);
	marker.setColor(FG);
	marker.fill();
	marker.setf(2, 3, BG);
	
	GeodesicReconstructionScanning algo = new GeodesicReconstructionScanning(
			GeodesicReconstructionType.BY_EROSION, 4);
	ImageProcessor result = algo.applyTo(marker, mask);
	
	assertEquals(16, result.getWidth());
	assertEquals(10, result.getHeight());
	assertEquals(BG, result.getf(2, 8), .01);
	assertEquals(BG, result.getf(8, 8), .01);
	assertEquals(BG, result.getf(8, 5), .01);
	assertEquals(BG, result.getf(14, 8), .01);
	assertEquals(FG, result.getf(15, 9), .01);
	assertEquals(FG, result.getf(0, 0), .01);
	assertEquals(FG, result.getf(5, 3), .01);
	assertEquals(FG, result.getf(11, 5), .01);
}
 
Example 17
Source File: ExpandLabelsPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Expand labels by a given factor
 * @param image  input label image
 * @param ratio  percentage of expansion (values between 0 and 100)
 * @return expanded image
 */
public static final ImageProcessor expandLabels(ImageProcessor image,
		float ratio) 
{
	// size of input image
	int sizeX = image.getWidth();
	int sizeY = image.getHeight();
	
	// size of result image
	int sizeX2 = (int) Math.round(sizeX * (1.0 + ratio / 100.0));
	int sizeY2 = (int) Math.round(sizeY * (1.0 + ratio / 100.0));
	
	// allocate memory for result
	ImageProcessor result = image.createProcessor(sizeX2, sizeY2);

	// compute centroids of labels
	int[] labels = LabelImages.findAllLabels(image);
	double[][] centroids = Centroid.centroids(image, labels);
	
	// compute shift associated to each label
	int nLabels = labels.length;
	int[][] shifts = new int[nLabels][2];
	for (int i = 0; i < nLabels; i++)
	{
		shifts[i][0] = (int) Math.floor(centroids[i][0] * ratio / 100.0);
		shifts[i][1] = (int) Math.floor(centroids[i][1] * ratio / 100.0);
	}
	
       // create associative array to know index of each label
	HashMap<Integer, Integer> labelIndices = new HashMap<Integer, Integer>();
       for (int i = 0; i < nLabels; i++) 
       {
       	labelIndices.put(labels[i], i);
       }

	for (int y = 0; y < sizeY; y++)
	{
		for (int x = 0; x < sizeX; x++)
		{
			float label = image.getf(x, y);
			if ( Float.compare( label, 0f ) == 0 )
				continue;

			int index = labelIndices.get((int)label);
			int x2 = x + shifts[index][0];
			int y2 = y + shifts[index][1];
			result.setf( x2, y2, label );
		}
	}
	
	return result;
}
 
Example 18
Source File: GeodesicReconstructionHybridTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link ijt.filter.morphology.GeodesicReconstruction#reconstructByErosion()}.
 */
@Test
public void testReconstructByErosion_FloatC8() {
	float BG = -42;
	float FG = 2500;
	float[][] data = new float[][]{
			{BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG},   
			{BG, FG, FG, BG, FG, FG, BG, FG, FG, FG, FG, FG, FG, FG, FG, BG},
			{BG, FG, FG, BG, FG, FG, BG, FG, FG, FG, FG, FG, FG, FG, FG, BG},
			{BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, BG, BG, BG, FG, FG, BG},
			{BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG},
			{BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG},
			{BG, FG, FG, BG, BG, BG, BG, FG, FG, BG, FG, FG, BG, FG, FG, BG},
			{BG, FG, FG, FG, FG, FG, FG, FG, FG, BG, FG, FG, BG, FG, FG, BG},
			{BG, FG, FG, FG, FG, FG, FG, FG, FG, BG, FG, FG, BG, FG, FG, BG},
			{BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG, BG},
	};
	int height = data.length;
	int width = data[0].length;
	ImageProcessor mask = new FloatProcessor(width, height);
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			if (data[y][x] == FG)
				mask.setf(x, y, BG);
			else
				mask.setf(x, y, FG);
		}
	}
	
	ImageProcessor marker = new FloatProcessor(width, height);
	marker.setColor(FG);
	marker.fill();
	marker.setf(2, 3, BG);
	
	GeodesicReconstructionHybrid algo = new GeodesicReconstructionHybrid(
			GeodesicReconstructionType.BY_EROSION, 8);
	ImageProcessor result = algo.applyTo(marker, mask);
	
	assertEquals(16, result.getWidth());
	assertEquals(10, result.getHeight());
	assertEquals(BG, result.getf(2, 8), .01);
	assertEquals(BG, result.getf(8, 8), .01);
	assertEquals(BG, result.getf(8, 5), .01);
	assertEquals(BG, result.getf(14, 8), .01);
	assertEquals(FG, result.getf(15, 9), .01);
	assertEquals(FG, result.getf(0, 0), .01);
	assertEquals(FG, result.getf(5, 3), .01);
	assertEquals(FG, result.getf(11, 5), .01);
}
 
Example 19
Source File: Cross3x3Strel.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void inPlaceDilationFloat(ImageProcessor image) {
	// size of image
	int width = image.getWidth();
	int height = image.getHeight();
	
	float[][] buffer = new float[3][width];
	
	// init buffer with background and first two lines
	for (int x = 0; x < width; x++) {
		buffer[0][x] = Float.NEGATIVE_INFINITY;
		buffer[1][x] = Float.NEGATIVE_INFINITY;
		buffer[2][x] = image.getf(x, 0);
	}
	
	// Iterate over image lines
	float valMax;
	for (int y = 0; y < height; y++) {
		fireProgressChanged(this, y, height);
		
		// permute lines in buffer
		float[] tmp = buffer[0];
		buffer[0] = buffer[1];
		buffer[1] = buffer[2];
		
		// initialize values of the last line in buffer 
		if (y < height - 1) {
			for (int x = 0; x < width; x++) 
				tmp[x] = image.getf(x, y+1);
		} else {
			for (int x = 0; x < width; x++) 
				tmp[x] = Float.NEGATIVE_INFINITY;
		}
		buffer[2] = tmp;
		
		// process first pixel independently
		valMax = max5(buffer[0][0], buffer[1][0], 
				buffer[1][1], buffer[2][0], Float.NEGATIVE_INFINITY);
		image.setf(0, y, valMax);
		
		// Iterate over pixel of the line
		for (int x = 1; x < width - 1; x++) {
			valMax = max5(buffer[0][x], buffer[1][x-1], buffer[1][x], 
					buffer[1][x+1], buffer[2][x]);
			image.setf(x, y, valMax);
		}
		
		// process last pixel independently
		valMax = max5(buffer[0][width-1], buffer[1][width-2], 
				buffer[1][width-1], buffer[2][width-1], Float.NEGATIVE_INFINITY);
		image.setf(width-1, y, valMax);
	}
	
	// clear the progress bar
	fireProgressChanged(this, height, height);
}
 
Example 20
Source File: ShiftedCross3x3Strel.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void inPlaceDilationFloat(ImageProcessor image) {
	// size of image
	int width = image.getWidth();
	int height = image.getHeight();

	float[][] buffer = new float[3][width];

	// init buffer with background and first two lines
	for (int x = 0; x < width; x++) {
		buffer[0][x] = Float.NEGATIVE_INFINITY;
		buffer[1][x] = Float.NEGATIVE_INFINITY;
		buffer[2][x] = image.getf(x, 0);
	}

	// Iterate over image lines
	float valMax;
	for (int y = 0; y < height; y++) {
		fireProgressChanged(this, y, height);

		// permute lines in buffer
		float[] tmp = buffer[0];
		buffer[0] = buffer[1];
		buffer[1] = buffer[2];

		// initialize values of the last line in buffer 
		if (y < height - 1) {
			for (int x = 0; x < width; x++) 
				tmp[x] = image.getf(x, y+1);
		} else {
			for (int x = 0; x < width; x++) 
				tmp[x] = Float.NEGATIVE_INFINITY;
		}
		buffer[2] = tmp;

		// Iterate over pixels of the line
		for (int x = 0; x < width - 2; x++) {
			valMax = max5(buffer[0][x+1], buffer[1][x], buffer[1][x+1], 
					buffer[1][x+2], buffer[2][x+1]);
			image.setf(x, y, valMax);
		}
		
		// process last two pixels independently
		valMax = max5(buffer[0][width-1], buffer[1][width-2], 
				buffer[1][width-1], buffer[2][width-1], Float.NEGATIVE_INFINITY);
		image.setf(width-2, y, valMax);
		valMax = Math.max(buffer[1][width-1], Float.NEGATIVE_INFINITY);
		image.setf(width-1, y, valMax);
	}
	
	// clear the progress bar
	fireProgressChanged(this, height, height);
}