/** * Get slice label * @param index slice index (from 1 to max size) * @return slice label */ public String getSliceLabel(int index){ return wholeStack.getSliceLabel(index); } /**
/** Returns true if this is a 3-slice, 8-bit RGB stack. */ public boolean isRGB() { return nSlices==3 && (stack[0] instanceof byte[]) && getSliceLabel(1)!=null && getSliceLabel(1).equals("Red"); }
/** Returns true if this is a Lab stack. */ public boolean isLab() { return nSlices==3 && getSliceLabel(1)!=null && getSliceLabel(1).equals("L*"); }
public void deleteSlice(int index) { File f = new File(dir + "/" + preview.getSliceLabel(index)); f.delete(); preview.deleteSlice(index); }
private synchronized void setStackNull() { if (oneSliceStack && stack!=null && stack.size()>0) { String label = stack.getSliceLabel(1); setProperty("Label", label); } stack = null; oneSliceStack = false; }
private synchronized void setStackNull() { if (oneSliceStack && stack!=null && stack.size()>0) { String label = stack.getSliceLabel(1); setProperty("Label", label); } stack = null; oneSliceStack = false; }
public ImageProcessor getProcessor(int index) { return IJ.openImage(dir + "/" + preview.getSliceLabel(index)). getProcessor(); }
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; }
/** Creates a new stack by cropping this one. */ public ImageStack crop(int x, int y, int z, int width, int height, int depth) { if (x<0||y<0||z<0||x+width>this.width||y+height>this.height||z+depth>getSize()) throw new IllegalArgumentException("Argument out of range"); ImageStack stack2 = new ImageStack(width, height, getColorModel()); for (int i=z; i<z+depth; i++) { ImageProcessor ip2 = this.getProcessor(i+1); ip2.setRoi(x, y, width, height); ip2 = ip2.crop(); stack2.addSlice(this.getSliceLabel(i+1), ip2); } return stack2; }
public void openFrame() { int index = preview.getCurrentSlice(); ImageProcessor ip = stack.getProcessor(index); new ImagePlus(stack.getPreview(). getSliceLabel(index), ip).show(); }
public void writeImage(ImagePlus imp, String path, int transparentIndex) throws Exception { if (imp.getStackSize()==4 && imp.getBitDepth()==8 && "alpha".equalsIgnoreCase(imp.getStack().getSliceLabel(4))) writeFourChannelsWithAlpha(imp, path); else if (transparentIndex>=0 && transparentIndex<=255 && imp.getBitDepth()==8) writeImageWithTransparency(imp, path, transparentIndex); else if (imp.getOverlay()!=null && !imp.getHideOverlay()) ImageIO.write(imp.flatten().getBufferedImage(), "png", new File(path)); else if (imp.getBitDepth()==16 && !imp.isComposite() && imp.getProcessor().isDefaultLut()) write16gs(imp, path); else ImageIO.write(imp.getBufferedImage(), "png", new File(path)); }
public void writeImage(ImagePlus imp, String path, int transparentIndex) throws Exception { if (imp.getStackSize()==4 && imp.getBitDepth()==8 && "alpha".equalsIgnoreCase(imp.getStack().getSliceLabel(4))) writeFourChannelsWithAlpha(imp, path); else if (transparentIndex>=0 && transparentIndex<=255 && imp.getBitDepth()==8) writeImageWithTransparency(imp, path, transparentIndex); else if (imp.getOverlay()!=null && !imp.getHideOverlay()) ImageIO.write(imp.flatten().getBufferedImage(), "png", new File(path)); else if (imp.getBitDepth()==16 && !imp.isComposite() && imp.getProcessor().isDefaultLut()) write16gs(imp, path); else ImageIO.write(imp.getBufferedImage(), "png", new File(path)); }
void first(){ if(slice!=1){ stack.addSlice(stack.getSliceLabel(slice), stack.getProcessor(slice),0); stack.deleteSlice(slice+1); imp.setStack(null,stack); imp.setSlice(1); imp.updateAndDraw(); } } void bkwd(){
void last(){ if(slice!=numSlices){ stack.addSlice(stack.getSliceLabel(slice), stack.getProcessor(slice),numSlices); stack.deleteSlice(slice); imp.setStack(null,stack); imp.setSlice(numSlices); imp.updateAndDraw(); } } void dup(){
/** Creates a float version of this stack. */ public ImageStack convertToFloat() { ImageStack stack2 = new ImageStack(width, height, getColorModel()); for (int i=1; i<=getSize(); i++) { ImageProcessor ip2 = this.getProcessor(i); ip2 = ip2.convertToFloat(); stack2.addSlice(this.getSliceLabel(i), ip2); } return stack2; }
public void setSlice(int index, ImageProcessor ip) { String name = preview.getSliceLabel(index); ImagePlus imp = new ImagePlus(name, ip); new FileSaver(imp).saveAsPng(dir + "/" + name); ip = ip.resize(w_prev).convertToByte(true); preview.setPixels(ip.getPixels(), index); }
public void setFrame() { int index = preview.getCurrentSlice(); if(!IJ.getImage().getTitle().equals( stack.getPreview().getSliceLabel(index))) return; ImageProcessor ip = IJ.getImage().getProcessor(); stack.setSlice(index, ip); IJ.getImage().changes = false; IJ.getImage().close(); preview.setStack(null, stack.getPreview()); preview.setSlice(index); }
/** * 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()); }
/** * 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()); }
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); } };