ij.process.ImageProcessor Java Examples

The following examples show how to use ij.process.ImageProcessor. 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: WatershedTransform2D.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Construct a watershed transform
 * 
 * @param input input image (usually a gradient image)
 * @param mask binary mask to restrict the region of interest (null to use whole input image)
 * @param connectivity pixel connectivity (4 or 8)
 */
public WatershedTransform2D(
		final ImageProcessor input,
		final ImageProcessor mask,
		final int connectivity )
{
	this.inputImage = input;
	this.maskImage = mask;
	
	if( connectivity != 4 && connectivity != 8 ) 
    {
		throw new IllegalArgumentException("Illegal connectivity value: it must be 4 or 8!");
	}
	
	this.connectivity = connectivity;
}
 
Example #2
Source File: DistanceTransformWatershed.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Apply the current filter settings to process the given image.
 */
public void run(ImageProcessor image)
{
	synchronized (this){
		if (floatProcessing)
			result = processFloat(image, weights.getFloatWeights(), normalize );
		else
			result = processShort(image, weights.getShortWeights(), normalize);
	}
	if (previewing)
	{
		// Fill up the values of original image with values of the result
		double valMax = result.getMax();
		for (int i = 0; i < image.getPixelCount(); i++)
		{
			image.set(i, (int) (255 * result.getf(i) / valMax));
		}
		image.resetMinAndMax();
		if (image.isInvertedLut())
			image.invertLut();
	}
}
 
Example #3
Source File: BinaryOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
public void run (ImageProcessor ip) {
	int fg = Prefs.blackBackground ? 255 : 0;
	foreground = ip.isInvertedLut() ? 255-fg : fg;
	background = 255 - foreground;
	ip.setSnapshotCopyMode(true);
	if (arg.equals("outline"))
		outline(ip);
	else if (arg.startsWith("fill"))
		fill(ip, foreground, background);
	else if (arg.startsWith("skel")) {
		ip.resetRoi(); skeletonize(ip);
	} else if (arg.equals("erode") || arg.equals("dilate"))
		doIterations(ip, arg);
	else if (arg.equals("open")) {
		doIterations(ip, "erode");
		doIterations(ip, "dilate");
	} else if (arg.equals("close")) {
		doIterations(ip, "dilate");
		doIterations(ip, "erode");
	}
	ip.setSnapshotCopyMode(false);
	ip.setBinaryThreshold();
}
 
Example #4
Source File: BinaryImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Converts a grayscale 2D image into a binary 2D image by setting
 * zero elements to 255, and non zero ones to 0.
 * 
 * @param image
 *            a gray scale image
 * @return a binary image containing 255 for all non-zero elements of
 *         original image
 	 */
public static final ImageProcessor binarizeBackground(ImageProcessor image) 
{
	int width = image.getWidth();
	int height = image.getHeight();
	ImageProcessor result = new ByteProcessor(width, height);
	
	for (int y = 0; y < height; y++)
	{
		for (int x = 0; x < width; x++) 
		{
			if (image.get(x, y) == 0) 
				result.set(x, y, 255);
		}
	}
	
	return result;
}
 
Example #5
Source File: ImageCalculatorTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.math.ImageCalculator#combineImages(ij.process.ImageProcessor, ij.process.ImageProcessor, inra.ijpb.math.ImageCalculator.Operation)}.
 */
@Test
public final void testCombineImages_FloatFloat_Times_Self()
{
    int width = 30;
    int height = 20;
    ImageProcessor image1 = new FloatProcessor(width, height);
    for (int i = 0; i < width; i++)
    {
        for (int j = 0; j < height; j++)
        {
            image1.setf(i, j, (float) (i+j));
        }
    }
    
    ImageCalculator.Operation op = ImageCalculator.Operation.TIMES;
    ImageProcessor result = ImageCalculator.combineImages(image1, image1, op);
    
    assertTrue(result instanceof FloatProcessor);
    assertEquals(30, result.getWidth());
    assertEquals(20, result.getHeight());
    
    assertEquals(48f*48f, result.getf(29, 19), .001);
    assertEquals(29f*29f, result.getf(29, 0), .001);
    assertEquals(19f*19f, result.getf(0, 19), .001);
}
 
