Re: Creating individual tiles from one large image

Posted by dscho on
URL: http://imagej.273.s1.nabble.com/Creating-individual-tiles-from-one-large-image-tp5000374p5000378.html

Hi Jacqui,

On Thu, 11 Oct 2012, Jacqui Ross wrote:

> So what we need to do is divide the large image into separate tiles and
> output them as an image sequence.

You might want to start from this macro:

-- snip --
run("Clown (14K)");

tileWidth = 32;
tileHeight = 19;

setBatchMode(true);
original = getImageID();
width = getWidth();
height = getHeight();

stack = 0; // the ID of the output; will be created on demand
for (x = 0; x < width; x += tileWidth) {
        currentTileWidth = width - x;
        if (currentTileWidth > tileWidth)
                currentTileWidth = tileWidth;
        for (y = 0; y < height; y += tileHeight) {
                currentTileHeight = height - y;
                if (currentTileHeight > tileHeight)
                        currentTileHeight = tileHeight;

                // copy the tile
                selectImage(original);
                makeRectangle(x, y, currentTileWidth, currentTileHeight);
                run("Copy");
                run("Select None");
                if (stack == 0) {
                        newImage("Tiled " + getTitle(), "RGB",
                                tileWidth, tileHeight, 1);
                        stack = getImageID();
                } else {
                        selectImage(stack);
                        run("Add Slice");
                }
                makeRectangle(0, 0, currentTileWidth, currentTileHeight);
                run("Paste");
                setMetadata("Label", "(x=" + x + ",y=" + y + ")");
        }
}
if (stack != 0) {
        selectImage(stack);
        run("Select None");
        setSlice(1); // work around bug: the slider is at slice 1,
                // but the last slice is shown
}
setBatchMode(false);
-- snap --

Use either Fiji's script editor (File>New>Script, followed by
Language>ImageJ Macro) or the bare-bones editor of ImageJ 1.x
(Plugins>New>Macro), paste the code and modify it to your liking (you
might want to remove the line opening the clown sample, adjust the image
type of the new type or replace newImage() with a call to the Duplicate...
plugin, and maybe adjust the slice label format).

Ciao,
Johannes

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html