Refine search
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); }
private void byteFromFloat(ImageProcessor ip, FloatProcessor floatEdm) { int width = ip.getWidth(); int height = ip.getHeight(); byte[] bPixels = (byte[])ip.getPixels(); float[] fPixels = (float[])floatEdm.getPixels(); for (int i=0; i<width*height; i++) { float v = fPixels[i]; bPixels[i] = v<255f ? (byte)(v+0.5) : (byte)255; } }
public static FloatProcessor modulo(float val, FloatProcessor mat) { FloatProcessor res = new FloatProcessor(mat.getWidth(), mat.getHeight()); res.setMask(mat.getMask()); float tmp; for (int i = 0, im = mat.getWidth(); i < im; i++) { for (int j = 0, jm = mat.getHeight(); j < jm; j++) { tmp = val / mat.getf(i, j); res.setf(i, j, val - (((float)((int)tmp)) * mat.getf(i, j))); } } return res; }
/** Sets the pixels, and min&max values from a FloatProcessor. * Also the values are taken from the FloatProcessor. * @param channelNumber Ignored (needed for compatibility with ColorProcessor.toFloat) * @param fp The FloatProcessor where the image data are read from. */ public void setPixels(int channelNumber, FloatProcessor fp) { if (fp.getPixels() != getPixels()) setPixels(fp.getPixels()); setMinAndMax(fp.getMin(), fp.getMax()); }
public static ImagePlus calculateLaplace_(ImagePlus imp) { IJ.showStatus("Calculating laplace"); ImagePlus g_z = Convolve3d.convolveZ(imp, H_z); int w = imp.getWidth(), h = imp.getHeight(); int d = imp.getStackSize(); ImageStack grad = new ImageStack(w, h); for(int z = 0; z < d; z++) { FloatProcessor res = new FloatProcessor(w, h); grad.addSlice("", res); float[] values = (float[])res.getPixels(); float[] x_ = (float[])g_x.getStack(). getProcessor(z+1).getPixels(); float[] y_ = (float[])g_y.getStack(). getProcessor(z+1).getPixels(); float[] z_ = (float[])g_z.getStack(). getProcessor(z+1).getPixels(); for(int i = 0; i < w*h; i++) { values[i] = (float)Math.sqrt(
int sizeY) final int maxPoolWidth = input.getWidth() / sizeX; final int maxPoolHeight = input.getHeight() / sizeY; final int inputWidth = input.getWidth(); final int inputHeight = input.getHeight(); ImageStack isMaxPoolInput = new ImageStack(maxPoolWidth, maxPoolHeight); ImageStack isMaxPoolLabel = new ImageStack(maxPoolWidth, maxPoolHeight); for(int slice = 1; slice <= input.getImageStackSize(); slice ++) IJ.log("Processing slice " + slice + "..."); double val = ((float[]) input.getImageStack().getProcessor( slice ).getPixels())[pos]; labelPix[ pos2 ] = ((byte[]) label.getImageStack().getProcessor( slice ).getPixels())[ pos ]; isMaxPoolInput.addSlice( new FloatProcessor( maxPoolWidth, maxPoolHeight, inputPix)); isMaxPoolLabel.addSlice( new ByteProcessor( maxPoolWidth, maxPoolHeight, labelPix, null ));
final int step) final int maxX = (inputImage.getWidth() - patchSize); final int maxY = (inputImage.getHeight() - patchSize); final int matrixWidth = (maxX/step+1) * (maxY/step+1) * inputImage.getImageStackSize(); for(int i=1; i<= inputImage.getImageStack().getSize(); i++) final ImageProcessor ip = inputImage.getImageStack().getProcessor(i).convertToFloat(); ip.setRoi(roi); final ImageProcessor patch = ip.crop(); float[] pixels = (float[])patch.getPixels(); IJ.log("SVD took: " + (end-start) + "ms"); final ImageStack result = new ImageStack(patchSize, patchSize); for(int j=0; j<v.getColumnDimension(); j++) column[j] = v.getEntry(j, i); result.addSlice("PCA " + i, new FloatProcessor(patchSize, patchSize, column));
IJ.error("No function available"); return; IJ.noImage(); return; if (img.getTitle().matches("y\\s=.*")) { //title looks like a fit function IJ.error("First select the image to be transformed"); return; int width = img.getWidth(); int height = img.getHeight(); int size = width*height; float[] data = new float[size]; for (int y=0; y<height; y++) { for (int x=0; x<width; x++) { value = ip.getPixelValue(x,y); data[y*width+x] = (float)cf.f(p, value); ImageProcessor ip2 = new FloatProcessor(width, height, data, ip.getColorModel()); new ImagePlus(img.getTitle()+"-transformed", ip2).show();
private void initResultImage() { if (this.labelImagePlus.getStackSize() == 1) { ImageProcessor labelImage = this.labelImagePlus.getProcessor(); int sizeX = labelImage.getWidth(); int sizeY = labelImage.getHeight(); ImageProcessor resultImage = new FloatProcessor(sizeX, sizeY); this.resultPlus = new ImagePlus("Result", resultImage); } else { ImageStack labelImage = this.labelImagePlus.getStack(); int sizeX = labelImage.getWidth(); int sizeY = labelImage.getHeight(); int sizeZ = labelImage.getSize(); ImageStack resultImage = ImageStack.create(sizeX, sizeY, sizeZ, 32); this.resultPlus = new ImagePlus("Result", resultImage); } this.resultPlus.copyScale(this.labelImagePlus); }
private ImageStack shrinkZ(ImageStack stack, int zshrink) { int w = stack.getWidth(); int h = stack.getHeight(); int d = stack.getSize(); int d2 = d/zshrink; ImageStack stack2 = new ImageStack (w, h, stack.getColorModel()); for (int z=1; z<=d2; z++) stack2.addSlice(stack.getProcessor(z).duplicate()); boolean rgb = stack.getBitDepth()==24; ImageProcessor ip = rgb?new ColorProcessor(d, h):new FloatProcessor(d, h); for (int x=0; x<w; x++) { IJ.showProgress(x+1, w); for (int y=0; y<h; y++) { float value; for (int z=0; z<d; z++) { value = (float)stack.getVoxel(x, y, z); ip.setf(z, y, value); } } ImageProcessor ip2 = shrink(ip, zshrink, 1, method); for (int x2=0; x2<d2; x2++) { for (int y2=0; y2<h; y2++) { stack2.setVoxel(x, y2, x2, ip2.getf(x2,y2)); } } } return stack2; }
@Override final protected void init() { stackOriginal = imp.getStack(); final FloatProcessor fp1, fp2; if ( imp.getType() == ImagePlus.GRAY32 ) { fp1 = ( FloatProcessor )stackOriginal.getProcessor( 1 ).duplicate(); fp2 = ( FloatProcessor )stackOriginal.getProcessor( 2 ).duplicate(); } else { fp1 = ( FloatProcessor )stackOriginal.getProcessor( 1 ).convertToFloat(); fp2 = ( FloatProcessor )stackOriginal.getProcessor( 2 ).convertToFloat(); } bc = new BlockPMCC( fp1, fp2 ); fpR = bc.getTargetProcessor(); fpR.setMinAndMax( -1.0, 1.0 ); fpR2 = ( FloatProcessor )fpR.duplicate(); final ImageStack stack = new ImageStack( fpR.getWidth(), fpR.getHeight() ); stack.addSlice( "r", fpR2 ); imp.setStack( stack ); }
/** This method has been replaced by IJ.createHyperStack(). */ public ImagePlus createHyperStack(String title, int channels, int slices, int frames, int bitDepth) { int size = channels*slices*frames; ImageStack stack2 = new ImageStack(width, height, size); // create empty stack ImageProcessor ip2 = null; switch (bitDepth) { case 8: ip2 = new ByteProcessor(width, height); break; case 16: ip2 = new ShortProcessor(width, height); break; case 24: ip2 = new ColorProcessor(width, height); break; case 32: ip2 = new FloatProcessor(width, height); break; default: throw new IllegalArgumentException("Invalid bit depth"); } stack2.setPixels(ip2.getPixels(), 1); // can't create ImagePlus will null 1st image ImagePlus imp2 = new ImagePlus(title, stack2); stack2.setPixels(null, 1); imp2.setDimensions(channels, slices, frames); imp2.setCalibration(getCalibration()); imp2.setOpenAsHyperStack(true); return imp2; }
void testDistance(ImageProcessor haystack, ImageProcessor needle, int level) { if (level > 0) { int factor = 1 << level; haystack = haystack.resize(haystack.getWidth() / factor, haystack.getHeight() / factor); needle = needle.resize(needle.getWidth() / factor, needle.getHeight() / factor); } int[] haystackPixels = (int[])haystack.getPixels(); int[] needlePixels = (int[])needle.getPixels(); int haystackW = haystack.getWidth(); int haystackH = haystack.getHeight(); int needleW = needle.getWidth(); int needleH = needle.getHeight(); int w = haystackW - needleW; int h = haystackH - needleH; float[] pixels = new float[w * h]; for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) pixels[i + w * j] = distance(haystackPixels, i, j, haystackW, needlePixels, needleW, needleH); IJ.showProgress(j + 1, h); } FloatProcessor fp = new FloatProcessor(w, h, pixels, null); new ImagePlus("distance", fp).show(); }
private static void blurZ(ImageStack stack, double sigmaZ) { GaussianBlur gb = new GaussianBlur(); double accuracy = (stack.getBitDepth()==8||stack.getBitDepth()==24)?0.002:0.0002; int w=stack.getWidth(), h=stack.getHeight(), d=stack.getSize(); float[] zpixels = null; FloatProcessor fp =null; IJ.showStatus("Z blurring"); gb.showProgress(false); int channels = stack.getProcessor(1).getNChannels(); for (int y=0; y<h; y++) { IJ.showProgress(y, h-1); for (int channel=0; channel<channels; channel++) { zpixels = stack.getVoxels(0, y, 0, w, 1, d, zpixels, channel); if (fp==null) fp = new FloatProcessor(w, d, zpixels); //if (y==h/2) new ImagePlus("before-"+h/2, fp.duplicate()).show(); gb.blur1Direction(fp, sigmaZ, accuracy, false, 0); stack.setVoxels(0, y, 0, w, 1, d, zpixels, channel); } } IJ.showStatus(""); }
if (ip.getWidth()!=imageWidth || ip.getHeight()!=imageHeight) ip = ip.resize(imageWidth, imageHeight); IJ.redirectErrorMessages(false); return ip; } else { ImageProcessor ip = null; switch (getBitDepth()) { case 8: ip=new ByteProcessor(imageWidth,imageHeight); break; case 16: ip=new ShortProcessor(imageWidth,imageHeight); break; case 24: ip=new ColorProcessor(imageWidth,imageHeight); break; case 32: ip=new FloatProcessor(imageWidth,imageHeight); break; IJ.redirectErrorMessages(false);
final ImagePlus imp1 = new ImagePlus( "http://fly.mpi-cbg.de/~saalfeld/Pictures/norway.jpg"); final ArrayImg< FloatType, FloatArray > image1 = ArrayImgs.floats( ( float[] )imp1.getProcessor().convertToFloatProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); final ArrayImg< UnsignedByteType, ByteArray > image2 = ArrayImgs.unsignedBytes( ( byte[] )imp1.getProcessor().convertToByteProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); final ArrayImg< UnsignedShortType, ShortArray > image3 = ArrayImgs.unsignedShorts( ( short[] )imp1.getProcessor().convertToShortProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); final ArrayImg< ARGBType, IntArray > image4 = ArrayImgs.argbs( ( int[] )imp1.getProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() );
public static ImagePlus FloatArrayToImagePlus(FloatArray2D image, String name, float min, float max) { ImagePlus imp = IJ.createImage(name,"32-Bit Black", image.width, image.height, 1); FloatProcessor ip = (FloatProcessor)imp.getProcessor(); FloatArrayToFloatProcessor(ip, image); if (min == max) ip.resetMinAndMax(); else ip.setMinAndMax(min, max); imp.updateAndDraw(); return imp; }
public ImagePlus imageplus() { final ImageStack imagestack = new ImageStack(dims.x,dims.y); for (int t=0; t<dims.t; ++t) for (int z=0; z<dims.z; ++z) for (int c=0; c<dims.c; ++c) imagestack.addSlice("",elements[c][t][z]); final FloatProcessor minmax = new FloatProcessor(2,1); final double[] evals = extrema(); minmax.putPixelValue(0,0,evals[0]); minmax.putPixelValue(1,0,evals[1]); minmax.resetMinAndMax(); imagestack.update(minmax); final Calibration cal = new Calibration(); cal.pixelWidth = aspects.x; cal.pixelHeight = aspects.y; cal.pixelDepth = aspects.z; cal.frameInterval = aspects.t; ImagePlus imageplus = new ImagePlus(name,imagestack); imageplus.setDimensions(dims.c,dims.z,dims.t); imageplus.setCalibration(cal); return imageplus; }
private FloatProcessor getRoiProcessor(ImagePlus imp, Roi roi, int index) { ImageProcessor ip = imp.getStack().getProcessor(index); ip.setRoi(roi.getBounds()); FloatProcessor fp = subtract(ip.crop().convertToFloatProcessor(), (float) CameraSetupPlugIn.getOffset()); float minVal = VectorMath.min((float[]) fp.getPixels()); if(minVal < 0) { IJ.log("\\Update:Camera base level is set higher than values in the image!"); fp = add(-minVal, fp); } fp.setMask(roi.getMask()); return fp; }