Point Selection Tools

File

ImageJ has the capacity to make multi point selections, but has limited abilities when it comes to managing those selections. This set of macros provides three simple tools for altering the current point selection by reversing the order or shifting the order of the point selection.

Point_Selection_Tools.ijm

//Shift Point Selection
//This set of macros allows simple modification of a multi-point selection
//It is useful in cases where you have a series of points selected in order,
//but need to change the start point or reverse the direction of the selection.
//Each sub-macro is fairly self-explanatory; they either shift selection
//indicies forward one, backwards one, or reverse their order.

macro "Point Selection - Shift Forward [w]" {
    shiftPointSelection(1);
}

macro "Point Selection - Shift Forward [q]" {
    shiftPointSelection(-1);
}

macro "Point Selection - Reverse [e]" {
    reversePointSelection();
}

function shiftPointSelection(distance) {
    getSelectionCoordinates(x, y);
    xn=newArray(lengthOf(x));
    yn=newArray(lengthOf(y));
    for (i=0; i<lengthOf(x); i++) {
        in=i+distance;
        while(in<0) {
            in+=lengthOf(x);
        }
        while(in>lengthOf(x)-1) {
            in-=lengthOf(x);
        }
        xn[in]=x[i];
        yn[in]=y[i];
    }
    makeSelection("points", xn, yn);
}

function reversePointSelection() {
    getSelectionCoordinates(x, y);
    xn=newArray(lengthOf(x));
    yn=newArray(lengthOf(y));
    for (i=0; i<lengthOf(x); i++) {
        in=lengthOf(x)-(i+1);
        xn[in]=x[i];
        yn[in]=y[i];
    }
    makeSelection("points", xn, yn);
    shiftPointSelection(1);
}

ImageJ Macros Gallery