Example #6
Source File: GrayscaleBoxDiameterOpeningPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void run(ImageProcessor image)
{
	BoxDiagonalOpeningQueue algo = new BoxDiagonalOpeningQueue();
	DefaultAlgoListener.monitor(algo);
	this.result = algo.process(image, this.minDiagonalLength); 
	
	if (previewing)
	{
		// Iterate over pixels to change value of reference image
		for (int i = 0; i < image.getPixelCount(); i++)
		{
			image.set(i, result.get(i));
		}
	}
}
 
Example #7
Source File: AreaOpeningQueue.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Collection<Point> findMaximaPositions(ImageProcessor image)
{
	// identify each maxima
	ImageProcessor maxima = MinimaAndMaxima.regionalMaxima(image, conn);
	
	int sizeX = image.getWidth();
	int sizeY = image.getHeight();
	
	Collection<Point> positions = new ArrayList<Point>();
	
	for (int y = 0; y < sizeY; y++)
	{
		for (int x = 0; x < sizeX; x++)
		{
			// if current pixel is a regional maximum, keep the position,
			// and remove the regional maximum
			if (maxima.get(x, y) > 0)
			{
				positions.add(new Point(x, y));
				FloodFill.floodFill(maxima, x, y, 0, this.conn);
			}
		}
	}

	return positions;
}
 
Example #8
Source File: CrossCorrelation2D.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
public CrossCorrelation2D(ImageProcessor ip1, ImageProcessor ip2, boolean showImages)
{
    if (showImages)
    {
        ImagePlus img1 = new ImagePlus("Image 1", ip1);
        ImagePlus img2 = new ImagePlus("Image 2", ip2);

        img1.show();
        img2.show();
    }

    this.img1 = ImageToFloatArray2D(ip1);
    this.img2 = ImageToFloatArray2D(ip2);
    this.showImages = showImages;
    //computeCrossCorrelation(ImageToFloatArray2D(ip1), ImageToFloatArray2D(ip2), showImages);
}
 
Example #9
Source File: GeodesicDiameterShortTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.binary.geodesic.GeodesicDiameterShort#longestGeodesicPaths(ij.process.ImageProcessor)}.
 */
@Test
public void testLongestGeodesicPaths_Rect()
{
	ImageProcessor image = new ByteProcessor(10, 3);
	for (int x = 1; x < 8; x++)
	{
		image.set(x, 1, 255);
	}

	GeodesicDiameterShort algo = new GeodesicDiameterShort(ChamferWeights.BORGEFORS);
	algo.analyzeImage(image);
	Map<Integer, List<Point>> pathMap = algo.longestGeodesicPaths();

	assertEquals(1, pathMap.size());
	List<Point> path1 = pathMap.get(255);
	assertEquals(7, path1.size());
}
 
Example #10
Source File: DistanceTransform5x5FloatTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public final void testDistanceMap_ChessBoard() 
{
	ByteProcessor image = new ByteProcessor(12, 10);
	image.setBackgroundValue(0);
	image.fill();
	for (int y = 2; y < 8; y++) {
		for (int x = 2; x < 10; x++) {
			image.set(x, y, 255);
		}
	}
	
	float[] weights = ChamferWeights.CHESSBOARD.getFloatWeights();
	DistanceTransform5x5Float algo = new DistanceTransform5x5Float(weights, true);
	ImageProcessor result = algo.distanceMap(image);
	
	assertNotNull(result);
	assertEquals(image.getWidth(), result.getWidth());
	assertEquals(image.getHeight(), result.getHeight());
	assertEquals(3, result.getf(4, 4), 1e-12);
}
 
Example #11
Source File: GeodesicDistanceTransformShort5x5Test.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testGeodesicDistanceMap_Borgefors()
{
	ImagePlus maskPlus = IJ.openImage(getClass().getResource("/files/circles.tif").getFile());
	ImageProcessor mask = maskPlus.getProcessor();
	ImageProcessor marker = mask.duplicate();
	marker.fill();
	marker.set(30, 30, 255);

	short[] weights = new short[] { 5, 7, 11 };
	GeodesicDistanceTransform algo = new GeodesicDistanceTransformShort5x5(
			weights, true);
	ImageProcessor map = algo.geodesicDistanceMap(marker, mask);

	assertEquals(250, map.get(190, 210));
}
 
