Posted by
Michael Schmid on
Feb 22, 2016; 2:18pm
URL: http://imagej.273.s1.nabble.com/ImageJ-X-Y-image-subtraction-tp5015686p5015691.html
Hi Potra,
not exactly what you want, but something similar:
Here is a macro for aligning stack slices. On each slice, click on the same object; press the space bar when done. It creates a union, not intersection of the images, and even adds a few pixels ('extraspace') but this can be changed - modify the calculation containing 'extraspace' near the end accordingly; and put the 'Canvas Size' command below the loop, not above it.
For your application, you can easily add a few lines to split the stack when done and subtract the images.
Of course, a more elegant solution would be a plugin showing the difference of two images while moving one of them manually (I'd love to have one), but that would be a bit more work.
Michael
________________________________________________________________
macro 'Manual Stack Register [F7]' {
extraspace = 5; //padding at all sides by this value
requires("1.42j");
n=nSlices();
if (n<2) exit ("stack required");
xs=newArray(nSlices);
ys=newArray(nSlices);
for (i=0; i<n; i++)
xs[i] = -1; //initialize positions as unset
nClicked = 0;
i=getSliceNumber()-1;
flags=0;
lasti = -1;
posS = "";
while (!isKeyDown("space")) {
getCursorLoc(x, y, z, flags);
if (flags&leftClick !=0) {
makePoint(x,y);
xs[i] = x;
ys[i] = y;
nClicked++;
lasti = i;
do {
wait(50);
getCursorLoc(x, y, z, flags);
} while (flags&leftClick !=0);
}
if (i != z) { //slice changed
i = z;
if (xs[i]>=0) {
makePoint(xs[i],ys[i]);
lasti = i;
}
while (isKeyDown("alt")) wait(50);
}
wait(20);
if (lasti>=0) posS = "pos. from "+(lasti+1);
showStatus("','=prev, '.'=next, space=done, esc=abort. "+posS);
}
if (nClicked<2) exit("Abort - at least two positions required");
lasti = -1;
for (i=0; i<n; i++) {
if (xs[i]>=0) {
if (lasti<0) {
lastx=xs[i];
lasty=ys[i];
}
for (j=lasti+1; j<i; j++) { //interpolate
xs[j] = lastx + (xs[i]-lastx)*(j-lasti)/(i-lasti);
ys[j] = lasty + (ys[i]-lasty)*(j-lasti)/(i-lasti);
}
lastx=xs[i];
lasty=ys[i];
lasti=i;
}
}
if (lasti<n-1) {
for (j=lasti+1; j<n; j++) {
xs[j] = lastx;
ys[j] = lasty;
}
}
Array.getStatistics(xs, xmin, xmax, mean, stdDev);
Array.getStatistics(ys, ymin, ymax, mean, stdDev);
newwidth = getWidth()+(xmax-xmin)+2*extraspace;
newheight = getHeight() +(ymax-ymin)+2*extraspace;
run("Canvas Size...", "width="+ newwidth +" height="+ newheight +" position=Top-Left zero");
for (i=0; i<n; i++) {
setSlice(i+1);
run("Translate...", "x="+(xmax-xs[i]+extraspace)+" y="+(ymax-ys[i]+extraspace)+" slice");
}
showStatus("stack registered");
}
________________________________________________________________
On Feb 22, 2016, at 13:30, Protra wrote:
> Hello,
>
> After looking to many plugins, I had to resign myself to ask here if any
> body knows about.
>
> I want to use ImageJ for the subtraction between two 32bit calibrated images
> (they hold STM information).
> But the point is that I should be able to move right/left/up/down one of the
> images in order to align them by hand (the automatic procedures fail because
> I do not want to align all the objects).
>
> The images have the same size (512x512 pixels) but naturally the result
> image would be smaller due to the x/y displacement of one of the images
> during the alignment.
>
> Is there some easy way to do it? Perhaps I should write the plugin, but I
> have no idea how it does work for ImageJ ...
>
> Any input would help!
>
> Thanks,
>
> Protra
>
>
>
> --
> View this message in context:
http://imagej.1557.x6.nabble.com/ImageJ-X-Y-image-subtraction-tp5015686.html> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html