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

The following examples show how to use ij.process.ImageProcessor#invertLut() . 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: 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 2
Source File: ChamferDistanceMapPlugin.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) 
  {
  	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: MorphologicalFilterCross3DPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Displays the current structuring element in a new ImagePlus. 
 * @param strel the structuring element to display
 */
private void showStrelImage(Strel3D strel) {
	// Size of the strel image (little bit larger than strel)
	int[] dim = strel.getSize();
	int width = dim[0] + 20; 
	int height = dim[1] + 20;
	
	// Creates strel image by dilating a point
	ImageProcessor maskProcessor = new ByteProcessor(width, height);
	maskProcessor.set(width / 2, height / 2, 255);
	ImageStack stack = new ImageStack();
	stack.addSlice(maskProcessor);
	stack = Morphology.dilation(stack, strel);
	maskProcessor = stack.getProcessor(1);
	
	// Forces the display to inverted LUT (display a black over white)
	if (!maskProcessor.isInvertedLut())
		maskProcessor.invertLut();
	
	// Display strel image
	ImagePlus maskImage = new ImagePlus("Element", maskProcessor);
	maskImage.show();
}
 
Example 4
Source File: ThresholderOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
void setInvertedLut(ImagePlus imp) {
	ImageProcessor ip = imp.getProcessor();
	ip.invertLut();
	int nImages = imp.getStackSize();
	if (nImages==1)
		ip.invert();
	else {
		ImageStack stack = imp.getStack();
		for (int slice=1; slice<=nImages; slice++)
			stack.getProcessor(slice).invert();
		stack.setColorModel(ip.getColorModel());
	}
}
 
Example 5
Source File: MorphologicalFilterPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Displays the current structuring element in a new ImagePlus. 
 * @param strel the structuring element to display
 */
private void showStrelImage(Strel strel)
{
	// Size of the strel image (little bit larger than strel)
	int[] dim = strel.getSize();
	int width = dim[0] + 20; 
	int height = dim[1] + 20;
	
	// Creates strel image by dilating a point
	ImageProcessor strelImage = new ByteProcessor(width, height);
	strelImage.set(width / 2, height / 2, 255);
	strelImage = Morphology.dilation(strelImage, strel);
	
	// Forces the display to inverted LUT (display a black over white)
	if (!strelImage.isInvertedLut())
		strelImage.invertLut();
	
	// Display strel image
	if (strelDisplay == null)
	{
		strelDisplay = new ImagePlus("Structuring Element", strelImage);
	} 
	else 
	{
		strelDisplay.setProcessor(strelImage);
	}
	strelDisplay.show();
}
 
Example 6
Source File: InteractiveMorphologicalReconstruction.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Apply the current filter settings to process the given image.
 */
public void run( ImageProcessor image )
{
	if( null == image )
		return;
	long t0 = System.currentTimeMillis();

	// Compute geodesic reconstruction
	result = process( image, imagePlus.getRoi() );

	if ( null == result )
	{
		// force preview to be unchecked when processing fails
		gd.getPreviewCheckbox().setState( false );
		pfr.dialogItemChanged( gd,
				new ActionEvent( gd.getPreviewCheckbox(),
						ActionEvent.ACTION_PERFORMED, "Preview" ) );
		return;
	}
	if( previewing )
	{
		// Fill up the values of original image with values of the result
		image.setPixels( result.getPixels() );

		image.resetMinAndMax();

		if (image.isInvertedLut())
			image.invertLut();
	}

	long t1 = System.currentTimeMillis();
	IJUtils.showElapsedTime(operation.toString(), t1 - t0, imagePlus);
}
 
Example 7
Source File: ThresholderOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
public void applyThreshold(ImagePlus imp) {
	imp.deleteRoi();
	ImageProcessor ip = imp.getProcessor();
	ip.resetBinaryThreshold();
	int type = imp.getType();
	if (type==ImagePlus.GRAY16 || type==ImagePlus.GRAY32) {
		applyShortOrFloatThreshold(imp);
		return;
	}
	if (!imp.lock()) return;
	double saveMinThreshold = ip.getMinThreshold();
	double saveMaxThreshold = ip.getMaxThreshold();
	autoThreshold = saveMinThreshold==ImageProcessor.NO_THRESHOLD;

	boolean useBlackAndWhite = true;
	boolean noArgMacro =IJ.macroRunning() && Macro.getOptions()==null;
	if (skipDialog)
		fill1 = fill2 = useBlackAndWhite = true;
	else if (!(autoThreshold||noArgMacro)) {
		GenericDialog gd = new GenericDialog("Make Binary");
		gd.addCheckbox("Thresholded pixels to foreground color", fill1);
		gd.addCheckbox("Remaining pixels to background color", fill2);
		gd.addMessage("");
		gd.addCheckbox("Black foreground, white background", useBW);
		gd.showDialog();
		if (gd.wasCanceled())
		{imp.unlock(); return;}
		fill1 = gd.getNextBoolean();
		fill2 = gd.getNextBoolean();
		useBW = useBlackAndWhite = gd.getNextBoolean();
	} else {
		fill1 = fill2 = true;
		convertToMask = true;
	}

	if (type!=ImagePlus.GRAY8)
		convertToByte(imp);
	ip = imp.getProcessor();

	if (autoThreshold)
		autoThreshold(ip);
	else {
		if (Recorder.record && !Recorder.scriptMode() && (!IJ.isMacro()||Recorder.recordInMacros))
			Recorder.record("setThreshold", (int)saveMinThreshold, (int)saveMaxThreshold);
		minThreshold = saveMinThreshold;
		maxThreshold = saveMaxThreshold;
	}

	if (convertToMask && ip.isColorLut())
		ip.setColorModel(ip.getDefaultColorModel());
	int fcolor, bcolor;
	ip.resetThreshold();
	int savePixel = ip.getPixel(0,0);
	if (useBlackAndWhite)
		ip.setColor(Color.black);
	else
		ip.setColor(Toolbar.getForegroundColor());
	ip.drawPixel(0,0);
	fcolor = ip.getPixel(0,0);
	if (useBlackAndWhite)
		ip.setColor(Color.white);
	else
		ip.setColor(Toolbar.getBackgroundColor());
	ip.drawPixel(0,0);
	bcolor = ip.getPixel(0,0);
	ip.setColor(Toolbar.getForegroundColor());
	ip.putPixel(0,0,savePixel);

	int[] lut = new int[256];
	for (int i=0; i<256; i++) {
		if (i>=minThreshold && i<=maxThreshold)
			lut[i] = fill1?fcolor:(byte)i;
		else {
			lut[i] = fill2?bcolor:(byte)i;
		}
	}
	if (imp.getStackSize()>1)
		new StackProcessor(imp.getStack(), ip).applyTable(lut);
	else
		ip.applyTable(lut);
	if (convertToMask) {
		if (!imp.isInvertedLut()) {
			setInvertedLut(imp);
			fcolor = 255 - fcolor;
			bcolor = 255 - bcolor;
		}
		if (Prefs.blackBackground)
			ip.invertLut();
	}
	if (fill1 && fill2 && ((fcolor==0&&bcolor==255)||(fcolor==255&&bcolor==0)))
		imp.getProcessor().setThreshold(fcolor, fcolor, ImageProcessor.NO_LUT_UPDATE);
	imp.updateAndRepaintWindow();
	imp.unlock();
}
 
Example 8
Source File: Lines_.java    From ij-ridgedetection with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Make binary.
 */
public void makeBinary() {
	ImagePlus binary = IJ.createHyperStack(imp.getTitle() + " Detected segments", imp.getWidth(), imp.getHeight(),
			imp.getNChannels(), imp.getStackSize() / imp.getNChannels(), 1, 8);
	binary.copyScale(imp);

	ImageProcessor binaryProcessor = binary.getProcessor();
	binaryProcessor.invertLut();
	if (imp.getCompositeMode() > 0) {
		((CompositeImage) binary).setLuts(imp.getLuts());
	}

	ImageStack is = binary.getImageStack();
	ImageProcessor ip = binary.getProcessor();

	for (Lines contours : result) {
		for (Line c : contours) {

			float[] x = c.getXCoordinates();
			float[] y = c.getYCoordinates();

			int[] x_poly_r = new int[x.length];
			int[] y_poly_r = new int[x.length];

			Polygon LineSurface = new Polygon();

			ip = is.getProcessor(c.getFrame());

			ip.setLineWidth(1);
			ip.setColor(255);

			for (int j = 0; j < x.length; j++) {
				// this draws the identified line
				if (j > 0) {
					ip.drawLine((int) Math.round(x[j - 1]), (int) Math.round(y[j - 1]), (int) Math.round(x[j]),
							(int) Math.round(y[j]));
				}

				// If Estimate Width is ticked, we also draw the line surface in the binary
				if (doEstimateWidth) {

					double nx = Math.sin(c.angle[j]);
					double ny = Math.cos(c.angle[j]);

					// left point coordinates are directly added to the polygon. right coordinates
					// are saved to be added at the end of the coordinates list
					LineSurface.addPoint((int) Math.round(x[j] - c.width_l[j] * nx),
							(int) Math.round(y[j] - c.width_l[j] * ny));

					x_poly_r[j] = (int) Math.round(x[j] + c.width_r[j] * nx);
					y_poly_r[j] = (int) Math.round(y[j] + c.width_r[j] * ny);
				}
			}

			if (doEstimateWidth) {
				// loop to add the right coordinates to the end of the polygon, reversed
				for (int j = 0; j < x.length; j++) {
					if (j < x.length) {
						LineSurface.addPoint(x_poly_r[x.length - 1 - j], y_poly_r[x.length - 1 - j]);
					}
				}
				// draw surfaces.
				ip.fillPolygon(LineSurface);
			}
		}
	}
	binary.show();
	binary.updateAndDraw();
}
 
Example 9
Source File: InteractiveGeodesicDistanceMap.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Apply the current filter settings to process the given image.
 */
public void run( ImageProcessor image )
{
	if( null == image )
		return;
	long t0 = System.currentTimeMillis();

	// Execute core of the plugin
	if (resultAsFloat)
		result = process( image, imagePlus.getRoi(),
				weights.getFloatWeights(), normalize );
	else
		result = process( image, imagePlus.getRoi(),
				weights.getShortWeights(), normalize );

	if ( null == result )
	{
		// force preview to be unchecked when processing fails
		gd.getPreviewCheckbox().setState( false );
		pfr.dialogItemChanged( gd,
				new ActionEvent( gd.getPreviewCheckbox(),
						ActionEvent.ACTION_PERFORMED, "Preview" ) );
		return;
	}

	if( previewing )
	{
		// Fill up the values of original image with values of the result
		double valMax = result.getMax();
		// values need to be adjusted to the input image type
		for (int i = 0; i < image.getPixelCount(); i++)
		{
			image.set(i, (int) (255 * result.getf(i) / valMax));
		}
		// Copy LUT
		image.setLut( result.getLut() );
		image.resetMinAndMax();
		if (image.isInvertedLut())
			image.invertLut();
	}

	long t1 = System.currentTimeMillis();
	IJUtils.showElapsedTime( "Interactive Geodesic Distance Map",
			t1 - t0, imagePlus );
}