/** * Refresh the output display with the current roi. This is done by sending a signal * to the Updater() thread. This method can be called from a script to force update * after the Roi has been changed with other means than the mouse */ public void update() { updater.doUpdate(); }
Updater() { super("Dynamic Reslice updater"); setPriority(Thread.NORM_PRIORITY); start(); }
@Override public void windowClosing(final WindowEvent e) { shutdown(); }
/** * return an {@link Image} of {@link UnsignedShortType} as input for the PhaseCorrelation. If no rectangular roi * is selected, it will only wrap the existing ImagePlus! * * @param imp - the {@link ImagePlus} * @param channel - which channel (if channel=0 means average all channels) * @param timepoint - which timepoint * * @return - the {@link Image} or null if it was not an ImagePlus.GRAY16 or if channel = 0 */ public static Image<UnsignedShortType> getWrappedImageUnsignedShort( final ImagePlus imp, final int channel, final int timepoint ) { if ( channel == 0 || imp.getType() != ImagePlus.GRAY16 ) return null; return ImageJFunctions.wrapShort( Hyperstack_rearranger.getImageChunk( imp, channel, timepoint ) ); }
/** * Main method, called when the plugin is launched from ImageJ menu. */ @Override public void run(final String arg) { if (imp == null) { IJ.noImage(); return; } final int stackSize = imp.getStackSize(); final Roi roi = imp.getRoi(); final int roiType = roi != null ? roi.getType() : 0; // stack required except for ROI = none or RECT if (stackSize < 2 && roi != null && roiType != Roi.RECTANGLE) { IJ.error("Dynamic Reslice...", "Stack required"); return; } // permissible ROI types: none,*LINE if (roi == null || (roiType != Roi.LINE && roiType != Roi.POLYLINE && roiType != Roi.FREELINE)) { IJ.error("Dynamic Reslice...", "Line selection required"); return; } // Show dialog (and quit if it was canceled). setup(); if (!showDialog()) return; start(); }
/** * Main method that actually dispatch the work. Update the destination * ImagePlus ({@link #dest_imp}) with the new content resulting from the * reslice. Also deal with calibration. */ protected void reslice() { ImageProcessor ip_out; final Roi roi = imp.getRoi(); final int roiType = roi != null ? roi.getType() : 0; /* * Save calibration */ final Calibration origCal = imp.getCalibration(); final double zSpacing = inputZSpacing / imp.getCalibration().pixelWidth; /* * Do reslice and update dest_imp */ ip_out = getSlice(imp, roi); dest_imp.setProcessor(null, ip_out); dealWithCalibration(); }
/** * Update the Dynamic reslice window. Called by the * Updater(), which lives in a separate thread. */ private void refresh() { // Only update if the roi is large enough, if ( imp.getRoi().getLength() < 2.0) return; // If not initialized, initialize if (!hasStarted) start(); // Re-calculate slice reslice(); }
/** * Converts this image to Hyperstack if it is RGB or 8-bit color * * @param imp - Inputimage * @return the output image, might be the same */ public static ImagePlus convertToHyperStack( ImagePlus imp ) { // first 8-bit color to RGB, directly to Hyperstack is not supported if ( imp.getType() == ImagePlus.COLOR_256 ) { if ( imp.getStackSize() > 1 ) new StackConverter( imp ).convertToRGB(); else new ImageConverter( imp ).convertToRGB(); } final Calibration cal = imp.getCalibration(); // now convert to hyperstack, this creates a new imageplus if ( imp.getType() == ImagePlus.COLOR_RGB ) { imp = new CompositeConverter2().makeComposite( imp ); imp.setCalibration( cal ); } return imp; } }
newImp = convertRGBToCompositeStack( imp ); else newImp = convertRGBToCompositeImage( imp );
void doUpdate() { if (isInterrupted()) return; synchronized (this) { request++; notify(); } }
/** * Create a new instance of this plugin, linked to the ImagePlus given in * argument. This ImagePlus will be used as the source for dynamic * reslicing. This constructor is meant to be called from a scripting * context, and take care of setting all properties according the ImagePlus * argument or defaults. * * @param _imp the source ImagePlus */ public Dynamic_Reslice(final ImagePlus _imp) { this.imp = _imp; setup(); }
void quit() { interrupt(); synchronized (this) { notify(); } }
return reorderHyperstack( imp, 0, 1, 2, closeOldImp, showNewImp ); else if ( newOrder.equalsIgnoreCase( "CTZ" ) ) return reorderHyperstack( imp, 0, 2, 1, closeOldImp, showNewImp ); else if ( newOrder.equalsIgnoreCase( "ZCT" ) ) return reorderHyperstack( imp, 1, 0, 2, closeOldImp, showNewImp ); else if ( newOrder.equalsIgnoreCase( "ZTC" ) ) return reorderHyperstack( imp, 1, 2, 0, closeOldImp, showNewImp ); else if ( newOrder.equalsIgnoreCase( "TCZ" ) ) return reorderHyperstack( imp, 2, 0, 1, closeOldImp, showNewImp ); else if ( newOrder.equalsIgnoreCase( "TZC" ) ) return reorderHyperstack( imp, 2, 1, 0, closeOldImp, showNewImp ); else
public ImagePlus radreslice(ImagePlus imp) { ImagePlus imp2; Roi roi = imp.getRoi(); int roiType = roi!=null?roi.getType():0; Calibration origCal = imp.getCalibration(); imp2 = radslice(imp); imp2.setCalibration(imp.getCalibration()); Calibration cal = imp2.getCalibration(); cal.pixelDepth = origCal.pixelHeight; return imp2; }
/** * Shut down the Dynamic reslice, that is, remove itself from the listener * list. */ public void shutdown() { updater.quit(); updater = null; imp.getCanvas().removeMouseMotionListener(this); imp.getWindow().removeWindowListener(this); dest_imp.getWindow().removeWindowListener(this); IJ.showStatus("Dynamic Reslice shut down."); }
/** * return an {@link Image} of {@link FloatType} as input for the PhaseCorrelation. If no rectangular roi * is selected, it will only wrap the existing ImagePlus! * * @param imp - the {@link ImagePlus} * @param channel - which channel (if channel=0 means average all channels) * @param timepoint - which timepoint * * @return - the {@link Image} or null if it was not an ImagePlus.GRAY32 or if channel = 0 */ public static Image<FloatType> getWrappedImageFloat( final ImagePlus imp, final int channel, final int timepoint ) { if ( channel == 0 || imp.getType() != ImagePlus.GRAY32 ) return null; return ImageJFunctions.wrapFloat( Hyperstack_rearranger.getImageChunk( imp, channel, timepoint ) ); }
/** * Method to start the dynamic reslice process after all parameters * have been set. Will not initiate as long as there is no ROI. */ public void start() { if (hasStarted || imp.getRoi() == null) return; // Get type of source window rgb = imp.getType() == ImagePlus.COLOR_RGB; notFloat = !rgb && imp.getType() != ImagePlus.GRAY32; // Create the destination ImagePlus dest_imp by get a slice a first time. dest_imp = new ImagePlus("Dynamic Reslice of "+imp.getShortTitle(), getSlice(imp, imp.getRoi())); dealWithCalibration(); // Copy min & max to new result final ImageProcessor ip = imp.getProcessor(); final double min = ip.getMin(); final double max = ip.getMax(); if (!rgb) dest_imp.getProcessor().setMinAndMax(min, max); // Display window result dest_imp.show(); // Add listeners imp.getCanvas().addMouseMotionListener(this); imp.getWindow().addWindowListener(this); dest_imp.getWindow().addWindowListener(this); // Set the started flag to true hasStarted = true; }
@Override public void mouseDragged(final MouseEvent e) { e.consume(); updater.doUpdate(); }
@Override public void run() { while (!isInterrupted()) { try { final long r; synchronized (this) { r = request; } // Call update from this thread if (r > 0) refresh(); synchronized (this) { if (r == request) { request = 0; // reset wait(); } // else loop through to update again } } catch (final Exception e) { } } } }
/** * return an {@link Image} of {@link UnsignedByteType} as input for the PhaseCorrelation. If no rectangular roi * is selected, it will only wrap the existing ImagePlus! * * @param imp - the {@link ImagePlus} * @param channel - which channel (if channel=0 means average all channels) * @param timepoint - which timepoint * * @return - the {@link Image} or null if it was not an ImagePlus.GRAY8 or if channel = 0 */ public static Image<UnsignedByteType> getWrappedImageUnsignedByte( final ImagePlus imp, final int channel, final int timepoint ) { if ( channel == 0 || imp.getType() != ImagePlus.GRAY8 ) return null; return ImageJFunctions.wrapByte( Hyperstack_rearranger.getImageChunk( imp, channel, timepoint ) ); }