Example #12
Source File: BinaryImages.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Computes the geodesic distance transform (or geodesic distance map) of a
 * binary image of marker, constrained to a binary mask. 
 * Returns the result in a new instance of FloatProcessor.
 * 
 * @param marker
 *            the binary image of marker
 * @param mask
 *            the binary image of mask
 * @param weights
 *            an array of chamfer weights, with at least two values
 * @param normalize
 *            indicates whether the resulting distance map should be
 *            normalized (divide distances by the first chamfer weight)
 * @return the geodesic distance map in a new ImageProcessor
 */
public static final ImageProcessor geodesicDistanceMap(ImageProcessor marker,
		ImageProcessor mask, float[] weights, boolean normalize) 
{
	GeodesicDistanceTransform algo;
	switch (weights.length) 
	{
	case 2:
		algo = new GeodesicDistanceTransformFloat(weights, normalize);
		break;
	case 3:
		algo = new GeodesicDistanceTransformFloat5x5(weights, normalize);
		break;
	default:
		throw new IllegalArgumentException(
				"Requires weight array with 2 or 3 elements");
	}
	
	return algo.geodesicDistanceMap(marker, mask);
}
 
Example #13
Source File: SquareStrelTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testErosion_Square4x4() {
	ImageProcessor image = createImage_Square4x4();
	Strel strel = new SquareStrel(3);
	
	ImageProcessor result = strel.erosion(image);

	for (int y = 0; y < 4; y++) {
		for (int x = 0; x < 10; x++) {
			assertEquals(0, result.get(x, y));
		}
	}
	for (int y = 4; y < 6; y++) {
		assertEquals(0, result.get(3, y));
		assertEquals(255, result.get(4, y));
		assertEquals(255, result.get(5, y));
		assertEquals(0, result.get(6, y));
	}
	for (int y = 6; y < 10; y++) {
		for (int x = 0; x < 10; x++) {
			assertEquals(0, result.get(x, y));
		}
	}
}
 
