Skip to content

Instantly share code, notes, and snippets.

@fiji
Created March 24, 2011 15:35
Show Gist options
  • Save fiji/885262 to your computer and use it in GitHub Desktop.
Save fiji/885262 to your computer and use it in GitHub Desktop.
import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.plugin.filter.PlugInFilter;
import ij.process.ImageProcessor;
public class JoshD_Z_Deinterlacing implements PlugInFilter {
protected ImagePlus image;
public int setup(String arg, ImagePlus image) {
this.image = image;
return DOES_ALL | NO_CHANGES;
}
public void run(ImageProcessor ip) {
int width = image.getWidth(), height = image.getHeight();
ImageStack stack = image.getStack();
ImageStack out = new ImageStack(width, height / 2);
for (int slice = 1; slice <= stack.getSize(); slice++) {
ip = stack.getProcessor(slice);
Object pixels = ip.getPixels();
ImageProcessor ip1 = ip.createProcessor(width, height / 2);
Object pixels1 = ip1.getPixels();
ImageProcessor ip2 = ip.createProcessor(width, height / 2);
Object pixels2 = ip2.getPixels();
for (int y = 0; y < (height - 1) / 2; y++) {
System.arraycopy(pixels, width * 2 * y, pixels1, width * y, width);
System.arraycopy(pixels, width * (2 * y + 1), pixels2, width * y, width);
}
out.addSlice("", ip1);
out.addSlice("", ip2);
IJ.showProgress(slice, stack.getSize());
}
new ImagePlus("Deinterleaved " + image.getTitle(), out).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment