I have an image with a lot of relatively short noisy lines, all of which are
very close to parallel with each other, and at a small angular offset from horizontal. As part of the processing, I want to align them to be horizontal. The FFT of these images provides a very nice component that is perpendicular to these lines, so that alignment of the FFT to vertical provides the required angle of rotation. Before I work on the automatic detection of the line and angle, and I wondering if anyone has already written a plugin/macro to do this. Thanks in advance. --aryeh -- Aryeh Weiss School of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384050 |
Hello, I have the same problem. Did you find a solution? Or is there any plugin with this functionality? Thanks for your help. Oliver |
oliver wrote:
> Aryeh Weiss wrote: >> I have an image with a lot of relatively short noisy lines, all of which >> are >> very close to parallel with each other, and at a small angular offset from >> horizontal. As part of the processing, I want to align them to be >> horizontal. >> The FFT of these images provides a very nice component that is >> perpendicular to >> these lines, so that alignment of the FFT to vertical provides the >> required >> angle of rotation. >> >> Before I work on the automatic detection of the line and angle, and I >> wondering >> if anyone has already written a plugin/macro to do this. >> > > Hello, I have the same problem. Did you find a solution? Or is there any > plugin with this functionality? > Thanks for your help. > Oliver > Yes -- someone pointed out to me that there is a best fit ellipse function built into ImageJ. If you really have a large number of parallel lines, you will have a well defined ellipse, whose major axis will be 90 degrees plus your offset (the 90 degrees depends on how you define your image orientation , but if you do it you will see how it should be). There will probalby be very well defined component at 0 and 90 degrees, since your CCD image is a grid of points. However, that is easily to erase from the FFT image before doing the fit to the ellipse. I found that the hysteresis thresholding plugin was very useful, because it picks up weak parts of the main ellipse, while leaving out a lot of noise which is not attached to anything strong. Below is an early version of the macro. It is hard coded with the image size, but you can easily change that. Hope it helps --aryeh -- Aryeh Weiss School of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384050 // ====================================== macro "Rotate v1.0 { run("Clear Results"); orig_input_ID = getImageID(); orig_input_Title = getTitle(); run("Duplicate...", "title=["+orig_input_Title+"_dup]"); source_ID = getImageID(); run("FFT"); run("Smooth"); fft_ID = getImageID(); run("Subtract Background...", "rolling=50"); // remove horizontal and vertical artifacts from FFT makeRectangle(522, 506, 502, 14); run("Multiply...", "value=0"); makeRectangle(0, 506, 501, 12); run("Multiply...", "value=0"); makeRectangle(512, 10, 2, 1014); run("Multiply...", "value=0"); run("BW Contrast Stretch amw Stack", "percent=0.10 low=10"); fft_cs_ID = getImageID(); run("Median...", "radius=2"); run("Gray Morphology", "radius=2 type=square operator=close"); run("Hysteresis ", "high=200 low=30"); //run("Threshold..."); fft_seg_ID = getImageID(); selectImage(fft_seg_ID+1); close(); selectImage(fft_seg_ID); setAutoThreshold(); setThreshold(128, 255); run("Convert to Mask"); // run("Clear Results"); run("Set Measurements...", "area fit redirect=None decimal=2"); run("Analyze Particles...", "size=100-Infinity circularity=0.00-1.00 show=Ellipses display"); offset_angle = getResult("Angle"); outlines_ID = getImageID(); offset_angle = offset_angle - 90; selectImage(source_ID); run("Arbitrarily...", "angle="+d2s(offset_angle,2)+" grid=20 interpolate"); // kludge to cut out black areas caused by rotate //makeRectangle(38, 33, 964, 969); //run("Crop"); selectImage(fft_ID); close(); selectImage(outlines_ID); close(); selectImage(fft_cs_ID); close(); selectImage(fft_seg_ID); close(); } |
Free forum by Nabble | Edit this page |