Example #14
Source File: GeometricMeasures2DTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Initialize 20x20 image with a disk of radius 8 in the middle, resulting
 * in expected perimeter equal to 50.2655. The center of the disk is 
 * slightly shifted to reduce discretization artifacts.
 * 
 * Test method for {@link ijt.measure.geometric.GeometricMeasures2D#croftonPerimeter_D2(ij.process.ImageProcessor, double[])}.
 */
@Test
@Deprecated
public final void testCroftonPerimeterD2_DiskR8()
{
	ImageProcessor image = createDiskR8Image();

	double[] resol = new double[]{1, 1};
	int[] labels = new int[]{255};
	double perims[] = GeometricMeasures2D.croftonPerimeterD2(image, labels, resol);
	assertEquals(1, perims.length);

	double exp = 2 * Math.PI * 8;
	// relative error is expected to be lower than 22% for four directions
	assertEquals(exp, perims[0], exp * .22);
}
 
Example #15
Source File: IntrinsicVolumes2DTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.measure.IntrinsicVolumes2D#eulerNumber(ij.process.ImageProcessor, int)}.
 */
@Test
public final void testEulerNumber_crossTouchingBordersC4()
{
	// create a binary image containing a square
	ImageProcessor image = new ByteProcessor(6, 6);
	for (int i = 0; i < 6; i++)
	{
		image.set(i, 2, 255);
		image.set(i, 3, 255);
		image.set(2, i, 255);
		image.set(3, i, 255);
	}
	
	int euler = IntrinsicVolumes2D.eulerNumber(image, 4);
	assertEquals(1, euler);
}
 
Example #16
Source File: AreaOpeningQueueTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testProcess()
{
	int sizeX = 4;
	int sizeY = 4;
	ImageProcessor image = new ByteProcessor(sizeX, sizeY);
	image.set(1, 1, 5);
	image.set(2, 1, 4);
	image.set(1, 2, 3);
	image.set(2, 2, 2);
	
	AreaOpening algo = new AreaOpeningQueue();

	ImageProcessor output = algo.process(image, 4);
	
	assertEquals(2, output.get(1, 1));
	assertEquals(2, output.get(2, 1));
	assertEquals(2, output.get(1, 2));
	assertEquals(2, output.get(2, 2));
}
 
Example #17
Source File: NonLinearTransform.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
public ImageProcessor[] transform(final ImageProcessor ip){
	if (!precalculated)
		this.precalculateTransfom();

	final ImageProcessor newIp = ip.createProcessor(ip.getWidth(), ip.getHeight());
	if (ip instanceof ColorProcessor) ip.max(0);
	final ImageProcessor maskIp = new ByteProcessor(ip.getWidth(),ip.getHeight());

	for (int x=0; x < width; x++){
		for (int y=0; y < height; y++){
			if (transField[x][y][0] == -1){
				continue;
			}
			newIp.set(x, y, (int) ip.getInterpolatedPixel((int)transField[x][y][0],(int)transField[x][y][1]));
			maskIp.set(x,y,255);
		}
	}
	return new ImageProcessor[]{newIp, maskIp};
}
 
Example #18
Source File: AreaOpeningQueueTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testProcessTwoMaxima()
{
	int sizeX = 6;
	int sizeY = 4;
	ImageProcessor image = new ByteProcessor(sizeX, sizeY);
	image.set(1, 1, 5);
	image.set(1, 2, 4);
	image.set(2, 1, 3);
	image.set(2, 2, 2);
	image.set(3, 1, 6);
	image.set(3, 2, 5);
	
	AreaOpening algo = new AreaOpeningQueue();

	ImageProcessor output = algo.process(image, 4);
	
	assertEquals(3, output.get(1, 1));
	assertEquals(3, output.get(2, 1));
	assertEquals(3, output.get(3, 1));
	assertEquals(3, output.get(1, 2));
	assertEquals(2, output.get(2, 2));
	assertEquals(3, output.get(3, 2));
}
 
Example #19
Source File: GeodesicDistanceTransformFloat5x5.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
private FloatProcessor initialize(ImageProcessor marker)
{
	// size of image
	sizeX = marker.getWidth();
	sizeY = marker.getHeight();
	
	FloatProcessor distMap = new FloatProcessor(sizeX, sizeY);
	distMap.setValue(0);
	distMap.fill();

	// initialize empty image with either 0 (foreground) or NaN (background)
	for (int y = 0; y < sizeY; y++) 
	{
		for (int x = 0; x < sizeX; x++) 
		{
			int val = marker.get(x, y) & 0x00ff;
			distMap.setf(x, y, val == 0 ? Float.POSITIVE_INFINITY : 0);
		}
	}

	return distMap;
}
 
Example #20
Source File: DistanceTransform5x5ShortTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Another test for chess-knight weights, to fix a bug that incorrectly
 * checked image bounds.
 */
@Test
public final void testDistanceMap_UntilCorners_ChessKnight2()
{
	ByteProcessor image = new ByteProcessor(9, 9);
	image.setValue(255);
	image.fill();
	image.set(6, 6, 0);
	
	short[] weights = ChamferWeights.CHESSKNIGHT.getShortWeights();
	DistanceTransform5x5Short algo = new DistanceTransform5x5Short(weights, false);
	ImageProcessor result = algo.distanceMap(image);
	
	assertNotNull(result);
	assertEquals(image.getWidth(), result.getWidth());
	assertEquals(image.getHeight(), result.getHeight());
	assertEquals(42, result.get(0, 0));
	assertEquals(32, result.get(8, 0));
	assertEquals(32, result.get(0, 8));
	assertEquals(14, result.get(8, 8));
	
	assertEquals(30, result.get(0, 6));
}
 
Example #21
Source File: HistogramMatcher.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
public static BufferedImage matchHisto(BufferedImage bi2, int[] histoToMatch) {
    ImagePlus ip = new ImagePlus("img",bi2);
    ImageConverter ic = new ImageConverter(ip);
    ic.convertToHSB();
    ImageProcessor processor = ip.getStack().getProcessor(2); // HSB -> processor 2 = saturation
    // ic.convertToGray8();
    // ImageProcessor processor = ip.getProcessor();
    int[] histo2 = processor.getHistogram();

    int[] lut = matchHistograms(histo2, histoToMatch);

    int c;
    for (int x=0; x<processor.getWidth(); x++)
        for (int y=0; y<processor.getHeight(); y++) {
            c = processor.get(x,y);
            if (c>18)
                processor.set(x,y,lut[c]);
        }

    //processor.setThreshold(20,200,ImageProcessor.NO_LUT_UPDATE);
    //processor.setAutoThreshold(AutoThresholder.Method.Otsu, false,ImageProcessor.OVER_UNDER_LUT);
    //processor.applyTable(lut);

    ic.convertHSBToRGB();
    return ip.getBufferedImage();
}
 
Example #22
Source File: TestImageAccessor.java    From Colocalisation_Analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a mask image with a black background and a white
 * rectangular foreground.
 *
 * @param width The width of the result image.
 * @param height The height of the result image.
 * @param offset The offset of the rectangular mask.
 * @param size The size of the rectangular mask.
 * @return A black image with a white rectangle on it.
 */
public static <T extends RealType<T> & NativeType<T>> RandomAccessibleInterval<T> createRectengularMaskImage(
		long width, long height, long[] offset, long[] size) {
	/* For now (probably until ImageJ2 is out) we use an
	 * ImageJ image to draw lines.
	 */
	int options = NewImage.FILL_BLACK + NewImage.CHECK_AVAILABLE_MEMORY;
        ImagePlus img = NewImage.createByteImage("Noise", (int)width, (int)height, 1, options);
	ImageProcessor imp = img.getProcessor();
	imp.setColor(Color.WHITE);
	Roi rect = new Roi(offset[0], offset[1], size[0], size[1]);

	imp.fill(rect);
	// we changed the data, so update it
	img.updateImage();

	return ImagePlusAdapter.wrap(img);
}
 
Example #23
Source File: DiskStrelTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Dilates a single pixel by a 3x3 disk, and check the shape of the result.
 * The result should be a 3x3 square (approximation of 3x3 disk)
 */
@Test
public void testDilate_SinglePixel_Radius() {
	Strel strel = DiskStrel.fromRadius(1);
	
	ImageProcessor image = new ByteProcessor(10, 10);
	image.setValue(0);
	image.fill();
	image.set(5, 5, 255);
	ImageProcessor result = strel.dilation(image);

	// Check all values inside square
	for (int y = 4; y < 7; y++)
		for (int x = 4; x < 7; x++)
			assertEquals(255, result.get(x, y));
}
 
Example #24
Source File: IntrinsicVolumes2DTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Test method for {@link inra.ijpb.measure.IntrinsicVolumes2D#perimeter(ij.process.ImageProcessor, Calibration, int)}.
 */
@Test
public final void testPerimeter_disk_D2()
{
	double radius = 16.0;

	// create a binary image containing a square
	ImageProcessor image = new ByteProcessor(40, 40);
	for (int y = 0; y < 40; y++)
	{
		double y2 = (y - 20.2);
		for (int x = 0; x < 40; x++)
		{
			double x2 = (x - 20.3);
			image.set(x, y, Math.hypot(x2, y2) < radius ? 255 : 0);
		}
	}
	
	// compute perimeter with default (1,1) calibration
	Calibration calib = new Calibration();
	double perim = IntrinsicVolumes2D.perimeter(image, calib, 2);
	
	// check to expected value with a tolerance of 5 percents
	double exp = 2 * Math.PI * radius;
	assertEquals(exp, perim, exp * 0.05);
}
 
Example #25
Source File: Distortion_Correction.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
ImageProcessor applyTransformToImageInverse(
		final AbstractAffineModel2D< ? > a, final ImageProcessor ip){
	final ImageProcessor newIp = ip.duplicate();
	newIp.max(0.0);

	for (int x=0; x<ip.getWidth(); x++){
		for (int y=0; y<ip.getHeight(); y++){
			final double[] position = new double[]{x,y};
			//				float[] newPosition = a.apply(position);
			double[] newPosition = new double[]{0,0};
			try
			{
				newPosition = a.applyInverse(position);
			}
			catch ( final NoninvertibleModelException e ) {}

			final int xn = (int) newPosition[0];
			final int yn = (int) newPosition[1];

			if ( (xn >= 0) && (yn >= 0) && (xn < ip.getWidth()) && (yn < ip.getHeight()))
				newIp.set(xn,yn,ip.get(x,y));

		}
	}
	return newIp;
}
 
Example #26
Source File: LargestInscribedCircle.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Computes largest inscribed disk of each region within a label image.
 * Regions must be disjoint.
 * 
 * @param labelImage
 *            the input image containing region labels
 * @param labels
 *            the set of labels within the image
 * @param calib
 *            the spatial calibration of the image
 * @return an array of Circle2D representing the inscribed circles of each
 *         region, in calibrated coordinates
 */
public Circle2D[] analyzeRegions(ImageProcessor labelImage, int[] labels, Calibration calib)
   {
   	// compute max label within image
   	int nLabels = labels.length;
   	
	// first distance propagation to find an arbitrary center
   	fireStatusChanged(this, "Compute distance map");
	ImageProcessor distanceMap = BinaryImages.distanceMap(labelImage);
	
	// Extract position of maxima
	fireStatusChanged(this, "Find inscribed disks center");
	Point[] posCenter;
	posCenter = findPositionOfMaxValues(distanceMap, labelImage, labels);
	float[] radii = getValues(distanceMap, posCenter);

	// Create result data table
	Circle2D[] circles = new Circle2D[nLabels];
	for (int i = 0; i < nLabels; i++) 
	{
		double xc = posCenter[i].x * calib.pixelWidth + calib.xOrigin;
		double yc = posCenter[i].y * calib.pixelHeight + calib.yOrigin;
		Point2D center = new Point2D.Double(xc, yc);
		circles[i] = new Circle2D(center, radii[i] * calib.pixelWidth);
	}

	return circles;
   }
 
Example #27
Source File: BinaryOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
ImageProcessor shrink(ImageProcessor ip, ImageProcessor ip2, boolean hasEdgePixels) {
	if (hasEdgePixels) {
		int width = ip.getWidth();
		int height = ip.getHeight();
		for (int y=0; y<height; y++)
			for (int x=0; x<width; x++)
				ip.putPixel(x, y, ip2.getPixel(x+1, y+1));
	}
	return ip;
}
 
Example #28
Source File: LUTYellow.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ImageProcessor process(ImageProcessor ip) {
	if (ip instanceof ColorProcessor) {
		Utils.log("Ignoring " + getClass().getSimpleName() + " filter for RGB image");
		return ip;
	}
	byte[] s = new byte[256];
	for (int i=0; i<256; ++i) s[i] = (byte)i;
	ip.setColorModel(new IndexColorModel(8, 256, s, s, new byte[256]));
	return ip;
}
 
Example #29
Source File: LabelSizeFilteringTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Test method for
 * {@link inra.ijpb.label.select.LabelSizeFiltering#process(ij.process.ImageProcessor)}.
 */
@Test
public void testProcessImageProcessor_GE()
{
	ByteProcessor image = createLabelImage();
	ImageProcessor result = new LabelSizeFiltering(RelationalOperator.GE, 5).process(image);
	int[] labels = LabelImages.findAllLabels(result);
	assertEquals(3, labels.length);
}
 
Example #30
Source File: ShiftedCross3x3Strel_LeftTest.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testDilation_Square4x4() {
	ImageProcessor image = createImage_Square4x4();
	Strel strel = ShiftedCross3x3Strel.LEFT;
	
	ImageProcessor expected = image.createProcessor(10, 10);
	for (int x = 4; x < 8; x++) {
		expected.set(x, 2, 255);
		expected.set(x, 7, 255);
	}
	for (int y = 3; y < 7; y++) {
		for (int x = 3; x < 9; x++) {
			expected.set(x, y, 255);
		}
	}

	ImageProcessor result = strel.dilation(image);
	
	for (int y = 0; y < image.getHeight(); y++) {
		for (int x = 0; x < image.getWidth(); x++) {
			int exp = expected.get(x, y);
			int res = result.get(x, y);
			if(expected.get(x, y) != result.get(x, y)) {
				System.out.println("At x=" + x + " and y=" + y
						+ ", exp=" + exp + " and res = " + res);
			}
			assertEquals(exp, res);
		}			
	}
}