import ij.ImagePlus; import ij.io.FileSaver; import ij.process.ImageProcessor; ImagePlus imgPlus = new ImagePlus("path-to-sample.jpg"); ImageProcessor imgProcessor = imgPlus.getProcessor(); imgProcessor.invert(); FileSaver fs = new FileSaver(imgPlus); fs.saveAsJpeg("path-to-inverted.jpg");
public ImagePlus[] getDisplacementField( ) { ImagePlus[] results = new ImagePlus[3]; ImageStack[] stack = new ImageStack[3]; for (int i = 0; i < 3; i++) stack[i] = new ImageStack(template.w, template.h); for (int k = 0; k < template.d; k++) { float[][] slice = new float[3][]; for (int i = 0; i < 3; i++) slice[i] = new float[template.w * template.h]; for (int j = 0; j < template.w * template.h; j++) //if (getLabel(j % w, j / w, k) != 0) for (int i = 0; i < 3; i++) slice[i][j] = displace[k][3 * j + i]; for (int i = 0; i < 3; i++) stack[i].addSlice("", slice[i]); } for (int i = 0; i < 3; i++) results[i] = new ImagePlus("displace "+i, stack[i]); return results; }
private ImagePlus computeStructure(final ImagePlus imp, final double sigma, final double integrationScale) { // Get channel(s) to process ImagePlus[] channels = extractChannels(imp); ImagePlus[] results = new ImagePlus[ channels.length ]; for(int ch=0; ch < channels.length; ch++) { final ArrayList<ImagePlus> eigenimages = ImageScience.computeEigenimages(sigma, integrationScale, channels[ch]); final ImageStack is = new ImageStack(width, height); is.addSlice(availableFeatures[STRUCTURE] +"_largest_" + sigma + "_" + integrationScale, eigenimages.get(0).getProcessor() ); is.addSlice(availableFeatures[STRUCTURE] +"_smallest_" + sigma + "_" + integrationScale, eigenimages.get(1).getProcessor() ); results[ ch ] = new ImagePlus ("Structure stack", is); } return mergeResultChannels(results); }
private void writeFourChannelsWithAlpha(ImagePlus imp, String path) throws Exception { ImageStack stack = imp.getStack(); int w=imp.getWidth(), h=imp.getHeight(); ImagePlus imp2 = new ImagePlus("", new ColorProcessor(w,h)); ColorProcessor cp = (ColorProcessor)imp2.getProcessor(); for (int channel=1; channel<=4; channel++) cp.setChannel(channel, (ByteProcessor)stack.getProcessor(channel)); BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); WritableRaster raster = bi.getRaster(); raster.setDataElements(0, 0, w, h, cp.getPixels()); ImageIO.write(bi, "png", new File(path)); }
/** * Display the whole image after classification */ void showClassificationImage(){ ImagePlus resultImage = new ImagePlus("classification result", classifiedImage.getProcessor().convertToByte(true).duplicate()); resultImage.show(); }
private void show(int n) { ImageStack stack = new ImageStack(w, h); for(int z = 0; z < d; z++) { stack.addSlice("", new FloatProcessor( w, h, u[n][z], null)); } new ImagePlus("Displacement_dim" + n, stack).show(); }
static void showCorrelations(CrossCorrelationDriftResults driftCorrection) { ImagePlus imp = new ImagePlus("Cross correlations", driftCorrection.getCorrelationImages()); //add center markers double[] binDriftsX = driftCorrection.getDriftDataX(); double[] binDriftsY = driftCorrection.getDriftDataY(); for(int i = 1; i < binDriftsX.length; i++) { RenderingOverlay.showPointsInImage(imp, new double[]{-binDriftsX[i] / driftCorrection.getScaleFactor() + imp.getWidth() / 2 + 0.5}, new double[]{-binDriftsY[i] / driftCorrection.getScaleFactor() + imp.getHeight() / 2 + 0.5}, i, Color.red, RenderingOverlay.MARKER_CROSS); } imp.show(); }
public ImagePlus compute(ImageStack stack) { w = stack.getWidth(); h = stack.getHeight(); d = stack.getSize(); ImageStack result = new ImageStack(w, h, d); for (int i = 1; i <= d; i++) result.setPixels(new float[w * h], i); current = 0; total = w * h * d * 3; new Z(stack, result).compute(); new Y(result).compute(); new X(result).compute(); return new ImagePlus("EDT", result); }
private ImagePlus computeStructure(final ImagePlus imp, final double sigma, final double integrationScale) { // Get channel(s) to process ImagePlus[] channels = extractChannels(imp); ImagePlus[] results = new ImagePlus[ channels.length ]; for(int ch=0; ch < channels.length; ch++) { final ArrayList<ImagePlus> eigenimages = ImageScience.computeEigenimages(sigma, integrationScale, channels[ch]); final ImageStack is = new ImageStack(width, height); is.addSlice(availableFeatures[STRUCTURE] +"_largest_" + sigma + "_" + integrationScale, eigenimages.get(0).getProcessor() ); is.addSlice(availableFeatures[STRUCTURE] +"_smallest_" + sigma + "_" + integrationScale, eigenimages.get(1).getProcessor() ); results[ ch ] = new ImagePlus ("Structure stack", is); } return mergeResultChannels(results); }
File inputFile = new File("someImage.png"); Image someImage = null; try { someImage = ImageIO.read(inputFile); } catch (IOException e) { e.printStackTrace(); } ImagePlus imagePlus = new ImagePlus(); imagePlus.setImage(someImage); ColorProcessor processor = (ColorProcessor) imagePlus.getProcessor();
/** * Read mask from file. * An error is shown if the file read is not of the same size as the * previous mask. * * @param filename name of the mask file */ public void readFile(String filename) { ImagePlus aux = new ImagePlus(filename); if (aux.getWidth()!=width || aux.getHeight()!=height) IJ.error("Mask in file is not of the expected size"); ImageProcessor ip = aux.getProcessor(); int k=0; for (int y = 0; (y < height); y++) for (int x = 0; (x < width); x++, k++) if (ip.getPixelValue(x,y)!=0) mask[k]=true; else mask[k]=false; }
public ImagePlus toFloat() { ImageStack stack = new ImageStack(w, h); for(int z = 0; z < d; z++) { stack.addSlice("",new FloatProcessor(w,h,dist[z],null)); } return new ImagePlus("Distance", stack); }
/** * Display the whole image after classification */ void showClassificationImage(){ ImagePlus resultImage = new ImagePlus("classification result", classifiedImage.getProcessor().convertToByte(true).duplicate()); resultImage.show(); }
public void show() { ImageStack rest = new ImageStack(w, h); ImageStack imst = new ImageStack(w, h); for(int z = 0; z < d; z++) { rest.addSlice("", new FloatProcessor(w, h, re[z], null)); imst.addSlice("", new FloatProcessor(w, h, im[z], null)); } new ImagePlus("re", rest).show(); new ImagePlus("im", imst).show(); // for(int i = 0; i < re.length; i++) { // System.out.print(df.format(re[i]) + " "); // System.out.print(df.format(im[i]) + " "); // } // System.out.println(); } }
public void openRoi(String dir, String name) throws IOException { String path = dir+name; RoiDecoder rd = new RoiDecoder(path); Roi roi = rd.getRoi(); Rectangle r = roi.getBounds(); ImagePlus img = WindowManager.getCurrentImage(); if (img==null || img.getWidth()<(r.x+r.width) || img.getHeight()<(r.y+r.height)) { ImageProcessor ip = new ByteProcessor(r.x+r.width+10, r.y+r.height+10); img = new ImagePlus(name, ip); img.show(); } img.setRoi(roi); }
/** * Get the image with the classified mismatches * * @param wr warping results * @param mismatchesLabels labels of the warping mismatches * @return image with classified mismatches */ public ImagePlus getMismatchImage(WarpingResults wr,int[] mismatchesLabels, int flags) { ByteProcessor bp = new ByteProcessor( wr.warpedSource.getWidth(), wr.warpedSource.getHeight() ); for(int i=0; i < wr.mismatches.size(); i++) { Point3f p = wr.mismatches.get( i ); bp.set( (int)p.x, (int)p.y, mismatchesLabels[ i ] & flags ); } return new ImagePlus( "Mismatches", bp ); }
/** * Construct object to store stack of image features. The input image * will be used as one of the features. * * @param image original 2D image (grayscale or RGB) */ public FeatureStack(ImagePlus image) { if( image.getType() == ImagePlus.COLOR_RGB) { originalImage = new ImagePlus("original image", image.getProcessor() ); colorFeatures = true; } else { originalImage = new ImagePlus("original image", image.getProcessor().duplicate().convertToFloat() ); colorFeatures = false; } width = image.getWidth(); height = image.getHeight(); wholeStack = new ImageStack(width, height); wholeStack.addSlice("original", originalImage.getProcessor().duplicate()); }