I have looked at various montage macros for creating composite mosaics
from overlapping images, and wanted to try something simpler using "imageJ/Stacks/Make Montage". Since my image offsets required for registration are constant, I can modify the MakeMontage.txt macro to offset the image rectangles before pasting. This works fine, but instead of the default "Paste Control" (Copy) I would like to use Blend, but ***only for the overlapping regions***. (Otherwise Blend blends the non-overlapped regions with the white or other background). newImage("test", type+" black", columns*getWidth, rows*getHeight, 1); iw=getWidth/columns; ih=getHeight/rows; x[0]=0; x[1]=-25; x[2]=0; x[3]=-25; // image offsets for registration y[0]=0; y[1]=0; y[2]=-75; y[3]=-75; // image offsets for registration montage=getImageID; selectImage(id); for (i=0; i<4; i++) { selectImage(id); setSlice(i+1); run("Select All"); run("Copy"); selectImage(montage); makeRectangle((i%columns)*iw+x[i], floor(i/columns)*ih+y[i], sw, sh); run("Paste"); } I am relatively new to imageJ macros but am excited by the possibilities. ______________________________________________ Dr Alan Hewat, NeutronOptics, Grenoble, FRANCE <[hidden email]> +33.476.98.41.68 http://www.NeutronOptics.com/hewat ______________________________________________ |
Hi Alan,
one possibility, though not as simple as the 'Paste Control', would be the 'Alpha Channel' plugin. http://imagejdocu.tudor.lu/doku.php?id=plugin:utilities:alpha_channel:start Create an 8-bit image with the same size of your output image, and set it to the weight of the copied image: 255 for the areas where you have no overlap, and 127 for the overlap. Run the 'Alpha Channel' immediately after 'Paste'. You can also have a soft transition: Put the edge of the alpha channel into the center of the overlap area and select a 'smooth radius' > 0 in the Alpha Channel Dialog. Michael _________________________________________________________________________ On Sat, May 23, 2009 11:05, Alan Hewat wrote: > I have looked at various montage macros for creating composite mosaics > from overlapping images, and wanted to try something simpler using > "imageJ/Stacks/Make Montage". Since my image offsets required for > registration are constant, I can modify the MakeMontage.txt macro to > offset the image rectangles before pasting. > > This works fine, but instead of the default "Paste Control" (Copy) I > would like to use Blend, but ***only for the overlapping regions***. > (Otherwise Blend blends the non-overlapped regions with the white or > other background). > > newImage("test", type+" black", columns*getWidth, rows*getHeight, > 1); > iw=getWidth/columns; ih=getHeight/rows; > x[0]=0; x[1]=-25; x[2]=0; x[3]=-25; // image offsets for > registration > y[0]=0; y[1]=0; y[2]=-75; y[3]=-75; // image offsets for > registration > montage=getImageID; > selectImage(id); > for (i=0; i<4; i++) { > selectImage(id); > setSlice(i+1); > run("Select All"); > run("Copy"); > selectImage(montage); > makeRectangle((i%columns)*iw+x[i], floor(i/columns)*ih+y[i], sw, > sh); > run("Paste"); > } > > I am relatively new to imageJ macros but am excited by the possibilities. > ______________________________________________ > Dr Alan Hewat, NeutronOptics, Grenoble, FRANCE > <[hidden email]> +33.476.98.41.68 > http://www.NeutronOptics.com/hewat > ______________________________________________ > |
In reply to this post by Alan Hewat
> This works fine, but instead of the default "Paste Control" (Copy) I
> would like to use Blend, but ***only for the overlapping regions***. > (Otherwise Blend blends the non-overlapped regions with the white or > other background). I do not think you can do that in a single step with the paste control. However you could cheat a bit and first paste with blending the overlapping part (which you can calculate given that you know the size of both images and the offsets) and then paste again the portion which does not overlap with the "copy" paste mode. Cheers, Gabriel |
2009/5/23 Gabriel Landini <[hidden email]>:
> However you could cheat a bit and first paste with blending the overlapping > part (which you can calculate given that you know the size of both images and > the offsets) and then paste again the portion which does not overlap with the > "copy" paste mode. Thanks Gabriel. It is relatively easy with two images to paste (Copy) the second on top of the first and then to calculate the overlapping rectangle and paste (Blend) that part of the first on top again. But it gets messy for pasting more images because the result is no longer a simple rectangle. 2009/5/23 Michael Schmid <[hidden email]>: > Create an 8-bit image with the same size of your output image, and set it > to the weight of the copied image: 255 for the areas where you have no > overlap, and 127 for the overlap. Run the 'Alpha Channel' immediately after 'Paste'. Thanks Michael. The Alpha Channel looks promising, but again I couldn't see how to easily specify the non-overlapping parts, especially for more than two images. The most elegant solution would be to have a "Paste Control" mode (Merge?) that was like Blend but did not blend in "white" (or "black") parts of an image (background). There are so many paste modes that I thought one must do that, but apparently not. The "Min" Paste Control mode on a white background came closest for an RGB image. Now I just have to work out how to write a new Paste Control mode :-) Alan ______________________________________________ Dr Alan Hewat, NeutronOptics, Grenoble, FRANCE <[hidden email]> +33.476.98.41.68 http://www.NeutronOptics.com/hewat ______________________________________________ |
In reply to this post by Alan Hewat
On Sat, 23 May 2009 11:05:20 +0200, Alan Hewat
<[hidden email]> wrote: >I have looked at various montage macros for creating composite mosaics >from overlapping images, and wanted to try something simpler using >"imageJ/Stacks/Make Montage". Since my image offsets required for >registration are constant, I can modify the MakeMontage.txt macro to >offset the image rectangles before pasting. I made a macro that converts a stack of images with an equal vertical offset into a single image. The overlapping parts are blended. Maybe this helps. // This macro stiches images from a stack into a new image //works only for 32 bit images (convert stack to 32 bit imege first). // displacement+overlap defines distance in pixels between two images. // overlap is the area that is blended via a wedge shape. macro "Stich Stack" { displacement=20; // note: total displacement is 24+20 = 44 pixels overlap=24; width=getWidth(); height=getHeight(); imageTitle=getTitle(); slices=nSlices; run("32-bit"); // force image to be 32 bit newTitle="Reconstructed "+imageTitle; newImage(newTitle, "32-bit Black", width, slices* (displacement+overlap)+overlap, 1); // reconstructed image newImage(imageTitle+"_wedge", "32-bit Black", width, displacement+2*overlap, 1); // create wedge shape blend type run("Min...", "value=1"); dy=1/overlap; if(dy>0) { for(y=0;y<overlap;y++) for(x=0;x<width;x++) setPixel(x,y,dy*y); for(y=0;y<overlap;y++) for(x=0;x<width;x++) setPixel(x,y+overlap+displacement,1-dy*y); } newImage(imageTitle+"_buffer", "32-bit Black", width, (displacement+2*overlap), 1); selectWindow(imageTitle); //stack image setBatchMode(true); for (slice=1; slice<=slices; slice++) { setSlice(slice); run("Specify...", "width="+ width +" height="+ displacement+2*overlap +" x=0 y="+ height/2-displacement/2-overlap+" slice="+slice); run("Copy"); selectWindow(imageTitle+"_buffer"); run("Select None"); setPasteMode("Copy"); run("Paste"); imageCalculator("Multiply", imageTitle+"_buffer",imageTitle+"_wedge"); selectWindow(imageTitle+"_buffer"); run("Select All"); run("Copy"); setPasteMode("Add"); selectWindow(newTitle); run("Select None"); run("Specify...", "width="+ width +" height=" + (displacement+2*overlap) +" x=0 y="+ ((overlap+displacement)*(slice-1)) ); setPasteMode("Add"); run("Paste"); selectWindow(imageTitle); } setBatchMode(false); selectWindow(imageTitle+"_buffer"); close(); selectWindow(imageTitle+"_wedge"); close(); selectWindow(newTitle); run("Select None"); run("Enhance Contrast", "saturated=0"); } |
In reply to this post by Alan Hewat
On May 26, 2009, at 6:00 AM, IMAGEJ automatic digest system wrote:
> Date: Mon, 25 May 2009 04:55:16 -0400 > From: Bruno Keijzers <[hidden email]> > Subject: Re: Paste and Blend only overlapping regions (MakeMontage > variation) > > On Sat, 23 May 2009 11:05:20 +0200, Alan Hewat=20 > <[hidden email]> wrote: > >> I have looked at various montage macros for creating composite >> mosaics >> from overlapping images, and wanted to try something simpler using >> "imageJ/Stacks/Make Montage". Since my image offsets required for >> registration are constant, I can modify the MakeMontage.txt macro to >> offset the image rectangles before pasting. > > I made a macro that converts a stack of images with an equal > vertical=20 > offset into a single image. The overlapping parts are blended. Maybe > this= > =20 > helps. > > // This macro stiches images from a stack into a new image > //works only for 32 bit images (convert stack to 32 bit imege first). > // displacement+overlap defines distance in pixels between two images. > // overlap is the area that is blended via a wedge shape. > > macro "Stich Stack" { ..... Thats nice, but what if your image offsets are not exactly (eg plus minus 1 pixel) correct ? Can they really be that good on a real optical system? I suspect that Stitch Directory with Images (unknown configuration) from Fiji (Fiji is just imageJ - batteries included) http://pacific.mpi-cbg.de/wiki/index.php/Stitching will give a better result, as it relies on the information in the overlapping parts of the image, rather than your best estimate of the real overlap. You dont even need to tell it the tile layout, as it figures it out itself, and it does some kind of global optimisation where 4 images overlap, so you get the best result there, and has nice blending options.... Dan Dr. Daniel James White BSc. (Hons.) PhD Senior Microscopist / Image Visualisation, Processing and Analysis Light Microscopy and Image Processing Facilities Max Planck Institute of Molecular Cell Biology and Genetics Pfotenhauerstrasse 108 01307 DRESDEN Germany +49 (0)15114966933 (German Mobile) +49 (0)351 210 2627 (Work phone at MPI-CBG) +49 (0)351 210 1078 (Fax MPI-CBG LMF) http://www.bioimagexd.net BioImageXD http://pacific.mpi-cbg.de Fiji Fiji is just ImageJ - Batteries Included http://www.chalkie.org.uk [hidden email] ( [hidden email] ) |
Amazing ! I just downloaded
http://pacific.mpi-cbg.de/downloads/Dresden-2009/fiji-win32-20090429.zip and before reading the instructions :-) pointed the macro "Stitch Directory with Images (unknown configuration)" to my directory containing 4 arbitrarily overlapping images - and up came the stitched image within 2 seconds. Magic. Thanks Dan, and all Fiji contributors. Actually my images are not of high enough resolution to make exact pixel registration essential, and the relative coordinates of my 4 cameras are fixed, so registration is not a real problem. But auto Fiji stitching is so simple, fast and powerful. I wonder why it can't also be used as a plugin to mageJ. Thanks again for all the good suggestions from the mailing list. Alan. 2009/5/26 Daniel James White <[hidden email]>: > I suspect that > Stitch Directory with Images (unknown configuration) > from Fiji (Fiji is just imageJ - batteries included) > http://pacific.mpi-cbg.de/wiki/index.php/Stitching > will give a better result, as it relies on the information > in the overlapping parts of the image, > rather than your best estimate of the real overlap. > > You dont even need to tell it the tile layout, as it figures it out itself, > and it does some kind of global optimisation where 4 images overlap, > so you get the best result there, > and has nice blending options.... > > Dan Dr Alan Hewat, NeutronOptics, Grenoble, FRANCE <[hidden email]> +33.476.98.41.68 http://www.NeutronOptics.com/hewat ______________________________________________ |
Hi Alan,
nice that is works for you! It can be by the way also used as an ImageJ plugin, available for download from my website: http://fly.mpi-cbg.de/~preibisch/ in the Software section. The corresponding paper can be found in the publication section. All the best, Stephan -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Alan Hewat Sent: Tuesday, May 26, 2009 10:52 AM To: [hidden email] Subject: Re: Paste and Blend only overlapping regions (MakeMontage variation) Amazing ! I just downloaded http://pacific.mpi-cbg.de/downloads/Dresden-2009/fiji-win32-20090429.zip and before reading the instructions :-) pointed the macro "Stitch Directory with Images (unknown configuration)" to my directory containing 4 arbitrarily overlapping images - and up came the stitched image within 2 seconds. Magic. Thanks Dan, and all Fiji contributors. Actually my images are not of high enough resolution to make exact pixel registration essential, and the relative coordinates of my 4 cameras are fixed, so registration is not a real problem. But auto Fiji stitching is so simple, fast and powerful. I wonder why it can't also be used as a plugin to mageJ. Thanks again for all the good suggestions from the mailing list. Alan. 2009/5/26 Daniel James White <[hidden email]>: > I suspect that > Stitch Directory with Images (unknown configuration) > from Fiji (Fiji is just imageJ - batteries included) > http://pacific.mpi-cbg.de/wiki/index.php/Stitching > will give a better result, as it relies on the information > in the overlapping parts of the image, > rather than your best estimate of the real overlap. > > You dont even need to tell it the tile layout, as it figures it out itself, > and it does some kind of global optimisation where 4 images overlap, > so you get the best result there, > and has nice blending options.... > > Dan ______________________________________________ Dr Alan Hewat, NeutronOptics, Grenoble, FRANCE <[hidden email]> +33.476.98.41.68 http://www.NeutronOptics.com/hewat ______________________________________________ |
Free forum by Nabble | Edit this page |