public int setup(String arg, ImagePlus imp) { if (imp!=null) { virtualStack = imp.getStack().isVirtual(); if (virtualStack) useOverlay = true; baseOverlay = imp.getOverlay(); flags += virtualStack?0:DOES_STACKS; firstFrame=1; lastFrame=defaultLastFrame=imp.getStackSize(); } this.imp = imp; return flags; }
public String toString() { String v = isVirtual()?"(V)":""; return ("stack["+getWidth()+"x"+getHeight()+"x"+getSize()+v+"]"); }
public String toString() { String v = isVirtual()?"(V)":""; return ("stack["+getWidth()+"x"+getHeight()+"x"+getSize()+v+"]"); }
public int setup(String arg, ImagePlus imp) { if (imp!=null) { virtualStack = imp.getStack().isVirtual(); if (virtualStack) useOverlay = true; baseOverlay = imp.getOverlay(); flags += virtualStack?0:DOES_STACKS; firstFrame=1; lastFrame=defaultLastFrame=imp.getStackSize(); } this.imp = imp; return flags; }
/** Calculates the voxel depth of the specified DICOM stack based on the distance between the first and last slices. */ public static double getVoxelDepth(ImageStack stack) { if (stack.isVirtual()) stack.getProcessor(1); String pos0 = getTag(stack.getSliceLabel(1), "0020,0032"); String posn = null; double voxelDepth = -1.0; if (pos0!=null) { String[] xyz = pos0.split("\\\\"); if (xyz.length!=3) return voxelDepth; double z0 = Double.parseDouble(xyz[2]); if (stack.isVirtual()) stack.getProcessor(stack.getSize()); posn = getTag(stack.getSliceLabel(stack.getSize()), "0020,0032"); if (posn==null) return voxelDepth; xyz = posn.split("\\\\"); if (xyz.length!=3) return voxelDepth; double zn = Double.parseDouble(xyz[2]); voxelDepth = Math.abs((zn - z0) / (stack.getSize() - 1)); } if (IJ.debugMode) IJ.log("DicomTools.getVoxelDepth: "+voxelDepth+" "+pos0+" "+posn); return voxelDepth; }
private static String getSliceLabel(ImageStack stack, int n) { String info = stack.getSliceLabel(n); if ((info==null || info.length()<100) && stack.isVirtual()) { String dir = ((VirtualStack)stack).getDirectory(); String name = ((VirtualStack)stack).getFileName(n); DICOM reader = new DICOM(); info = reader.getInfo(dir+name); if (info!=null) info = name + "\n" + info; } return info; }
private static String getSliceLabel(ImageStack stack, int n) { String info = stack.getSliceLabel(n); if ((info==null || info.length()<100) && stack.isVirtual()) { String dir = ((VirtualStack)stack).getDirectory(); String name = ((VirtualStack)stack).getFileName(n); DICOM reader = new DICOM(); info = reader.getInfo(dir+name); if (info!=null) info = name + "\n" + info; } return info; }
/** * Assigns a pixel array to the current position, * * @param pixels */ public void setPixels(final Object pixels) { if (isInitialized && pixels != null) { if (imageStack.isVirtual()) return; if (!pixels.getClass().equals( imageStack.getPixels(getCurrentImageStackIndex()).getClass())) return; if (width * height != Array.getLength(pixels)) { throw (new IllegalArgumentException( "Array size does not match image dimensions.")); } imageStack.setPixels(pixels, getCurrentImageStackIndex()); channelIPs[currentPosition[2]].setPixels(pixels); super.getStack().setPixels(pixels, getCurrentPosition(3) + 1); } }
/** Sets the image name. */ public void setTitle(String title) { if (title==null) return; if (win!=null) { if (ij!=null) Menus.updateWindowMenuItem(this, this.title, title); String virtual = stack!=null && stack.isVirtual()?" (V)":""; String global = getGlobalCalibration()!=null?" (G)":""; String scale = ""; double magnification = win.getCanvas().getMagnification(); if (magnification!=1.0) { double percent = magnification*100.0; int digits = percent>100.0||percent==(int)percent?0:1; scale = " (" + IJ.d2s(percent,digits) + "%)"; } win.setTitle(title+virtual+global+scale); } boolean titleChanged = !title.equals(this.title); this.title = title; if (titleChanged && listeners.size()>0) notifyListeners(UPDATED); }
/** Sorts a DICOM stack by image number. */ public static ImageStack sort(ImageStack stack) { if (IJ.debugMode) IJ.log("Sorting by DICOM image number"); if (stack.getSize()==1) return stack; String[] strings = getSortStrings(stack, "0020,0013"); if (strings==null) return stack; StringSorter.sort(strings); ImageStack stack2 = null; if (stack.isVirtual()) stack2 = ((VirtualStack)stack).sortDicom(strings, sliceLabels, MAX_DIGITS); else stack2 = sortStack(stack, strings); return stack2!=null?stack2:stack; }
/** Sorts a DICOM stack by image number. */ public static ImageStack sort(ImageStack stack) { if (IJ.debugMode) IJ.log("Sorting by DICOM image number"); if (stack.getSize()==1) return stack; String[] strings = getSortStrings(stack, "0020,0013"); if (strings==null) return stack; StringSorter.sort(strings); ImageStack stack2 = null; if (stack.isVirtual()) stack2 = ((VirtualStack)stack).sortDicom(strings, sliceLabels, MAX_DIGITS); else stack2 = sortStack(stack, strings); return stack2!=null?stack2:stack; }
/** Asks for the compression type and filename; then saves as AVI file */ public void run(ImageProcessor ip) { if (!showDialog(imp)) return; //compression type dialog SaveDialog sd = new SaveDialog("Save as AVI...", imp.getTitle(), ".avi"); String fileName = sd.getFileName(); if (fileName == null) return; String fileDir = sd.getDirectory(); FileInfo fi = imp.getOriginalFileInfo(); if (fi!=null && imp.getStack().isVirtual() && fileDir.equals(fi.directory) && fileName.equals(fi.fileName)) { IJ.error("AVI Writer", "Virtual stacks cannot be saved in place."); return; } try { writeImage(imp, fileDir + fileName, COMPRESSION_TYPES[compressionIndex], jpegQuality); IJ.showStatus(""); } catch (IOException e) { IJ.error("AVI Writer", "An error occured writing the file.\n \n" + e); } IJ.showStatus(""); }
/** Updates this image from the pixel data in its associated ImageProcessor, then displays it. Does nothing if there is no window associated with this image (i.e. show() has not been called).*/ public synchronized void updateAndDraw() { if (stack!=null && !stack.isVirtual() && currentSlice>=1 && currentSlice<=stack.getSize()) { Object pixels = stack.getPixels(currentSlice); if (ip!=null && pixels!=null && pixels!=ip.getPixels()) { // was stack updated? try { ip.setPixels(pixels); ip.setSnapshotPixels(null); } catch(Exception e) {} } } if (win!=null) { win.getCanvas().setImageUpdated(); if (listeners.size()>0) notifyListeners(UPDATED); } draw(); }
/** Updates this image from the pixel data in its associated ImageProcessor, then displays it. Does nothing if there is no window associated with this image (i.e. show() has not been called).*/ public synchronized void updateAndDraw() { if (stack!=null && !stack.isVirtual() && currentSlice>=1 && currentSlice<=stack.getSize()) { Object pixels = stack.getPixels(currentSlice); if (ip!=null && pixels!=null && pixels!=ip.getPixels()) { // was stack updated? try { ip.setPixels(pixels); ip.setSnapshotPixels(null); } catch(Exception e) {} } } if (win!=null) { win.getCanvas().setImageUpdated(); if (listeners.size()>0) notifyListeners(UPDATED); } draw(); }
public static ImagePlusImgLoader< UnsignedShortType > createGray32( final ImagePlus imp, final MinMaxOption minMaxOption, final double min, final double max ) { if( imp.getType() != ImagePlus.GRAY32 ) throw new RuntimeException( "expected ImagePlus type GRAY32" ); if ( imp.getStack() != null && imp.getStack().isVirtual() ) return new ImagePlusImgLoader<>( imp, VirtualStackImageLoader.createFloatInstance( imp ), minMaxOption, min, max, new UnsignedShortType(), new RealUnsignedShortConverterFactory() ); else return new ImagePlusImgLoader<>( imp, ImageStackImageLoader.createFloatInstance( imp ), minMaxOption, min, max, new UnsignedShortType(), new RealUnsignedShortConverterFactory() ); }
public static ImagePlusImgLoader< UnsignedShortType > createGray16( final ImagePlus imp, final MinMaxOption minMaxOption, final double min, final double max ) { if( imp.getType() != ImagePlus.GRAY16 ) throw new RuntimeException( "expected ImagePlus type GRAY16" ); if ( imp.getStack() != null && imp.getStack().isVirtual() ) return new ImagePlusImgLoader<>( imp, VirtualStackImageLoader.createUnsignedShortInstance( imp ), minMaxOption, min, max, new UnsignedShortType(), new RealUnsignedShortConverterFactory() ); else return new ImagePlusImgLoader<>( imp, ImageStackImageLoader.createUnsignedShortInstance( imp ), minMaxOption, min, max, new UnsignedShortType(), new RealUnsignedShortConverterFactory() ); }
public static ImagePlusImgLoader< UnsignedShortType > createGray8( final ImagePlus imp, final MinMaxOption minMaxOption, final double min, final double max ) { if( imp.getType() != ImagePlus.GRAY8 ) throw new RuntimeException( "expected ImagePlus type GRAY8" ); if ( imp.getStack() != null && imp.getStack().isVirtual() ) return new ImagePlusImgLoader<>( imp, VirtualStackImageLoader.createUnsignedByteInstance( imp ), minMaxOption, min, max, new UnsignedShortType(), new RealUnsignedShortConverterFactory() ); else return new ImagePlusImgLoader<>( imp, ImageStackImageLoader.createUnsignedByteInstance( imp ), minMaxOption, min, max, new UnsignedShortType(), new RealUnsignedShortConverterFactory() ); }
public static ImagePlusImgLoader< FloatType > createFloatFromGray8( final ImagePlus imp, final MinMaxOption minMaxOption, final double min, final double max ) { if( imp.getType() != ImagePlus.GRAY8 ) throw new RuntimeException( "expected ImagePlus type GRAY8" ); if ( imp.getStack() != null && imp.getStack().isVirtual() ) return new ImagePlusImgLoader<>( imp, VirtualStackImageLoader.createUnsignedByteInstance( imp ), minMaxOption, min, max, new FloatType(), new RealFloatConverterFactory() ); else return new ImagePlusImgLoader<>( imp, ImageStackImageLoader.createUnsignedByteInstance( imp ), minMaxOption, min, max, new FloatType(), new RealFloatConverterFactory() ); }
public void reduceStack(ImagePlus imp, int factor) { ImageStack stack = imp.getStack(); boolean virtual = stack.isVirtual(); int n = stack.getSize(); ImageStack stack2 = new ImageStack(stack.getWidth(), stack.getHeight()); for (int i=1; i<=n; i+=factor) { if (virtual) IJ.showProgress(i, n); stack2.addSlice(stack.getSliceLabel(i), stack.getProcessor(i)); } imp.setStack(null, stack2); if (virtual) { IJ.showProgress(1.0); imp.setTitle(imp.getTitle()); } Calibration cal = imp.getCalibration(); if (cal.scaled()) cal.pixelDepth *= factor; }
public void reduceStack(ImagePlus imp, int factor) { ImageStack stack = imp.getStack(); boolean virtual = stack.isVirtual(); int n = stack.getSize(); ImageStack stack2 = new ImageStack(stack.getWidth(), stack.getHeight()); for (int i=1; i<=n; i+=factor) { if (virtual) IJ.showProgress(i, n); stack2.addSlice(stack.getSliceLabel(i), stack.getProcessor(i)); } imp.setStack(null, stack2); if (virtual) { IJ.showProgress(1.0); imp.setTitle(imp.getTitle()); } Calibration cal = imp.getCalibration(); if (cal.scaled()) cal.pixelDepth *= factor; }