Anaglyph Macro Speedup
Posted by Jon Harman-3 on May 05, 2008; 8:26pm
URL: http://imagej.273.s1.nabble.com/Anaglyph-Macro-Speedup-tp3696335.html
Hi,
After writing this macro I found the nice plugin by Ronald Petie that
does it much faster.
But I would like to know: Is there any way to speed up this sort of
macro: one that does pixel by pixel operations on two images and then
writes the result to a third image. I have tried to speed it up, but it
is very slow on a large image.
Jon
Here is my macro code:
//This macro can convert two images to an anaglyph for stereo viewing.
Dialog.create("Make Anaglyph from stereo pairs");
Dialog.addMessage("Choose the left then the right image");
atype = newArray("Gray","Color");
Dialog.addChoice("Anaglyph Type",atype,"Gray");
Dialog.show;
ans = Dialog.getChoice();
gray = 1;
if(ans == "Color") gray = 0;
open("");
id0 = getImageID();
open();
id1 = getImageID();
setBatchMode(true);
width = getWidth();
height = getHeight();
line0 = newArray(width);
line1 = newArray(width);
line2 = newArray(width);
newImage("Anaglyph", "RGB", width, height, 1);
id2 = getImageID();
for (h=0;h<height;h++) {
selectImage(id0);
for(w=0;w<width;w++) line0[w] = getPixel(w,h);
selectImage(id1);
for(w=0;w<width;w++) line1[w] = getPixel(w,h);
for(w=0;w<width;w++) {
p = line0[w];
r = (p >> 16) & 0xff;
g = (p >> 8) & 0xff;
b = p & 0xff;
p = line1[w];
r1 = (p >> 16) & 0xff;
g1 = (p >> 8) & 0xff;
b1 = p & 0xff;
if(gray == 0) {
line2[w] = (r << 16) + (g1 << 8) + b1;
}
else {
y = floor(r * 0.3 + g * 0.586 + b * 0.114);
y1 = floor(r1 * 0.3 + g1 * 0.586 + b1 * 0.114);
line2[w] = (y << 16) + (y1 << 8) + y1;
}
}
selectImage(id2);
for(w=0;w<width; w++) setPixel(w,h,line2[w]);
}
setBatchMode(false);
saveAs("jpeg");