Java Code Examples for ij.process.ImageProcessor#setLut()
The following examples show how to use
ij.process.ImageProcessor#setLut() .
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: LabelSizeFiltering.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
public ImageProcessor process(ImageProcessor labelImage) { // compute area of each label int[] labels = LabelImages.findAllLabels(labelImage); int[] areas = LabelImages.pixelCount(labelImage, labels); // find labels with sufficient area ArrayList<Integer> labelsToKeep = new ArrayList<Integer>(labels.length); for (int i = 0; i < labels.length; i++) { if (operator.evaluate(areas[i], sizeLimit)) { labelsToKeep.add(labels[i]); } } // Convert array list into int array int[] labels2 = new int[labelsToKeep.size()]; for (int i = 0; i < labelsToKeep.size(); i++) { labels2[i] = labelsToKeep.get(i); } // keep only necessary labels ImageProcessor result = LabelImages.keepLabels(labelImage, labels2); if (!(result instanceof ColorProcessor)) result.setLut(labelImage.getLut()); return result; }
Example 2
Source File: LabelImages.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Applies area opening on a label image: creates a new label image that * contains only particles with at least the specified number of pixels. * * @param labelImage * an image of label regions * @param nPixelMin * the minimal number of pixels of regions * @return a new image containing only regions with enough pixels */ public static final ImageProcessor areaOpening(ImageProcessor labelImage, int nPixelMin) { // compute area of each label int[] labels = findAllLabels(labelImage); int[] areas = pixelCount(labelImage, labels); // find labels with sufficient area ArrayList<Integer> labelsToKeep = new ArrayList<Integer>(labels.length); for (int i = 0; i < labels.length; i++) { if (areas[i] >= nPixelMin) { labelsToKeep.add(labels[i]); } } // Convert array list into int array int[] labels2 = new int[labelsToKeep.size()]; for (int i = 0; i < labelsToKeep.size(); i++) { labels2[i] = labelsToKeep.get(i); } // keep only necessary labels ImageProcessor result = keepLabels(labelImage, labels2); if (!(result instanceof ColorProcessor)) result.setLut(labelImage.getLut()); return result; }
Example 3
Source File: BinaryImages.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns a binary image in which the largest region has been replaced by * the background value. * * @param image * a binary image containing several individual particles * @return a new binary image containing all the regions from original image * but the largest one */ public static final ImageProcessor removeLargestRegion(ImageProcessor image) { ImageProcessor labelImage = componentsLabeling(image, 4, 16); LabelImages.removeLargestLabel(labelImage); ImageProcessor result = binarize(labelImage); result.setLut(image.getLut()); return result; }
Example 4
Source File: MorphologicalSegmentation.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Update the overlay in the display image based on * the current result and slice */ void updateResultOverlay() { if( null != resultImage ) { int slice = displayImage.getCurrentSlice(); final String displayOption = (String) resultDisplayList.getSelectedItem(); ImageRoi roi = null; if( displayOption.equals( catchmentBasinsText ) ) { roi = new ImageRoi(0, 0, resultImage.getImageStack().getProcessor( slice ) ); roi.setOpacity( 1.0 ); } else if( displayOption.equals( overlaidDamsText ) ) { ImageProcessor lines = BinaryImages.binarize( resultImage.getImageStack().getProcessor( slice ) ); lines.invert(); lines.setLut( LUT.createLutFromColor( Color.red ) ); roi = new ImageRoi( 0, 0, lines ); roi.setZeroTransparent( true ); roi.setOpacity( 1.0 ); } else if( displayOption.equals( watershedLinesText ) ) { roi = new ImageRoi(0, 0, BinaryImages.binarize( resultImage.getImageStack().getProcessor( slice ) ) ); roi.setOpacity( 1.0 ); } else if( displayOption.equals( overlaidBasinsText ) ) { roi = new ImageRoi(0, 0, resultImage.getImageStack().getProcessor( slice ) ); roi.setOpacity( opacity ); } displayImage.setOverlay( new Overlay( roi ) ); } }
Example 5
Source File: InteractiveMarkerControlledWatershed.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Update the overlay in the display image based on * the current result and slice */ void updateResultOverlay() { if( null != resultImage ) { int slice = displayImage.getCurrentSlice(); final String displayOption = (String) resultDisplayList.getSelectedItem(); ImageRoi roi = null; if( displayOption.equals( catchmentBasinsText ) ) { roi = new ImageRoi(0, 0, resultImage.getImageStack().getProcessor( slice ) ); roi.setOpacity( 1.0 ); } else if( displayOption.equals( overlaidDamsText ) ) { ImageProcessor lines = BinaryImages.binarize( resultImage.getImageStack().getProcessor( slice ) ); lines.invert(); lines.setLut( LUT.createLutFromColor( Color.red ) ); roi = new ImageRoi( 0, 0, lines ); roi.setZeroTransparent( true ); roi.setOpacity( 1.0 ); } else if( displayOption.equals( watershedLinesText ) ) { roi = new ImageRoi(0, 0, BinaryImages.binarize( resultImage.getImageStack().getProcessor( slice ) ) ); roi.setOpacity( 1.0 ); } else if( displayOption.equals( overlaidBasinsText ) ) { roi = new ImageRoi(0, 0, resultImage.getImageStack().getProcessor( slice ) ); roi.setOpacity( opacity ); } displayImage.setOverlay( new Overlay( roi ) ); } }
Example 6
Source File: ConvexifyPlugin.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void run(String arg0) { ImagePlus imagePlus = IJ.getImage(); // Check Input data validity ImagePlus resultPlus; if (imagePlus.getStackSize() > 1) { IJ.showMessage("Invalid Input", "Requires a binary 2D image as input"); return; } ImageProcessor image = imagePlus.getProcessor(); if (image instanceof ColorProcessor) { IJ.showMessage("Invalid Input", "Requires a binary 2D image as input"); return; } // Process image long t0 = System.currentTimeMillis(); ImageProcessor result = Convexity.convexify(image); long elapsedTime = System.currentTimeMillis() - t0; // Copy input image meta-data result.setLut(image.getLut()); String newName = imagePlus.getShortTitle() + "-convex"; resultPlus = new ImagePlus(newName, result); resultPlus.copyScale(imagePlus); resultPlus.show(); // Show elapsed time IJUtils.showElapsedTime("Convexify", elapsedTime, imagePlus); }
Example 7
Source File: InteractiveGeodesicDistanceMap.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
/** * 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 ); }
Example 8
Source File: InteractiveGeodesicDistanceMap.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
/** * Computes the distance propagated from the boundary of the white * particles, within the white phase. * * @param mask * the binary mask image that will constrain the propagation * @param roi * the roi to define the marker image * @param weights * the set of chamfer weights for computing distances * @param normalize * specifies whether the resulting distance map should be * normalized * @return geodesic distance map image */ public ImageProcessor process( ImageProcessor mask, Roi roi, float[] weights, boolean normalize) { if( mask == null || imagePlus == null || baseImage == null) { IJ.showMessage( "Please run the plugin with an image open." ); return null; } if( weights == null ) { IJ.showMessage( "Weights not specified" ); return null; } if( roi == null ) { IJ.showMessage( "Please define the markers using for example " + "the point selection tool." ); return null; } // Create marker image from ROI ByteProcessor marker = new ByteProcessor( mask.getWidth(), mask.getHeight() ); marker.setColor( java.awt.Color.WHITE ); marker.draw( roi ); // Initialize calculator GeodesicDistanceTransform algo; if( weights.length == 2 ) algo = new GeodesicDistanceTransformFloat( weights, normalize ); else algo = new GeodesicDistanceTransformFloat5x5( weights, normalize ); DefaultAlgoListener.monitor( algo ); // Compute distance on specified images ImageProcessor result = algo.geodesicDistanceMap( marker, mask ); // setup display options double maxVal = result.getMax(); result.setLut( createFireLUT( maxVal ) ); // create result image return result; }
Example 9
Source File: InteractiveGeodesicDistanceMap.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 4 votes |
/** * Computes the distance propagated from the boundary of the white * particles, within the white phase. * * @param mask * the binary mask image that will constrain the propagation * @param roi * the roi to define the marker image * @param weights * the set of chamfer weights for computing distances * @param normalize * specifies whether the resulting distance map should be * normalized * @return geodesic distance map image */ public ImageProcessor process( ImageProcessor mask, Roi roi, short[] weights, boolean normalize) { if( mask == null || imagePlus == null || baseImage == null) { IJ.showMessage( "Please run the plugin with an image open." ); return null; } if( weights == null ) { IJ.showMessage( "Weights not specified" ); return null; } if( roi == null ) { IJ.showMessage( "Please define the markers using for example " + "the point selection tool." ); return null; } // Create marker image from ROI ByteProcessor marker = new ByteProcessor( mask.getWidth(), mask.getHeight() ); marker.setColor( java.awt.Color.WHITE ); marker.draw( roi ); // Initialize calculator GeodesicDistanceTransform algo; if( weights.length == 2 ) algo = new GeodesicDistanceTransformShort( weights, normalize ); else algo = new GeodesicDistanceTransformShort5x5( weights, normalize ); DefaultAlgoListener.monitor( algo ); // Compute distance on specified images ImageProcessor result = algo.geodesicDistanceMap( marker, mask ); // setup display options double maxVal = result.getMax(); result.setLut( createFireLUT( maxVal ) ); // create result image return result; }
Example 10
Source File: BinaryImages.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 3 votes |
/** * Returns a binary image that contains only the largest region. * * @param image * a binary image containing several individual regions * @return a new binary image containing only the largest region from * original image */ public static final ImageProcessor keepLargestRegion(ImageProcessor image) { ImageProcessor labelImage = componentsLabeling(image, 4, 16); ImageProcessor result = binarize(LabelImages.keepLargestLabel(labelImage)); result.setLut(image.getLut()); return result; }