Java Code Examples for ij.process.ImageProcessor#getPixels()
The following examples show how to use
ij.process.ImageProcessor#getPixels() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BinaryOrbit.java From orbit-image-analysis with GNU General Public License v3.0 | 6 votes |
public void fill(ImageProcessor ip, int foreground, int background) { int width = ip.getWidth(); int height = ip.getHeight(); FloodFiller ff = new FloodFiller(ip); ip.setColor(127); for (int y=0; y<height; y++) { if (ip.getPixel(0,y)==background) ff.fill(0, y); if (ip.getPixel(width-1,y)==background) ff.fill(width-1, y); } for (int x=0; x<width; x++){ if (ip.getPixel(x,0)==background) ff.fill(x, 0); if (ip.getPixel(x,height-1)==background) ff.fill(x, height-1); } byte[] pixels = (byte[])ip.getPixels(); int n = width*height; for (int i=0; i<n; i++) { if (pixels[i]==127) pixels[i] = (byte)background; else pixels[i] = (byte)foreground; } }
Example 2
Source File: RankFiltersOrbit.java From orbit-image-analysis with GNU General Public License v3.0 | 6 votes |
/** Reset region between inner rectangle 'roi' and outer rectangle 'roi1' to the snapshot */ private void resetRoiBoundary(ImageProcessor ip, Rectangle roi, Rectangle roi1) { int width = ip.getWidth(); Object pixels = ip.getPixels(); Object snapshot = ip.getSnapshotPixels(); for (int y=roi1.y, p = roi1.x+y*width; y<roi.y; y++,p+=width) System.arraycopy(snapshot, p, pixels, p, roi1.width); int leftWidth = roi.x - roi1.x; int rightWidth = roi1.x+roi1.width - (roi.x+roi.width); for (int y=roi.y, pL=roi1.x+y*width, pR=roi.x+roi.width+y*width; y<roi.y+roi.height; y++,pL+=width,pR+=width) { if (leftWidth > 0) System.arraycopy(snapshot, pL, pixels, pL, leftWidth); if (rightWidth > 0) System.arraycopy(snapshot, pR, pixels, pR, rightWidth); } for (int y=roi.y+roi.height, p = roi1.x+y*width; y<roi1.y+roi1.height; y++,p+=width) System.arraycopy(snapshot, p, pixels, p, roi1.width); }
Example 3
Source File: RankFiltersOrbit.java From orbit-image-analysis with GNU General Public License v3.0 | 6 votes |
void showMasks() { int w=150, h=150; ImageStack stack = new ImageStack(w, h); //for (double r=0.1; r<3; r+=0.01) { for (double r=0.5; r<50; r+=0.5) { ImageProcessor ip = new FloatProcessor(w,h,new int[w*h]); float[] pixels = (float[])ip.getPixels(); int[] lineRadii = makeLineRadii(r); int kHeight = kHeight(lineRadii); int kRadius = kRadius(lineRadii); int y0 = h/2-kHeight/2; for (int i = 0, y = y0; i<kHeight; i++, y++) for (int x = w/2+lineRadii[2*i], p = x+y*w; x <= w/2+lineRadii[2*i+1]; x++, p++) pixels[p] = 1f; stack.addSlice("radius="+r+", size="+(2*kRadius+1), ip); } new ImagePlus("Masks", stack).show(); }
Example 4
Source File: FSLoader.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
boolean save(ImageProcessor ip, final String path, final float quality, final boolean as_grey) { if (as_grey) ip = ip.convertToByte(false); if (ip instanceof ByteProcessor) { return save(path, new byte[][]{(byte[])ip.getPixels()}, ip.getWidth(), ip.getHeight(), quality); } else if (ip instanceof ColorProcessor) { final int[] p = (int[]) ip.getPixels(); final byte[] r = new byte[p.length], g = new byte[p.length], b = new byte[p.length], a = new byte[p.length]; for (int i=0; i<p.length; ++i) { final int x = p[i]; r[i] = (byte)((x >> 16)&0xff); g[i] = (byte)((x >> 8)&0xff); b[i] = (byte) (x &0xff); a[i] = (byte)((x >> 24)&0xff); } return save(path, new byte[][]{r, g, b, a}, ip.getWidth(), ip.getHeight(), quality); } return false; }
Example 5
Source File: ColorImages.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates a new ColorProcessor from the red, green and blue channels. Each * channel must be an instance of ByteProcessor. * * @param red * the image for the red channel (must be a ByteProcessor) * @param green * the image for the green channel (must be a ByteProcessor) * @param blue * the image for the blue channel (must be a ByteProcessor) * @return the color image corresponding to the concatenation of the three * channels * @throws IllegalArgumentException * if one of the channel is not an instance of ByteProcessor */ public static final ColorProcessor mergeChannels(ImageProcessor red, ImageProcessor green, ImageProcessor blue) { // check validity of input if (!(red instanceof ByteProcessor)) throw new IllegalArgumentException("Input channels must be instances of ByteProcessor"); if (!(green instanceof ByteProcessor)) throw new IllegalArgumentException("Input channels must be instances of ByteProcessor"); if (!(blue instanceof ByteProcessor)) throw new IllegalArgumentException("Input channels must be instances of ByteProcessor"); // Extract byte array of each channel byte[] redArray = (byte[]) red.getPixels(); byte[] greenArray = (byte[]) green.getPixels(); byte[] blueArray = (byte[]) blue.getPixels(); // get image size int width = red.getWidth(); int height = red.getHeight(); // create result color image ColorProcessor result = new ColorProcessor(width, height); result.setRGB(redArray, greenArray, blueArray); return result; }
Example 6
Source File: ExportMultilevelTiles.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
static private final boolean isEmptyTile(final ImageProcessor ip) { if (ip instanceof ByteProcessor) { final byte[] b = (byte[])ip.getPixels(); for (int i=0; i<b.length; ++i) { if (0 != b[i]) return false; } } else if (ip instanceof ColorProcessor) { final int[] c = (int[])ip.getPixels(); for (int i=0; i<c.length; ++i) { if (0 != (c[i] & 0x00ffffff)) return false; } } return true; }
Example 7
Source File: Patch.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
/** @param c contains the current Display 'channels' value (the transparencies of each channel). This method creates a new color image in which each channel (R, G, B) has the corresponding alpha (in fact, opacity) specified in the 'c'. This alpha is independent of the alpha of the whole Patch. The method updates the Loader cache with the newly created image. The argument 'imp' is optional: if null, it will be retrieved from the loader. * <p> * For non-color images, a standard image is returned regardless of the given {@code c}. * </p> * @param c */ private Image adjustChannels(final int c, final boolean force, ImagePlus imp) { if (null == imp) imp = project.getLoader().fetchImagePlus(this); ImageProcessor ip = imp.getProcessor(); if (null == ip) return null; // fixing synch problems when deleting a Patch Image awt = null; if (ImagePlus.COLOR_RGB == type) { if (imp.getType() != type ) { ip = Utils.convertTo(ip, type, false); // all other types need not be converted, since there are no alphas anyway } if ((c&0x00ffffff) == 0x00ffffff && !force) { // full transparency awt = ip.createImage(); //imp.getImage(); // pixels array will be shared using ij138j and above } else { // modified from ij.process.ColorProcessor.createImage() by Wayne Rasband final int[] pixels = (int[])ip.getPixels(); final float cr = ((c&0xff0000)>>16) / 255.0f; final float cg = ((c&0xff00)>>8) / 255.0f; final float cb = (c&0xff) / 255.0f; final int[] pix = new int[pixels.length]; int p; for (int i=pixels.length -1; i>-1; i--) { p = pixels[i]; pix[i] = (((int)(((p&0xff0000)>>16) * cr))<<16) + (((int)(((p&0xff00)>>8) * cg))<<8) + (int) ((p&0xff) * cb); } final int w = imp.getWidth(); final MemoryImageSource source = new MemoryImageSource(w, imp.getHeight(), DCM, pix, 0, w); source.setAnimated(true); source.setFullBufferUpdates(true); awt = Toolkit.getDefaultToolkit().createImage(source); } } else { awt = ip.createImage(); } //Utils.log2("ip's min, max: " + ip.getMin() + ", " + ip.getMax()); this.channels = c; return awt; }
Example 8
Source File: Distortion_Correction.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
static double getXcorrBlackOut(ImageProcessor ip1, ImageProcessor ip2){ ip1 = ip1.convertToFloat(); ip2 = ip2.convertToFloat(); //If this is not done, the black area from the transformed image influences xcorr result //better alternative would be to use mask images and only calculate xcorr of //the region present in both images. for (int i=0; i<ip1.getWidth(); i++){ for (int j=0; j<ip1.getHeight(); j++){ if (ip1.get(i,j) == 0) ip2.set(i,j,0); if (ip2.get(i,j) == 0) ip1.set(i,j,0); } } // FloatProcessor ip1f = (FloatProcessor)ip1.convertToFloat(); // FloatProcessor ip2f = (FloatProcessor)ip2.convertToFloat(); final float[] data1 = ( float[] )ip1.getPixels(); final float[] data2 = ( float[] )ip2.getPixels(); final double[] data1b = new double[data1.length]; final double[] data2b = new double[data2.length]; int count = 0; double mean1 = 0.0, mean2 = 0.0; for (int i=0; i < data1.length; i++){ //if ((data1[i] == 0) || (data2[i] == 0)) //continue; data1b[i] = data1[i]; data2b[i] = data2[i]; mean1 += data1b[i]; mean2 += data2b[i]; count++; } mean1 /= (double) count; mean2 /= (double) count; double L2_1 = 0.0, L2_2 = 0.0; for (int i=0; i < count; i++){ L2_1 += (data1b[i] - mean1) * (data1b[i] - mean1); L2_2 += (data2b[i] - mean2) * (data2b[i] - mean2); } L2_1 = Math.sqrt(L2_1); L2_2 = Math.sqrt(L2_2); double xcorr = 0.0; for (int i=0; i < count; i++){ xcorr += ((data1b[i]-mean1) / L2_1) * ((data2b[i]-mean2) / L2_2); } //System.out.println("XcorrVal: " + xcorr); return xcorr; }