Does anyone know a macro/plugin code how to mirror a selection to make a
symmetric selection in an FFT image for filtering? I draw some circles on a FFT and want to get the corresponding circles on the other side of the image center. I found this short macro from Jerome: roiManager("Add"); getSelectionCoordinates(xs,ys); m=getWidth()/2; for (i=0;i<xs.length;i++) { xs[i]=m-(xs[i]-m); ys[i]=m-(ys[i]-m); } makeSelection ("polygon",xs,ys); roiManager("Add"); which makes a corresponding ROI, but the ROI is not a selection and I can not run 'run("Make Inverse");' on it for example. So I am stuck here... Please help me. Jürgen -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Jürgen
In my hands this works fine. If I add 'run("Make Inverse");' at the end of the code I end up with an inverted selection from the mirrored selection. Maybe you meant to use 'run("Invert");'? Best wishes Kees -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Jürgen Gluch Sent: 27 November 2013 21:28 To: [hidden email] Subject: How to create symmetric selection in FFT image Does anyone know a macro/plugin code how to mirror a selection to make a symmetric selection in an FFT image for filtering? I draw some circles on a FFT and want to get the corresponding circles on the other side of the image center. I found this short macro from Jerome: roiManager("Add"); getSelectionCoordinates(xs,ys); m=getWidth()/2; for (i=0;i<xs.length;i++) { xs[i]=m-(xs[i]-m); ys[i]=m-(ys[i]-m); } makeSelection ("polygon",xs,ys); roiManager("Add"); which makes a corresponding ROI, but the ROI is not a selection and I can not run 'run("Make Inverse");' on it for example. So I am stuck here... Please help me. Jürgen -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Jürgen Gluch
Hi Jürgen,
if you do filtering by setting some areas in an FFT display black or white and doing a backward transform, ImageJ takes care of adding the mirrored black or white areas automatically. Thus, usually you need not care about adding the mirror yourself. By the way, ImageJ also smooths the mask to avoid 'ringing'. If you need a selection for some other purpose and you want to invert it: To make the inverse of both selections, add both, the original and the inverted to the Roi Manager and then run More>>Or (Combine). In a macro, this is roiManager("OR"); Then you can run("Make Inverse"); Michael ________________________________________________________________ On Nov 27, 2013, at 22:27, Jürgen Gluch wrote: > Does anyone know a macro/plugin code how to mirror a selection to make a > symmetric selection in an FFT image for filtering? > I draw some circles on a FFT and want to get the corresponding circles on > the other side of the image center. > > I found this short macro from Jerome: > > roiManager("Add"); > getSelectionCoordinates(xs,ys); > m=getWidth()/2; > for (i=0;i<xs.length;i++) { > xs[i]=m-(xs[i]-m); > ys[i]=m-(ys[i]-m); > } > makeSelection ("polygon",xs,ys); > roiManager("Add"); > > which makes a corresponding ROI, but the ROI is not a selection and I can > not run 'run("Make Inverse");' on it for example. So I am stuck here... > Please help me. Jürgen > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear all,
Thanks for the answers. The "Combine" was the missing part. My macro works: run("FFT"); waitForUser("Draw a selection"); roiManager("Add"); getSelectionCoordinates(xs,ys); m=getWidth()/2; for (i=0;i<xs.length;i++) { xs[i]=m-(xs[i]-m); ys[i]=m-(ys[i]-m); } makeSelection ("polygon",xs,ys); roiManager("Add"); roiManager("Deselect"); // If nothing is selected, the 'Combine' works for all selections roiManager("OR"); // = 'Combine' run("Make Inverse"); run("Set...", "value=0"); run("Select None"); run("Inverse FFT"); exit(); // end macro Michael, from your answer I learned that ImageJ distinguishes between a "white" and a "black" mask. So instead of "Make Inverse" and "Set to 0", I could also fill with white ("Set to 255"). Is the difference just from the smoothing of the mask edge? And I have to note that my approach with "black" on the outside obviously results in an empty image after "Inverse FFT" - which was the reason to look for a mirrored selection. best wishes Jürgen -- Jürgen Gluch Kötitzer Str. 9a / 01445 Radebeul / Deutschland Mobil: +49 (0)176 2297 1673 VOIP: [hidden email] XMPP: [hidden email] 2013/11/28 Michael Schmid <[hidden email]>: > Hi Jürgen, > > if you do filtering by setting some areas in an FFT display black or white and doing a backward transform, ImageJ takes care of adding the mirrored black or white areas automatically. Thus, usually you need not care about adding the mirror yourself. > By the way, ImageJ also smooths the mask to avoid 'ringing'. > > If you need a selection for some other purpose and you want to invert it: > To make the inverse of both selections, add both, the original and the inverted to the Roi Manager and then run More>>Or (Combine). In a macro, this is roiManager("OR"); > Then you can run("Make Inverse"); > > Michael > ________________________________________________________________ > On Nov 27, 2013, at 22:27, Jürgen Gluch wrote: > >> Does anyone know a macro/plugin code how to mirror a selection to make a >> symmetric selection in an FFT image for filtering? >> I draw some circles on a FFT and want to get the corresponding circles on >> the other side of the image center. >> >> I found this short macro from Jerome: >> >> roiManager("Add"); >> getSelectionCoordinates(xs,ys); >> m=getWidth()/2; >> for (i=0;i<xs.length;i++) { >> xs[i]=m-(xs[i]-m); >> ys[i]=m-(ys[i]-m); >> } >> makeSelection ("polygon",xs,ys); >> roiManager("Add"); >> >> which makes a corresponding ROI, but the ROI is not a selection and I can >> not run 'run("Make Inverse");' on it for example. So I am stuck here... >> Please help me. Jürgen >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Jürgen,
if you do an inverse FFT and you have a 'white' mask, Imagej keeps everything that is white (pixel value 255) and clears everything else (pixel values 0-254 become 0). Then it smooths the mask, multiplies it with the FFT values and runs the inverse FFT. If you have a 'black' mask, ImageJ clears everything that is black (pixel values 0) and keeps everything that has pixel values between 1 and 255, irrespective of the pixel value. Again, the result is smoothed and multiplied with the FFT data before the inverse FFT is done. Note that the FFT that you see is for display purposes only (it is a power spectrum with log scaling); the actual FFT data are invisible. If you want to control the smoothing yourself or if you want to apply different factors for different spatial frequencies (i.e., different parts of the FFT), use the 'Custom Filter'. There, you have to care about smoothing yourself. If you need it, somewhere I should have an unpublished plugin that does smoothing and takes the periodic boundary conditions into account. Michael ________________________________________________________________ On Nov 28, 2013, at 13:30, Jürgen Gluch wrote: > Dear all, > > Thanks for the answers. The "Combine" was the missing part. My macro works: > > run("FFT"); > waitForUser("Draw a selection"); > roiManager("Add"); > getSelectionCoordinates(xs,ys); > m=getWidth()/2; > for (i=0;i<xs.length;i++) { > xs[i]=m-(xs[i]-m); > ys[i]=m-(ys[i]-m); > } > makeSelection ("polygon",xs,ys); > roiManager("Add"); > roiManager("Deselect"); // If nothing is selected, the 'Combine' works > for all selections > roiManager("OR"); // = 'Combine' > run("Make Inverse"); > run("Set...", "value=0"); > run("Select None"); > run("Inverse FFT"); > exit(); // end macro > > Michael, from your answer I learned that ImageJ distinguishes between > a "white" and a "black" mask. So instead of "Make Inverse" and "Set to > 0", I could also fill with white ("Set to 255"). Is the difference > just from the smoothing of the mask edge? And I have to note that my > approach with "black" on the outside obviously results in an empty > image after "Inverse FFT" - which was the reason to look for a > mirrored selection. > > best wishes > Jürgen -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thanks for the very clear explanation. May I put it in the wiki? No
need for the unpublished plugin. And I tested it, the power spectum image has always values 0<v<255 :-D Now the macro has only 4 lines (fft,wait,set=255,ifft) and I learned a lot. I used the custom filter for tomographic reconstruction (WBP) before. It works very well. -- Jürgen Gluch Kötitzer Str. 9a / 01445 Radebeul / Deutschland Mobil: +49 (0)176 2297 1673 VOIP: [hidden email] XMPP: [hidden email] 2013/11/28 Michael Schmid <[hidden email]>: > Hi Jürgen, > > if you do an inverse FFT and you have a 'white' mask, Imagej keeps everything that is white (pixel value 255) and clears everything else (pixel values 0-254 become 0). Then it smooths the mask, multiplies it with the FFT values and runs the inverse FFT. > > If you have a 'black' mask, ImageJ clears everything that is black (pixel values 0) and keeps everything that has pixel values between 1 and 255, irrespective of the pixel value. Again, the result is smoothed and multiplied with the FFT data before the inverse FFT is done. > > Note that the FFT that you see is for display purposes only (it is a power spectrum with log scaling); the actual FFT data are invisible. > > If you want to control the smoothing yourself or if you want to apply different factors for different spatial frequencies (i.e., different parts of the FFT), use the 'Custom Filter'. There, you have to care about smoothing yourself. If you need it, somewhere I should have an unpublished plugin that does smoothing and takes the periodic boundary conditions into account. > > Michael > ________________________________________________________________ > On Nov 28, 2013, at 13:30, Jürgen Gluch wrote: > >> Dear all, >> >> Thanks for the answers. The "Combine" was the missing part. My macro works: >> >> run("FFT"); >> waitForUser("Draw a selection"); >> roiManager("Add"); >> getSelectionCoordinates(xs,ys); >> m=getWidth()/2; >> for (i=0;i<xs.length;i++) { >> xs[i]=m-(xs[i]-m); >> ys[i]=m-(ys[i]-m); >> } >> makeSelection ("polygon",xs,ys); >> roiManager("Add"); >> roiManager("Deselect"); // If nothing is selected, the 'Combine' works >> for all selections >> roiManager("OR"); // = 'Combine' >> run("Make Inverse"); >> run("Set...", "value=0"); >> run("Select None"); >> run("Inverse FFT"); >> exit(); // end macro >> >> Michael, from your answer I learned that ImageJ distinguishes between >> a "white" and a "black" mask. So instead of "Make Inverse" and "Set to >> 0", I could also fill with white ("Set to 255"). Is the difference >> just from the smoothing of the mask edge? And I have to note that my >> approach with "black" on the outside obviously results in an empty >> image after "Inverse FFT" - which was the reason to look for a >> mirrored selection. >> >> best wishes >> Jürgen > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |