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"); |
Hi Jon,
> 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. The macro language uses strings as internal data representation, so no, you can't speed up pixel by pixel operations. I would use the macro language for very high level sequences of comands only, such as open an image, run a plugin on it, save the result and close it. Everything else is iddle play; a java plugin will work orders of magnitude faster. Albert -- Albert Cardona http://www.mcdb.ucla.edu/Research/Hartenstein/acardona |
On Monday 05 May 2008 23:32:25 Albert Cardona wrote:
> > 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. > > The macro language uses strings as internal data representation, so no, > you can't speed up pixel by pixel operations. Ah, but you could split the image in RGB planes and operate on those instead of going pixel by pixel. You have 2 images with r0, g0, b0 and r1, g1, b1. Your macro (if I am not mistaken, I have not run it) creates a new image which is r0,g1,b1. I would split both images into R, G, B planes and then merge R0, G1, B1 planes into a new RGB image. This is done by 2 plugin commands "Image>Color>RGB Split" and "RGB Merge" which called from a macro would be way faster. Cheers, G. |
Free forum by Nabble | Edit this page |