/** * Get the Dice coefficient between two label images. * @param labelImage1 first label image * @param labelImage2 second label image * @return Dice coefficient value or -1 if error * @see <a href="https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient">https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient</a> */ public static final double getDiceCoefficient( ImagePlus labelImage1, ImagePlus labelImage2 ) { return getDiceCoefficient( labelImage1.getImageStack(), labelImage2.getImageStack() ); } /**
/** * Add Hessian features from original image (single thread version). * The features include a scalar representing the Hessian, the trace, determinant, * 1st eigenvalue, 2nd eigenvalue, orientation, gamma-normalized square eigenvalue difference * and the square of Gamma-normalized eigenvalue difference * * @param sigma radius of the Gaussian filter to use */ public void addHessian(float sigma) { ImagePlus merged = calculateHessian(originalImage, sigma); for(int i=1; i<=merged.getImageStackSize(); i++) wholeStack.addSlice(merged.getImageStack().getSliceLabel(i), merged.getImageStack().getPixels(i)); }
/** * Add Hessian features from original image (single thread version). * The features include a scalar representing the Hessian, the trace, determinant, * 1st eigenvalue, 2nd eigenvalue, orientation, gamma-normalized square eigenvalue difference * and the square of Gamma-normalized eigenvalue difference * * @param sigma radius of the Gaussian filter to use */ public void addHessian(float sigma) { ImagePlus merged = calculateHessian(originalImage, sigma); for(int i=1; i<=merged.getImageStackSize(); i++) wholeStack.addSlice(merged.getImageStack().getSliceLabel(i), merged.getImageStack().getPixels(i)); }
/** * Get the total overlap between two label images (source and target). * <p> * Total Overlap (for all regions) $TO = \frac{ \sum_r{|S_r \cap T_r|} }{ \sum_r{|T_r|} }$. * @param sourceImage source label image * @param targetImage target label image * @return total overlap value or -1 if error * @see <a href="http://www.insight-journal.org/browse/publication/707">http://www.insight-journal.org/browse/publication/707</a> */ public static final double getTotalOverlap( ImagePlus sourceImage, ImagePlus targetImage ) { return getTotalOverlap( sourceImage.getImageStack(), targetImage.getImageStack() ); }
/** * Add HSB features */ public void addHSB() { final ImagePlus hsb = originalImage.duplicate(); ImageConverter ic = new ImageConverter( hsb ); ic.convertToHSB(); for(int n=1; n<=hsb.getImageStackSize(); n++) wholeStack.addSlice(hsb.getImageStack().getSliceLabel(n), hsb.getImageStack().getProcessor(n).convertToRGB()); }
/** * Get the Jaccard index (intersection over union overlap) between * two label images. * @param labelImage1 first label image * @param labelImage2 second label image * @return Jaccard index value or -1 if error * @see <a href="https://en.wikipedia.org/wiki/Jaccard_index">https://en.wikipedia.org/wiki/Jaccard_index</a> */ public static final double getJaccardIndex( ImagePlus labelImage1, ImagePlus labelImage2 ) { return getJaccardIndex( labelImage1.getImageStack(), labelImage2.getImageStack() ); } /**
/** * Add HSB features */ public void addHSB() { final ImagePlus hsb = originalImage.duplicate(); ImageConverter ic = new ImageConverter( hsb ); ic.convertToHSB(); for(int n=1; n<=hsb.getImageStackSize(); n++) wholeStack.addSlice(hsb.getImageStack().getSliceLabel(n), hsb.getImageStack().getProcessor(n).convertToRGB()); }
/** * Get the Jaccard index per label (intersection over union overlap) between * two label images. * @param labelImage1 reference label image * @param labelImage2 label image to compare with * @return Jaccard index per label in the reference image or null if error * @see <a href="https://en.wikipedia.org/wiki/Jaccard_index">https://en.wikipedia.org/wiki/Jaccard_index</a> */ public static final ResultsTable getJaccardIndexPerLabel( ImagePlus labelImage1, ImagePlus labelImage2 ) { return getJaccardIndexPerLabel( labelImage1.getImageStack(), labelImage2.getImageStack() ); } /**
public ImagePlus call(){ final ImagePlus hsb = originalImage.duplicate(); ImageConverter ic = new ImageConverter( hsb ); ic.convertToHSB(); ImageStack is = new ImageStack(originalImage.getWidth(), originalImage.getHeight()); for(int n=1; n<=hsb.getImageStackSize(); n++) is.addSlice(hsb.getImageStack().getSliceLabel(n), hsb.getImageStack().getProcessor(n).convertToRGB()); return new ImagePlus ("HSB", is); } };
/** * Get the Dice coefficient per label (intersection over union overlap) between * two label images. * @param labelImage1 reference label image * @param labelImage2 label image to compare with * @return Dice coefficient per label in the reference image or null if error * @see <a href="https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient">https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient</a> */ public static final ResultsTable getDiceCoefficientPerLabel( ImagePlus labelImage1, ImagePlus labelImage2 ) { return getDiceCoefficientPerLabel( labelImage1.getImageStack(), labelImage2.getImageStack() ); } /**
public ImagePlus call(){ final ImagePlus hsb = originalImage.duplicate(); ImageConverter ic = new ImageConverter( hsb ); ic.convertToHSB(); ImageStack is = new ImageStack(originalImage.getWidth(), originalImage.getHeight()); for(int n=1; n<=hsb.getImageStackSize(); n++) is.addSlice(hsb.getImageStack().getSliceLabel(n), hsb.getImageStack().getProcessor(n).convertToRGB()); return new ImagePlus ("HSB", is); } };
/** * Find minimum and maximum value of input image * * @param image input 2d/3d image * @return array of 2 extreme values */ public static final double[] findMinAndMax( ImagePlus image ) { return findMinAndMax( image.getImageStack() ); } /**
/** * bag class for getting the result of the loaded classifier */ private static class LoadedClassifier { private AbstractClassifier newClassifier = null; private Instances newHeader = null; }
private ImageProcessor getFirstSliceIP(final String filename) { final ImagePlus imp = IJ.openImage(filename); final ImageStack is = imp.getImageStack(); final ImageProcessor ip = is.getProcessor(1); return ip == null ? imp.getProcessor() : ip; }
/** * bag class for getting the result of the loaded classifier */ private static class LoadedClassifier { private AbstractClassifier newClassifier = null; private Instances newHeader = null; }
/** * Reset labels to original form */ void resetLabels() { displayImage.setStack( inputImage.getImageStack().duplicate() ); displayImage.updateAndDraw(); }
/** Creates a wrapper {@code Image} of the given {@code ImagePlus} object. This is done by checking the element type and calling the wrapper constructor of the corresponding {@code Image} subclass. @param imageplus The {@code ImagePlus} object whose image data is to be wrapped. @return A wrapper {@code Image} object of the given {@code ImagePlus} object. The two objects share the actual image data. @throws IllegalArgumentException If the elements of {@code imageplus} are of a non-supported type. @throws NullPointerException If {@code imageplus} is {@code null}. */ public static Image wrap(final ImagePlus imageplus) { final Object[] slices = imageplus.getImageStack().getImageArray(); if (slices[0] instanceof byte[]) return new ByteImage(imageplus); if (slices[0] instanceof short[]) return new ShortImage(imageplus); if (slices[0] instanceof float[]) return new FloatImage(imageplus); if (slices[0] instanceof int[]) return new ColorImage(imageplus); throw new IllegalArgumentException("Non-supported data type"); }
/** * Update the overlay */ void updateResultOverlay() { if( null != clusteredImage ) { int slice = image.getCurrentSlice(); ImageRoi roi = null; roi = new ImageRoi(0, 0, clusteredImage.getImageStack().getProcessor(slice)); roi.setOpacity((double) opacitySlider.getValue()/100); image.setOverlay(new Overlay(roi)); } }
/** * Update the result image overlay with the corresponding slice */ public void updateResultOverlay() { ImageProcessor overlay = classifiedImage.getImageStack().getProcessor(displayImage.getCurrentSlice()).duplicate(); //IJ.log("updating overlay with result from slice " + displayImage.getCurrentSlice()); overlay = overlay.convertToByte(false); overlay.setColorModel(overlayLUT); win.resultOverlay.setImage(overlay); }
/** * Update the result image overlay with the corresponding slice */ public void updateResultOverlay() { ImageProcessor overlay = classifiedImage.getImageStack().getProcessor(displayImage.getCurrentSlice()).duplicate(); //IJ.log("updating overlay with result from slice " + displayImage.getCurrentSlice()); overlay = overlay.convertToByte(false); overlay.setColorModel(overlayLUT); win.resultOverlay.setImage(overlay); }