https://imagej.net/api.php?action=feedcontributions&user=Llamero&feedformat=atomImageJ - User contributions [en]2019-11-19T05:32:23ZUser contributionsMediaWiki 1.28.0https://imagej.net/index.php?title=Raspberry_Pi&diff=38820Raspberry Pi2018-12-08T04:33:20Z<p>Llamero: </p>
<hr />
<div>{{PlatformsMenu}}{{Minibox | logo=Pi.svg | blurb=Learn programming through fun, practical projects!}}The [[wikipedia:Raspberry Pi|Raspberry Pi]] is an inexpensive single-board computer system which runs the [[wikipedia:Raspbian|Raspbian]] operating system, a flavor of Debian [[Linux]]. This page provides advice and guidance for running [[ImageJ]] and [[Fiji]] on Raspberry Pi systems.<br />
<br />
<br />
{{TOC}}<br />
= Installation =<br />
{{ImageJ1 | You might notice there is as an <code>imagej</code> package available from your package manager. Please be aware that this provides [[ImageJ 1.x]] only, packaged by a third party, without cooperation from the core ImageJ development team. You will not have access to any [[ImageJ2]]-specific features such as [[Script parameters|parameterized scripts]], and you will likely have permissions errors because it is a system-wide ImageJ installation.}}The following steps describe how to install ImageJ on a Raspberry Pi:<br />
<br />
# Install Java 8 on your Pi. Verify it works using <code>java -version</code> from the command line.<br />
# Download and install the [http://downloads.imagej.net/fiji/latest/fiji-nojre.zip platform-independent "no JRE" distribution of Fiji].<br />
# Download the [https://github.com/imagej/imagej/blob/master/bin/ImageJ.sh ImageJ.sh] shell script, set its executable bit (<code>chmod +x ImageJ.sh</code>) and run it to launch ImageJ. Note that the shell script supports only a subset of the functionality of the native [[ImageJ Launcher]], but it should be able to run ImageJ successfully.<br />
#Move the ImageJ.sh file to the Fiji.app folder<br />
<br />
The following steps describe how to create a desktop icon to launch FIJI on a Raspberry Pi:<br />
<br />
#Dowload the Fiji icon image: [https://imagej.net/_images/thumb/a/ae/Fiji-icon.png/48px-Fiji-icon.png Fiji icon link]<br />
#Press ctrl + alt + t to open the terminal window<br />
#Type: <code> nano FIJI launcher.desktop </code> and press return. This will load Nano which will allow you to create a desktop icon.<br />
#Type the following code, replacing "/path/to" with the paths to the ImageJ.sh file and the Fiji icon: <br />
<source lang="linux-config"><br />
[Desktop Entry]<br />
Name=Fiji launcher<br />
Version=1.0<br />
Comment=Launches Fiji<br />
Exec=/path/to/ImageJ.sh<br />
Icon=/path/to/48px-Fiji-icon.png<br />
Terminal=false<br />
Type=Application<br />
Categories=Education<br />
</source><br />
#Press Ctrl + x and then press Y to exit and save the new desktop icon.<br />
#Enter your desired file name, such as "Fiji Launcher.desktop" and press return. Once complete, an icon should be visible on the desktop.<br />
#Press Ctrl + x to return to the terminal window<br />
#In the terminal window, type the following to navigate to the Desktop: <code> cd ~/Desktop </code><br />
#Then type the following to make the new icon executable: <code>chmod +x "Fiji Launcher.desktop"</code><br />
<br />
<br />
= 3D Visualization =<br />
<br />
It is supposedly possible to run [[Java 3D]] on the Pi; see [http://stackoverflow.com/questions/28529344/how-to-run-java3d-on-rpi-2 this StackOverflow thread]. However, there have been no official reported successes on ImageJ community channels yet. If you get it working, please edit this section to describe the steps you used!<br />
<br />
Even better, if you get [[ClearVolume]] and/or [[SciView]] working on the Pi, please update this page, and announce it on the [[ImageJ Forum]]!<br />
<br />
= Troubleshooting =<br />
See the [[Troubleshooting]] page.<br />
<br />
= Frequently Asked Questions =<br />
See the [[Frequently Asked Questions]] page.<br />
<br />
= See also =<br />
* Topics tagged [http://forum.imagej.net/tags/raspberry-pi raspberry-pi] on the [[ImageJ Forum]].<br />
* The [[Linux]] page, for general information about ImageJ on Linux systems.<br />
<br />
[[Category:Platforms]]</div>Llamerohttps://imagej.net/index.php?title=Raspberry_Pi&diff=38819Raspberry Pi2018-12-08T00:09:11Z<p>Llamero: </p>
<hr />
<div>{{PlatformsMenu}}{{Minibox | logo=Pi.svg | blurb=Learn programming through fun, practical projects!}}The [[wikipedia:Raspberry Pi|Raspberry Pi]] is an inexpensive single-board computer system which runs the [[wikipedia:Raspbian|Raspbian]] operating system, a flavor of Debian [[Linux]]. This page provides advice and guidance for running [[ImageJ]] and [[Fiji]] on Raspberry Pi systems.<br />
<br />
<br />
{{TOC}}<br />
= Installation =<br />
{{ImageJ1 | You might notice there is as an <code>imagej</code> package available from your package manager. Please be aware that this provides [[ImageJ 1.x]] only, packaged by a third party, without cooperation from the core ImageJ development team. You will not have access to any [[ImageJ2]]-specific features such as [[Script parameters|parameterized scripts]], and you will likely have permissions errors because it is a system-wide ImageJ installation.}}The following steps describe how to install ImageJ on a Raspberry Pi:<br />
<br />
# Install Java 8 on your Pi. Verify it works using <code>java -version</code> from the command line.<br />
# Download and install the [http://downloads.imagej.net/fiji/latest/fiji-nojre.zip platform-independent "no JRE" distribution of Fiji].<br />
# Download the [https://github.com/imagej/imagej/blob/master/bin/ImageJ.sh ImageJ.sh] shell script, set its executable bit (<code>chmod +x ImageJ.sh</code>) and run it to launch ImageJ. Note that the shell script supports only a subset of the functionality of the native [[ImageJ Launcher]], but it should be able to run ImageJ successfully.<br />
#Move the ImageJ.sh file to the Fiji.app folder<br />
<br />
The following steps describe how to create a desktop icon to launch FIJI on a Raspberry Pi:<br />
<br />
#Dowload the Fiji icon image: [https://imagej.net/_images/thumb/a/ae/Fiji-icon.png/48px-Fiji-icon.png Fiji icon link]<br />
#Press ctrl + alt + t to open the terminal window<br />
#Type: <code> nano FIJI launcher.desktop </code> and press return. This will load Nano which will allow you to create a desktop icon.<br />
#Type the following code, replacing "/path/to" with the paths to the ImageJ.sh file and the Fiji icon:<br />
<source lang="linux-config"><br />
[Desktop Entry]<br />
Name=Fiji launcher<br />
Version=1.0<br />
Comment=Launches Fiji<br />
Exec=/path/to/ImageJ.sh<br />
Icon=/path/to/48px-Fiji-icon.png<br />
Terminal=false<br />
Type=Application<br />
Categories=Education<br />
</source><br />
#Press Ctrl + x and then press Y to exit and save the new desktop icon.<br />
#Enter you desired file name, such as "Fiji Launcher.desktop" and press return. Once complete, an icon should be visible on the desktop.<br />
#Press Ctrl + x to return to the terminal window<br />
#In the terminal window, type the following to navigate to the Desktop: <code> cd ~/Desktop <code><br />
#Then type the following to make the new icon executable: <code>chmod +x "Fiji Launcher.desktop"</code><br />
<br />
<br />
= 3D Visualization =<br />
<br />
It is supposedly possible to run [[Java 3D]] on the Pi; see [http://stackoverflow.com/questions/28529344/how-to-run-java3d-on-rpi-2 this StackOverflow thread]. However, there have been no official reported successes on ImageJ community channels yet. If you get it working, please edit this section to describe the steps you used!<br />
<br />
Even better, if you get [[ClearVolume]] and/or [[SciView]] working on the Pi, please update this page, and announce it on the [[ImageJ Forum]]!<br />
<br />
= Troubleshooting =<br />
See the [[Troubleshooting]] page.<br />
<br />
= Frequently Asked Questions =<br />
See the [[Frequently Asked Questions]] page.<br />
<br />
= See also =<br />
* Topics tagged [http://forum.imagej.net/tags/raspberry-pi raspberry-pi] on the [[ImageJ Forum]].<br />
* The [[Linux]] page, for general information about ImageJ on Linux systems.<br />
<br />
[[Category:Platforms]]</div>Llamerohttps://imagej.net/index.php?title=Raspberry_Pi&diff=38818Raspberry Pi2018-12-08T00:08:00Z<p>Llamero: Added clarification about where to put the ImageJ.sh file, as well as a guide on how to make an executable desktop icon for Fiji</p>
<hr />
<div>{{PlatformsMenu}}{{Minibox | logo=Pi.svg | blurb=Learn programming through fun, practical projects!}}The [[wikipedia:Raspberry Pi|Raspberry Pi]] is an inexpensive single-board computer system which runs the [[wikipedia:Raspbian|Raspbian]] operating system, a flavor of Debian [[Linux]]. This page provides advice and guidance for running [[ImageJ]] and [[Fiji]] on Raspberry Pi systems.<br />
<br />
<br />
{{TOC}}<br />
= Installation =<br />
{{ImageJ1 | You might notice there is as an <code>imagej</code> package available from your package manager. Please be aware that this provides [[ImageJ 1.x]] only, packaged by a third party, without cooperation from the core ImageJ development team. You will not have access to any [[ImageJ2]]-specific features such as [[Script parameters|parameterized scripts]], and you will likely have permissions errors because it is a system-wide ImageJ installation.}}The following steps describe how to install ImageJ on a Raspberry Pi:<br />
<br />
# Install Java 8 on your Pi. Verify it works using <code>java -version</code> from the command line.<br />
# Download and install the [http://downloads.imagej.net/fiji/latest/fiji-nojre.zip platform-independent "no JRE" distribution of Fiji].<br />
# Download the [https://github.com/imagej/imagej/blob/master/bin/ImageJ.sh ImageJ.sh] shell script, set its executable bit (<code>chmod +x ImageJ.sh</code>) and run it to launch ImageJ. Note that the shell script supports only a subset of the functionality of the native [[ImageJ Launcher]], but it should be able to run ImageJ successfully.<br />
#Move the ImageJ.sh file to the Fiji.app folder<br />
<br />
The following steps describe how to create a desktop icon to launch FIJI on a Raspberry Pi:<br />
<br />
#Dowload the Fiji icon image: [https://imagej.net/_images/thumb/a/ae/Fiji-icon.png/48px-Fiji-icon.png Fiji icon link]<br />
#Press ctrl + alt + t to open the terminal window<br />
#Type: <code> nano FIJI launcher.desktop </code> and press return. This will load Nano which will allow you to create a desktop icon.<br />
#Type the following code, replacing "/path/to" with the paths to the ImageJ.sh file and the Fiji icon:<br />
<source lang="linux-config"><br />
[Desktop Entry]<br />
Name=Fiji launcher<br />
Version=1.0<br />
Comment=Launches Fiji<br />
Exec=/path/to/ImageJ.sh<br />
Icon=/path/to/48px-Fiji-icon.png<br />
Terminal=false<br />
Type=Application<br />
Categories=Education<br />
</source><br />
#Press Ctrl + x and then press Y to exit and save the new desktop icon. #Enter you desired file name, such as "Fiji Launcher.desktop" and press return. Once complete, an icon should be visible on the desktop.<br />
#Press Ctrl + x to return to the terminal window<br />
#In the terminal window, type the following to navigate to the Desktop: <code> cd ~/Desktop <code><br />
#Then type the following to make the new icon executable: <code>chmod +x "Fiji Launcher.desktop"</code><br />
<br />
<br />
= 3D Visualization =<br />
<br />
It is supposedly possible to run [[Java 3D]] on the Pi; see [http://stackoverflow.com/questions/28529344/how-to-run-java3d-on-rpi-2 this StackOverflow thread]. However, there have been no official reported successes on ImageJ community channels yet. If you get it working, please edit this section to describe the steps you used!<br />
<br />
Even better, if you get [[ClearVolume]] and/or [[SciView]] working on the Pi, please update this page, and announce it on the [[ImageJ Forum]]!<br />
<br />
= Troubleshooting =<br />
See the [[Troubleshooting]] page.<br />
<br />
= Frequently Asked Questions =<br />
See the [[Frequently Asked Questions]] page.<br />
<br />
= See also =<br />
* Topics tagged [http://forum.imagej.net/tags/raspberry-pi raspberry-pi] on the [[ImageJ Forum]].<br />
* The [[Linux]] page, for general information about ImageJ on Linux systems.<br />
<br />
[[Category:Platforms]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=38536Hough Circle Transform2018-09-22T02:56:37Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| update site = UCB Vision Sciences<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = September 21<sup>st</sup>, 2018 (v1.0.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform: '''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform: '''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. Since the Hough space search starts with the highest scoring circle, and then the second highest, and so on, if there are a greater number of circles with<br />
a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. ratio of votes) that a circle can have to count as a valid object. This value is described as the following ratio: <br />
:<math>\text{Hough score}=\left ( \frac{\text{number of votes}}{\text{transform resolution}} \right )</math><br />
Since the maximum number of votes a circle can receive is the transform resolution (i.e. every transform resulted in a vote), the highest score a circle can receive is 1.0. Thus, the lower the score threshold, the more tolerant the search will be of incomplete and/or imperfect circles.<br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series (NOTE: This option can be turned off in Advanced Mode: see "Reduce transform resolution"). Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1000.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.0.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this option is selected by default.<br />
<br />
----<br />
<br />
=== Local Search Parameters ===<br />
When using a Hough Transform to track circular objects over time, such as with pupil dilation or eye tracking, it is highly inefficient to calculate the full Hough Space and then search the full Hough space, since you know the object in the current frame is going to be roughly in the same position and have roughly the same radius as the corresponding object in the previous frame.<br />
<br />
The local search algorithm takes advantage of this ''a priori'' information to greatly reduce the volume of the transform and search space in subsequent frames, allowing for many orders of magnitude increase in processing speed.<br />
<br />
The local search algorithm is comprised of three sub-algorithms, depending on the state of the prior frame:<br />
<br />
'''Full - '''For the first frame, a "full" Hough circle transform (the standard algorithm) is performed to find the initial radius and position of each circular object in the frame (up to the maximum number of circles set). The full Hough transform will also be used if the number of circular objects found in a given frame is 0.<br />
<br />
'''Local - '''If the number of circular objects in the previous frame is greater than or equal to the minimum number of objects set, then the algorithm will use an exclusively local search to find the same circular objects in the next frame. The local algorithm performs a transform of only the nearby Hough space of the object found in the last frame, and then searches only this local space for the same object in the current frame.<br />
<br />
'''Partial Local - ''' If the number of circular objects in the previous frame is less than the minimum number of objects set but greater than 0, then the algorithm will use a a hybrid search. A full Hough transform will be performed such that any missing circles will now be found. However, so speed up the search, the algorithm will first search locally within the Hough space for the same circular objects found in the previous frame, and then will search the entire Hough space for any remaining circular objects.<br />
<br />
<br />
[[File:Local Search.png|thumb|1000px|center|'''Local versus full Hough transform.''' <br />
<br />
The left panel shows the input data with a single circle in the center of the image with a radius of 50 pixels. The center panel shows orthogonal projections of the full 3D Hough space. The radius search range was 10-110 pixels. The left panel shows a local Hough transform of the same circle, with a search area of 20x20 pixels, and a radius search range of +/- 10 pixels of the original circle radius. NOTE: In Hough space, the Z-dimension is the radius of the transform.]]<br />
<br />
====''Minimum number of circles to be found''====<br />
<br />
This value represents the minimum number of circles the Hough circle transform will search for before switching to using the partial or full search algorithms to find missing circles. For example, if the transform found 20 circles in the first frame, and the minimum is set to 10, then the algorithm will tolerate loosing track of 10 of the original circles before searching the full Hough space for the missing circles. <br />
<br />
====''Local radius search bandwidth (+/- previous radius)''==== <br />
<br />
This value allows you to set the Z-axis of the local Hough search space. For example, if in your data you do not expect the radius of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same radius as in the previous frame +/- 10 pixels.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to the total radius search range (maximum search radius - minimum search radius).<br />
<br />
====''Local search radius for position of next centroid''==== <br />
<br />
This value allows you to set the x,y axis search radius. For example, if in your data you do not expect the position of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same position as in the previous frame +/- 10 pixels.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to the minimum search radius.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently. However, while the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
NOTE: This option is only available in advanced mode. this value defaults to 1.0. <br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
NOTE: Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== Bug Report ==<br />
April 5, 2018 - Fixed bug where the clear radius ratio was ignored.<br />
<br />
September 21, 2018 - Fixed bug where repeated calls to the plugin would result in a memory leak.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=38535Hough Circle Transform2018-09-22T02:54:35Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| update site = UCB Vision Sciences<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = September 21<sup>st</sup>, 2018 (v1.0.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform: '''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform: '''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. Since the Hough space search starts with the highest scoring circle, and then the second highest, and so on, if there are a greater number of circles with<br />
a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. ratio of votes) that a circle can have to count as a valid object. This value is described as the following ratio: <br />
:<math>\text{Hough score}=\left ( \frac{\text{number of votes}}{\text{transform resolution}} \right )</math><br />
Since the maximum number of votes a circle can receive is the transform resolution (i.e. every transform resulted in a vote), the highest score a circle can receive is 1.0. Thus, the lower the score threshold, the more tolerant the search will be of incomplete and/or imperfect circles.<br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series (NOTE: This option can be turned off in Advanced Mode: see "Reduce transform resolution"). Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1000.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.0.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this option is selected by default.<br />
<br />
----<br />
<br />
=== Local Search Parameters ===<br />
When using a Hough Transform to track circular objects over time, such as with pupil dilation or eye tracking, it is highly inefficient to calculate the full Hough Space and then search the full Hough space, since you know the object in the current frame is going to be roughly in the same position and have roughly the same radius as the corresponding object in the previous frame.<br />
<br />
The local search algorithm takes advantage of this ''a priori'' information to greatly reduce the volume of the transform and search space in subsequent frames, allowing for many orders of magnitude increase in processing speed.<br />
<br />
The local search algorithm is comprised of three sub-algorithms, depending on the state of the prior frame:<br />
<br />
'''Full - '''For the first frame, a "full" Hough circle transform (the standard algorithm) is performed to find the initial radius and position of each circular object in the frame (up to the maximum number of circles set). The full Hough transform will also be used if the number of circular objects found in a given frame is 0.<br />
<br />
'''Local - '''If the number of circular objects in the previous frame is greater than or equal to the minimum number of objects set, then the algorithm will use an exclusively local search to find the same circular objects in the next frame. The local algorithm performs a transform of only the nearby Hough space of the object found in the last frame, and then searches only this local space for the same object in the current frame.<br />
<br />
'''Partial Local - ''' If the number of circular objects in the previous frame is less than the minimum number of objects set but greater than 0, then the algorithm will use a a hybrid search. A full Hough transform will be performed such that any missing circles will now be found. However, so speed up the search, the algorithm will first search locally within the Hough space for the same circular objects found in the previous frame, and then will search the entire Hough space for any remaining circular objects.<br />
<br />
<br />
[[File:Local Search.png|thumb|1000px|center|'''Local versus full Hough transform.''' <br />
<br />
The left panel shows the input data with a single circle in the center of the image with a radius of 50 pixels. The center panel shows orthogonal projections of the full 3D Hough space. The radius search range was 10-110 pixels. The left panel shows a local Hough transform of the same circle, with a search area of 20x20 pixels, and a radius search range of +/- 10 pixels of the original circle radius. NOTE: In Hough space, the Z-dimension is the radius of the transform.]]<br />
<br />
====''Minimum number of circles to be found''====<br />
<br />
This value represents the minimum number of circles the Hough circle transform will search for before switching to using the partial or full search algorithms to find missing circles. For example, if the transform found 20 circles in the first frame, and the minimum is set to 10, then the algorithm will tolerate loosing track of 10 of the original circles before searching the full Hough space for the missing circles. <br />
<br />
====''Local radius search bandwidth (+/- previous radius)''==== <br />
<br />
This value allows you to set the Z-axis of the local Hough search space. For example, if in your data you do not expect the radius of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same radius as in the previous frame +/- 10 pixels.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to the total radius search range (maximum search radius - minimum search radius).<br />
<br />
====''Local search radius for position of next centroid''==== <br />
<br />
This value allows you to set the x,y axis search radius. For example, if in your data you do not expect the position of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same position as in the previous frame +/- 10 pixels.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to the minimum search radius.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently. However, while the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
NOTE: This option is only available in advanced mode. this value defaults to 1.0. <br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
NOTE: Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== Bug Report ==<br />
April 5, 2018 - Fixed bug where the clear radius ratio was ignored.<br />
September 21, 2018 - Fixed bug where repeated calls to the plugin would result in a memory leak.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=37530Hough Circle Transform2018-04-05T07:16:44Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| update site = UCB Vision Sciences<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = April 5th<sup>th</sup>, 2018 (v0.9.1)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform: '''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform: '''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. Since the Hough space search starts with the highest scoring circle, and then the second highest, and so on, if there are a greater number of circles with<br />
a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. ratio of votes) that a circle can have to count as a valid object. This value is described as the following ratio: <br />
:<math>\text{Hough score}=\left ( \frac{\text{number of votes}}{\text{transform resolution}} \right )</math><br />
Since the maximum number of votes a circle can receive is the transform resolution (i.e. every transform resulted in a vote), the highest score a circle can receive is 1.0. Thus, the lower the score threshold, the more tolerant the search will be of incomplete and/or imperfect circles.<br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series (NOTE: This option can be turned off in Advanced Mode: see "Reduce transform resolution"). Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1000.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.0.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this option is selected by default.<br />
<br />
----<br />
<br />
=== Local Search Parameters ===<br />
When using a Hough Transform to track circular objects over time, such as with pupil dilation or eye tracking, it is highly inefficient to calculate the full Hough Space and then search the full Hough space, since you know the object in the current frame is going to be roughly in the same position and have roughly the same radius as the corresponding object in the previous frame.<br />
<br />
The local search algorithm takes advantage of this ''a priori'' information to greatly reduce the volume of the transform and search space in subsequent frames, allowing for many orders of magnitude increase in processing speed.<br />
<br />
The local search algorithm is comprised of three sub-algorithms, depending on the state of the prior frame:<br />
<br />
'''Full - '''For the first frame, a "full" Hough circle transform (the standard algorithm) is performed to find the initial radius and position of each circular object in the frame (up to the maximum number of circles set). The full Hough transform will also be used if the number of circular objects found in a given frame is 0.<br />
<br />
'''Local - '''If the number of circular objects in the previous frame is greater than or equal to the minimum number of objects set, then the algorithm will use an exclusively local search to find the same circular objects in the next frame. The local algorithm performs a transform of only the nearby Hough space of the object found in the last frame, and then searches only this local space for the same object in the current frame.<br />
<br />
'''Partial Local - ''' If the number of circular objects in the previous frame is less than the minimum number of objects set but greater than 0, then the algorithm will use a a hybrid search. A full Hough transform will be performed such that any missing circles will now be found. However, so speed up the search, the algorithm will first search locally within the Hough space for the same circular objects found in the previous frame, and then will search the entire Hough space for any remaining circular objects.<br />
<br />
<br />
[[File:Local Search.png|thumb|1000px|center|'''Local versus full Hough transform.''' <br />
<br />
The left panel shows the input data with a single circle in the center of the image with a radius of 50 pixels. The center panel shows orthogonal projections of the full 3D Hough space. The radius search range was 10-110 pixels. The left panel shows a local Hough transform of the same circle, with a search area of 20x20 pixels, and a radius search range of +/- 10 pixels of the original circle radius. NOTE: In Hough space, the Z-dimension is the radius of the transform.]]<br />
<br />
====''Minimum number of circles to be found''====<br />
<br />
This value represents the minimum number of circles the Hough circle transform will search for before switching to using the partial or full search algorithms to find missing circles. For example, if the transform found 20 circles in the first frame, and the minimum is set to 10, then the algorithm will tolerate loosing track of 10 of the original circles before searching the full Hough space for the missing circles. <br />
<br />
====''Local radius search bandwidth (+/- previous radius)''==== <br />
<br />
This value allows you to set the Z-axis of the local Hough search space. For example, if in your data you do not expect the radius of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same radius as in the previous frame +/- 10 pixels.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to the total radius search range (maximum search radius - minimum search radius).<br />
<br />
====''Local search radius for position of next centroid''==== <br />
<br />
This value allows you to set the x,y axis search radius. For example, if in your data you do not expect the position of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same position as in the previous frame +/- 10 pixels.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to the minimum search radius.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently. However, while the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
NOTE: This option is only available in advanced mode. this value defaults to 1.0. <br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
NOTE: Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== Bug Report ==<br />
April 5, 2018 - Fixed bug where the clear radius ratio was ignored.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=File:Hough_GUI2.png&diff=30254File:Hough GUI2.png2017-04-19T05:42:03Z<p>Llamero: Llamero uploaded a new version of File:Hough GUI2.png</p>
<hr />
<div>== Licensing ==<br />
{{cc-by-sa-4.0}}</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30251Hough Circle Transform2017-04-19T05:28:03Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform: '''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform: '''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. Since the Hough space search starts with the highest scoring circle, and then the second highest, and so on, if there are a greater number of circles with<br />
a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. ratio of votes) that a circle can have to count as a valid object. This value is described as the following ratio: <br />
:<math>\text{Hough score}=\left ( \frac{\text{number of votes}}{\text{transform resolution}} \right )</math><br />
Since the maximum number of votes a circle can receive is the transform resolution (i.e. every transform resulted in a vote), the highest score a circle can receive is 1.0. Thus, the lower the score threshold, the more tolerant the search will be of incomplete and/or imperfect circles.<br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series (NOTE: This option can be turned off in Advanced Mode: see "Reduce transform resolution"). Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1000.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.0.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this option is selected by default.<br />
<br />
----<br />
<br />
=== Local Search Parameters ===<br />
When using a Hough Transform to track circular objects over time, such as with pupil dilation or eye tracking, it is highly inefficient to calculate the full Hough Space and then search the full Hough space, since you know the object in the current frame is going to be roughly in the same position and have roughly the same radius as the corresponding object in the previous frame.<br />
<br />
The local search algorithm takes advantage of this ''a priori'' information to greatly reduce the volume of the transform and search space in subsequent frames, allowing for many orders of magnitude increase in processing speed.<br />
<br />
The local search algorithm is comprised of three sub-algorithms, depending on the state of the prior frame:<br />
<br />
'''Full - '''For the first frame, a "full" Hough circle transform (the standard algorithm) is performed to find the initial radius and position of each circular object in the frame (up to the maximum number of circles set). The full Hough transform will also be used if the number of circular objects found in a given frame is 0.<br />
<br />
'''Local - '''If the number of circular objects in the previous frame is greater than or equal to the minimum number of objects set, then the algorithm will use an exclusively local search to find the same circular objects in the next frame. The local algorithm performs a transform of only the nearby Hough space of the object found in the last frame, and then searches only this local space for the same object in the current frame.<br />
<br />
'''Partial Local - ''' If the number of circular objects in the previous frame is less than the minimum number of objects set but greater than 0, then the algorithm will use a a hybrid search. A full Hough transform will be performed such that any missing circles will now be found. However, so speed up the search, the algorithm will first search locally within the Hough space for the same circular objects found in the previous frame, and then will search the entire Hough space for any remaining circular objects.<br />
<br />
<br />
[[File:Local Search.png|thumb|1000px|center|'''Local versus full Hough transform.''' <br />
<br />
The left panel shows the input data with a single circle in the center of the image with a radius of 50 pixels. The center panel shows orthogonal projections of the full 3D Hough space. The radius search range was 10-110 pixels. The left panel shows a local Hough transform of the same circle, with a search area of 20x20 pixels, and a radius search range of +/- 10 pixels of the original circle radius. NOTE: In Hough space, the Z-dimension is the radius of the transform.]]<br />
<br />
====''Minimum number of circles to be found''====<br />
<br />
This value represents the minimum number of circles the Hough circle transform will search for before switching to using the partial or full search algorithms to find missing circles. For example, if the transform found 20 circles in the first frame, and the minimum is set to 10, then the algorithm will tolerate loosing track of 10 of the original circles before searching the full Hough space for the missing circles. <br />
<br />
====''Local radius search bandwidth (+/- previous radius)''==== <br />
<br />
This value allows you to set the Z-axis of the local Hough search space. For example, if in your data you do not expect the radius of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same radius as in the previous frame +/- 10 pixels.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to the total radius search range (maximum search radius - minimum search radius).<br />
<br />
====''Local search radius for position of next centroid''==== <br />
<br />
This value allows you to set the x,y axis search radius. For example, if in your data you do not expect the position of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same position as in the previous frame +/- 10 pixels.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to the minimum search radius.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently. However, while the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
NOTE: This option is only available in advanced mode. this value defaults to 1.0. <br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
NOTE: Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30248Hough Circle Transform2017-04-19T05:27:01Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform: '''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform: '''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. Since the Hough space search starts with the highest scoring circle, and then the second highest, and so on, if there are a greater number of circles with<br />
a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. ratio of votes) that a circle can have to count as a valid object. This value is described as the following ratio: <br />
:<math>\text{Hough score}=\left ( \frac{\text{number of votes}}{\text{transform resolution}} \right )</math><br />
Since the maximum number of votes a circle can receive is the transform resolution (i.e. every transform resulted in a vote), the highest score a circle can receive is 1.0. Thus, the lower the score threshold, the more tolerant the search will be of incomplete and/or imperfect circles.<br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series (NOTE: This option can be turned off in Advanced Mode: see "Reduce transform resolution"). Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1000.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.0.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this option is selected by default.<br />
<br />
----<br />
<br />
=== Local Search Parameters ===<br />
When using a Hough Transform to track circular objects over time, such as with pupil dilation or eye tracking, it is highly inefficient to calculate the full Hough Space and then search the full Hough space, since you know the object in the current frame is going to be roughly in the same position and have roughly the same radius as the corresponding object in the previous frame.<br />
<br />
The local search algorithm takes advantage of this ''a priori'' information to greatly reduce the volume of the transform and search space in subsequent frames, allowing for many orders of magnitude increase in processing speed.<br />
<br />
The local search algorithm is comprised of three sub-algorithms, depending on the state of the prior frame:<br />
<br />
'''Full - '''For the first frame, a "full" Hough circle transform (the standard algorithm) is performed to find the initial radius and position of each circular object in the frame (up to the maximum number of circles set). The full Hough transform will also be used if the number of circular objects found in a given frame is 0.<br />
<br />
'''Local - '''If the number of circular objects in the previous frame is greater than or equal to the minimum number of objects set, then the algorithm will use an exclusively local search to find the same circular objects in the next frame. The local algorithm performs a transform of only the nearby Hough space of the object found in the last frame, and then searches only this local space for the same object in the current frame.<br />
<br />
'''Partial Local - ''' If the number of circular objects in the previous frame is less than the minimum number of objects set but greater than 0, then the algorithm will use a a hybrid search. A full Hough transform will be performed such that any missing circles will now be found. However, so speed up the search, the algorithm will first search locally within the Hough space for the same circular objects found in the previous frame, and then will search the entire Hough space for any remaining circular objects.<br />
<br />
<br />
[[File:Local Search.png|thumb|1000px|center|'''Local versus full Hough transform.''' <br />
<br />
The left panel shows the input data with a single circle in the center of the image with a radius of 50 pixels. The center panel shows orthogonal projections of the full 3D Hough space. The radius search range was 10-110 pixels. The left panel shows a local Hough transform of the same circle, with a search area of 20x20 pixels, and a radius search range of +/- 10 pixels of the original circle radius. NOTE: In Hough space, the Z-dimension is the radius of the transform.]]<br />
<br />
====''Minimum number of circles to be found''====<br />
<br />
This value represents the minimum number of circles the Hough circle transform will search for before switching to using the partial or full search algorithms to find missing circles. For example, if the transform found 20 circles in the first frame, and the minimum is set to 10, then the algorithm will tolerate loosing track of 10 of the original circles before searching the full Hough space for the missing circles. <br />
<br />
====''Local radius search bandwidth (+/- previous radius)''==== <br />
<br />
This value allows you to set the Z-axis of the local Hough search space. For example, if in your data you do not expect the radius of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same radius as in the previous frame +/- 10 pixels.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to the total radius search range (maximum search radius - minimum search radius).<br />
<br />
====''Local search radius for position of next centroid:''==== <br />
<br />
This value allows you to set the x,y axis search radius. For example, if in your data you do not expect the position of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same position as in the previous frame +/- 10 pixels.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to the minimum search radius.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently. However, while the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
NOTE: This option is only available in advanced mode. this value defaults to 1.0. <br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
NOTE: Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30245Hough Circle Transform2017-04-19T05:25:48Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform: '''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform: '''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. Since the Hough space search starts with the highest scoring circle, and then the second highest, and so on, if there are a greater number of circles with<br />
a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. ratio of votes) that a circle can have to count as a valid object. This value is described as the following ratio: <br />
:<math>\text{Hough score}=\left ( \frac{\text{number of votes}}{\text{transform resolution}} \right )</math><br />
Since the maximum number of votes a circle can receive is the transform resolution (i.e. every transform resulted in a vote), the highest score a circle can receive is 1.0. Thus, the lower the score threshold, the more tolerant the search will be of incomplete and/or imperfect circles.<br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series (NOTE: This option can be turned off in Advanced Mode: see "Reduce transform resolution"). Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1000.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.0.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this option is selected by default.<br />
<br />
=== Local Search Parameters ===<br />
When using a Hough Transform to track circular objects over time, such as with pupil dilation or eye tracking, it is highly inefficient to calculate the full Hough Space and then search the full Hough space, since you know the object in the current frame is going to be roughly in the same position and have roughly the same radius as the corresponding object in the previous frame.<br />
<br />
The local search algorithm takes advantage of this ''a priori'' information to greatly reduce the volume of the transform and search space in subsequent frames, allowing for many orders of magnitude increase in processing speed.<br />
<br />
The local search algorithm is comprised of three sub-algorithms, depending on the state of the prior frame:<br />
<br />
'''Full - '''For the first frame, a "full" Hough circle transform (the standard algorithm) is performed to find the initial radius and position of each circular object in the frame (up to the maximum number of circles set). The full Hough transform will also be used if the number of circular objects found in a given frame is 0.<br />
<br />
'''Local - '''If the number of circular objects in the previous frame is greater than or equal to the minimum number of objects set, then the algorithm will use an exclusively local search to find the same circular objects in the next frame. The local algorithm performs a transform of only the nearby Hough space of the object found in the last frame, and then searches only this local space for the same object in the current frame.<br />
<br />
'''Partial Local - ''' If the number of circular objects in the previous frame is less than the minimum number of objects set but greater than 0, then the algorithm will use a a hybrid search. A full Hough transform will be performed such that any missing circles will now be found. However, so speed up the search, the algorithm will first search locally within the Hough space for the same circular objects found in the previous frame, and then will search the entire Hough space for any remaining circular objects.<br />
<br />
<br />
[[File:Local Search.png|thumb|1000px|center|'''Local versus full Hough transform.''' <br />
<br />
The left panel shows the input data with a single circle in the center of the image with a radius of 50 pixels. The center panel shows orthogonal projections of the full 3D Hough space. The radius search range was 10-110 pixels. The left panel shows a local Hough transform of the same circle, with a search area of 20x20 pixels, and a radius search range of +/- 10 pixels of the original circle radius. NOTE: In Hough space, the Z-dimension is the radius of the transform.]]<br />
<br />
====''Minimum number of circles to be found''====<br />
<br />
This value represents the minimum number of circles the Hough circle transform will search for before switching to using the partial or full search algorithms to find missing circles. For example, if the transform found 20 circles in the first frame, and the minimum is set to 10, then the algorithm will tolerate loosing track of 10 of the original circles before searching the full Hough space for the missing circles. <br />
<br />
====''Local radius search bandwidth (+/- previous radius)''==== <br />
<br />
This value allows you to set the Z-axis of the local Hough search space. For example, if in your data you do not expect the radius of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same radius as in the previous frame +/- 10 pixels.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to the total radius search range (maximum search radius - minimum search radius).<br />
<br />
====''Local search radius for position of next centroid:''==== <br />
<br />
This value allows you to set the x,y axis search radius. For example, if in your data you do not expect the position of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same position as in the previous frame +/- 10 pixels.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to the minimum search radius.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently. However, while the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
NOTE: This option is only available in advanced mode. this value defaults to 1.0. <br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
NOTE: Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30242Hough Circle Transform2017-04-19T05:22:51Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform: '''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform: '''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. Since the Hough space search starts with the highest scoring circle, and then the second highest, and so on, if there are a greater number of circles with<br />
a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. ratio of votes) that a circle can have to count as a valid object. This value is described as the following ratio: <br />
:<math>\text{Hough score}=\left ( \frac{\text{number of votes}}{\text{transform resolution}} \right )</math><br />
Since the maximum number of votes a circle can receive is the transform resolution (i.e. every transform resulted in a vote), the highest score a circle can receive is 1.0. Thus, the lower the score threshold, the more tolerant the search will be of incomplete and/or imperfect circles.<br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series (NOTE: This option can be turned off in Advanced Mode: see "Reduce transform resolution"). Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1000.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.0.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this option is selected by default.<br />
<br />
=== Local Search Parameters ===<br />
When using a Hough Transform to track circular objects over time, such as with pupil dilation or eye tracking, it is highly inefficient to calculate the full Hough Space and then search the full Hough space, since you know the object in the current frame is going to be roughly in the same position and have roughly the same radius as the corresponding object in the previous frame.<br />
<br />
The local search algorithm takes advantage of this ''a priori'' information to greatly reduce the volume of the transform and search space in subsequent frames, allowing for many orders of magnitude increase in processing speed.<br />
<br />
The local search algorithm is comprised of three sub-algorithms, depending on the state of the prior frame:<br />
<br />
'''Full - '''For the first frame, a "full" Hough circle transform (the standard algorithm) is performed to find the initial radius and position of each circular object in the frame (up to the maximum number of circles set). The full Hough transform will also be used if the number of circular objects found in a given frame is 0.<br />
<br />
'''Local - '''If the number of circular objects in the previous frame is greater than or equal to the minimum number of objects set, then the algorithm will use an exclusively local search to find the same circular objects in the next frame. The local algorithm performs a transform of only the nearby Hough space of the object found in the last frame, and then searches only this local space for the same object in the current frame.<br />
<br />
'''Partial Local - ''' If the number of circular objects in the previous frame is less than the minimum number of objects set but greater than 0, then the algorithm will use a a hybrid search. A full Hough transform will be performed such that any missing circles will now be found. However, so speed up the search, the algorithm will first search locally within the Hough space for the same circular objects found in the previous frame, and then will search the entire Hough space for any remaining circular objects.<br />
<br />
<br />
[[File:Local Search.png|thumb|1000px|center|'''Local versus full Hough transform.''' <br />
<br />
The left panel shows the input data with a single circle in the center of the image with a radius of 50 pixels. The center panel shows orthogonal projections of the full 3D Hough space. The radius search range was 10-110 pixels. The left panel shows a local Hough transform of the same circle, with a search area of 20x20 pixels, and a radius search range of +/- 10 pixels of the original circle radius. NOTE: In Hough space, the Z-dimension is the radius of the transform.]]<br />
<br />
====''Minimum number of circles to be found''====<br />
<br />
This value represents the minimum number of circles the Hough circle transform will search for before switching to using the partial or full search algorithms to find missing circles. For example, if the transform found 20 circles in the first frame, and the minimum is set to 10, then the algorithm will tolerate loosing track of 10 of the original circles before searching the full Hough space for the missing circles. <br />
<br />
====''Local radius search bandwidth (+/- previous radius)''==== <br />
<br />
This value allows you to set the Z-axis of the local Hough search space. For example, if in your data you do not expect the radius of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same radius as in the previous frame +/- 10 pixels.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to the total radius search range (maximum search radius - minimum search radius).<br />
<br />
====''Local search radius for position of next centroid:''==== <br />
<br />
This value allows you to set the x,y axis search radius. For example, if in your data you do not expect the position of any circular object to change by more than 10 pixels in a single frame, then you would narrow the local search by entering 10. The local search will then search for a circular object of the same position as in the previous frame +/- 10 pixels.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently. However, while the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
NOTE: This option is only available in advanced mode. this value defaults to 1.0. <br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
NOTE: Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30239Hough Circle Transform2017-04-19T04:24:10Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform: '''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform: '''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. ratio of votes) that a circle can have to count as a valid object. This value is described as the following ratio: <br />
:<math>\text{Hough score}=\left ( \frac{\text{number of votes}}{\text{transform resolution}} \right )</math><br />
Since the maximum number of votes a circle can receive is the transform resolution (i.e. every transform resulted in a vote), the highest score a circle can receive is 1.0. Thus, the lower the score threshold, the more tolerant the search will be of incomplete and/or imperfect circles.<br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series (NOTE: This option can be turned off in Advanced Mode: see "Reduce transform resolution"). Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1000.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio (Advanced Mode only)''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.0.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this option is selected by default.<br />
<br />
=== Local Search Parameters ===<br />
When using a Hough Transform to track circular objects over time, such as with pupil dilation or eye tracking, it is highly inefficient to calculate the full Hough Space and then search the full Hough space, since you know the object in the current frame is going to be roughly in the same position and have roughly the same radius as the corresponding object in the previous frame.<br />
<br />
The local search algorithm takes advantage of this ''a priori'' information to greatly reduce the volume of the transform and search space in subsequent frames, allowing for many orders of magnitude increase in processing speed.<br />
<br />
The local search algorithm is comprised of three sub-algorithms, depending on the state of the prior frame:<br />
<br />
'''Full - '''For the first frame, a "full" Hough circle transform (the standard algorithm) is performed to find the initial radius and position of each circular object in the frame (up to the maximum number of circles set). The full Hough transform will also be used if the number of circular objects found in a given frame is 0.<br />
<br />
'''Local - '''If the number of circular objects in the previous frame is greater than or equal to the minimum number of objects set, then the algorithm will use an exclusively local search to find the same circular objects in the next frame. The local algorithm performs a transform of only the nearby Hough space of the object found in the last frame, and then searches only this local space for the same object in the current frame.<br />
<br />
'''Partial Local - ''' If the number of circular objects in the previous frame is less than the minimum number of objects set but greater than 0, then the algorithm will use a a hybrid search. A full Hough transform will be performed such that any missing circles will now be found. However, so speed up the search, the algorithm will first search locally within the Hough space for the same circular objects found in the previous frame, and then will search the entire Hough space for any remaining circular objects.<br />
<br />
<br />
[[File:Local Search.png|thumb|1000px|center|'''Local versus full Hough transform.''' <br />
<br />
The left panel shows the input data with a single circle in the center of the image with a radius of 50 pixels. The center panel shows orthogonal projections of the full 3D Hough space. The radius search range was 10-110 pixels. The left panel shows a local Hough transform of the same circle, with a search area of 20x20 pixels, and a radius search range of +/- 10 pixels of the original circle radius. NOTE: In Hough space, the Z-dimension is the radius of the transform.]]<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently. However, while the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
NOTE: This option is only available in advanced mode. <br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
NOTE: Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30236Hough Circle Transform2017-04-19T04:21:57Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform: '''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform: '''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. ratio of votes) that a circle can have to count as a valid object. This value is described as the following ratio: <br />
:<math>\text{Hough score}=\left ( \frac{\text{number of votes}}{\text{transform resolution}} \right )</math><br />
Since the maximum number of votes a circle can receive is the transform resolution (i.e. every transform resulted in a vote), the highest score a circle can receive is 1.0. Thus, the lower the score threshold, the more tolerant the search will be of incomplete and/or imperfect circles.<br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series (NOTE: This option can be turned off in Advanced Mode: see "Reduce transform resolution"). Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1000.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio (Advanced Mode only)''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.0.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this option is selected by default.<br />
<br />
=== Local Search Parameters ===<br />
When using a Hough Transform to track circular objects over time, such as with pupil dilation or eye tracking, it is highly inefficient to calculate the full Hough Space and then search the full Hough space, since you know the object in the current frame is going to be roughly in the same position and have roughly the same radius as the corresponding object in the previous frame.<br />
<br />
The local search algorithm takes advantage of this ''a priori'' information to greatly reduce the volume of the transform and search space in subsequent frames, allowing for many orders of magnitude increase in processing speed.<br />
<br />
The local search algorithm is comprised of three sub-algorithms, depending on the state of the prior frame:<br />
<br />
'''Full - '''For the first frame, a "full" Hough circle transform (the standard algorithm) is performed to find the initial radius and position of each circular object in the frame (up to the maximum number of circles set). The full Hough transform will also be used if the number of circular objects found in a given frame is 0.<br />
<br />
'''Local - '''If the number of circular objects in the previous frame is greater than or equal to the minimum number of objects set, then the algorithm will use an exclusively local search to find the same circular objects in the next frame. The local algorithm performs a transform of only the nearby Hough space of the object found in the last frame, and then searches only this local space for the same object in the current frame.<br />
<br />
'''Partial Local - ''' If the number of circular objects in the previous frame is less than the minimum number of objects set but greater than 0, then the algorithm will use a a hybrid search. A full Hough transform will be performed such that any missing circles will now be found. However, so speed up the search, the algorithm will first search locally within the Hough space for the same circular objects found in the previous frame, and then will search the entire Hough space for any remaining circular objects.<br />
<br />
<br />
[[File:Local Search.png|thumb|1000px|center|'''Local versus full Hough transform.''' <br />
<br />
The left panel shows the input data with a single circle in the center of the image with a radius of 50 pixels. The center panel shows orthogonal projections of the full 3D Hough space. The radius search range was 10-110 pixels. The left panel shows a local Hough transform of the same circle, with a search area of 20x20 pixels, and a radius search range of +/- 10 pixels of the original circle radius.]]<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently. However, while the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
NOTE: This option is only available in advanced mode. <br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
'''Note''': Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=File:Local_Search.png&diff=30235File:Local Search.png2017-04-19T04:14:59Z<p>Llamero: This figure compares the full Hough transform versus the local Hough transform, showing the greatly increased efficiency of only searching the local Hough space.</p>
<hr />
<div>== Summary ==<br />
This figure compares the full Hough transform versus the local Hough transform, showing the greatly increased efficiency of only searching the local Hough space.<br />
== Licensing ==<br />
{{cc-by-sa-4.0}}</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30232Hough Circle Transform2017-04-19T04:13:15Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform: '''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform: '''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. ratio of votes) that a circle can have to count as a valid object. This value is described as the following ratio: <br />
:<math>\text{Hough score}=\left ( \frac{\text{number of votes}}{\text{transform resolution}} \right )</math><br />
Since the maximum number of votes a circle can receive is the transform resolution (i.e. every transform resulted in a vote), the highest score a circle can receive is 1.0. Thus, the lower the score threshold, the more tolerant the search will be of incomplete and/or imperfect circles.<br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series (NOTE: This option can be turned off in Advanced Mode: see "Reduce transform resolution"). Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1000.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio (Advanced Mode only)''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.0.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this option is selected by default.<br />
<br />
=== Local Search Parameters ===<br />
When using a Hough Transform to track circular objects over time, such as with pupil dilation or eye tracking, it is highly inefficient to calculate the full Hough Space and then search the full Hough space, since you know the object in the current frame is going to be roughly in the same position and have roughly the same radius as the corresponding object in the previous frame.<br />
<br />
The local search algorithm takes advantage of this ''a priori'' information to greatly reduce the volume of the transform and search space in subsequent frames, allowing for many orders of magnitude increase in processing speed.<br />
<br />
The local search algorithm is comprised of three sub-algorithms, depending on the state of the prior frame:<br />
<br />
'''Full - '''For the first frame, a "full" Hough circle transform (the standard algorithm) is performed to find the initial radius and position of each circular object in the frame (up to the maximum number of circles set). The full Hough transform will also be used if the number of circular objects found in a given frame is 0.<br />
<br />
'''Local - '''If the number of circular objects in the previous frame is greater than or equal to the minimum number of objects set, then the algorithm will use an exclusively local search to find the same circular objects in the next frame. The local algorithm performs a transform of only the nearby Hough space of the object found in the last frame, and then searches only this local space for the same object in the current frame.<br />
<br />
'''Partial Local - ''' If the number of circular objects in the previous frame is less than the minimum number of objects set but greater than 0, then the algorithm will use a a hybrid search. A full Hough transform will be performed such that any missing circles will now be found. However, so speed up the search, the algorithm will first search locally within the Hough space for the same circular objects found in the previous frame, and then will search the entire Hough space for any remaining circular objects.<br />
<br />
<br />
[[File:Local Search.png|thumb|1000px|center|'''Local versus full Hough transform.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently. However, while the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
NOTE: This option is only available in advanced mode. <br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
'''Note''': Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30229Hough Circle Transform2017-04-19T02:35:30Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform: '''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform: '''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. ratio of votes) that a circle can have to count as a valid object. This value is described as the following ratio: <br />
:<math>\text{Hough score}=\left ( \frac{\text{number of votes}}{\text{transform resolution}} \right )</math><br />
Since the maximum number of votes a circle can receive is the transform resolution (i.e. every transform resulted in a vote), the highest score a circle can receive is 1.0. Thus, the lower the score threshold, the more tolerant the search will be of incomplete and/or imperfect circles.<br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series (NOTE: This option can be turned off in Advanced Mode: see "Reduce transform resolution"). Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1000.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio (Advanced Mode only)''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this value defaults to 1.0.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
NOTE: This option is only available in advanced mode. In easy mode, this option is selected by default.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently. However, while the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
NOTE: This option is only available in advanced mode. <br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
'''Note''': Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30224Hough Circle Transform2017-04-19T02:28:40Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform: '''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform: '''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment (Advanced Mode only)''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found (Advanced Mode only)''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. ratio of votes) that a circle can have to count as a valid object. This value is described as the following ratio: <br />
:<math>\text{Hough score}=\left ( \frac{\text{number of votes}}{\text{transform resolution}} \right )</math><br />
Since the maximum number of votes a circle can receive is the transform resolution (i.e. every transform resulted in a vote), the highest score a circle can receive is 1.0. Thus, the lower the score threshold, the more tolerant the search will be of incomplete and/or imperfect circles.<br />
<br />
====''Hough transform resolution (Advanced Mode only)''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series (NOTE: This option can be turned off in Advanced Mode: see "Reduce transform resolution"). Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio (Advanced Mode only)''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution (Advanced Mode only)''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series (Advanced Mode Only)''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
Warning: Even though the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
'''Note''': Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30221Hough Circle Transform2017-04-19T00:17:37Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform: '''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform: '''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment (Advanced Mode Only)''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found (Advanced Mode Only)''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. ratio of votes) that a circle can have to count as a valid object. This value is described as the following ratio: <br />
:<math>\text{Hough score}=\left ( \frac{\text{number of votes}}{\text{transform resolution}} \right )</math><br />
Since the maximum number of votes a circle can receive is the transform resolution (i.e. every transform resulted in a vote), the highest score a circle can receive is 1.0. Thus, the lower the score threshold, the more tolerant the search will be of incomplete and/or imperfect circles.<br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series (Advanced Mode Only)''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
Warning: Even though the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
'''Note''': Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30154Hough Circle Transform2017-04-18T22:07:27Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform'''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform'''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
----<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment (Advanced Mode Only)''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found (Advanced Mode Only)''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series (Advanced Mode Only)''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
Warning: Even though the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
'''Note''': Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30151Hough Circle Transform2017-04-18T22:06:14Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform'''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform'''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== ''Easy Mode'' ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== ''Advanced Mode'' ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment (Advanced Mode Only)''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found (Advanced Mode Only)''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series (Advanced Mode Only)''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
Warning: Even though the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
'''Note''': Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30148Hough Circle Transform2017-04-18T22:05:16Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform'''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform'''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
===GUI Mode===<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
==== Easy Mode ====<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
==== Advanced Mode ====<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment (Advanced Mode Only)''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found (Advanced Mode Only)''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series (Advanced Mode Only)''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
Warning: Even though the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
'''Note''': Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30145Hough Circle Transform2017-04-18T22:03:59Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform'''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform'''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
==GUI Mode==<br />
The GUI has two available modes, "Easy" and "Advanced." <br />
<br />
=== Easy Mode ===<br />
This mode uses the minimal number of user input values necessary to run the transform. The remaining parameters are all defaulted to the most conservative values, such that all circles matching the criteria are found. To retrieve the default values, run the GUI in easy mode with the recorder turned on: {{bc | Plugins | Macros | Record...}} This will return the value for every argument used in the search.<br />
<br />
=== Advanced Mode ===<br />
This mode is intended for a more fine tuned search, such as to better adapt the search space to your data, and/or increase the speed of the Hough transform. In this mode, all of the available search parameters are available, and the option to see the Raw Hough transform output also becomes available.<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment (Advanced Mode Only)''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
In easy mode, this value defaults to 1.<br />
<br />
====''Maximum number of circles to be found (Advanced Mode Only)''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. This value is capped at 65535, since this is the largest number of circle IDs that can be generated at a 16-bit resolution.<br />
<br />
In easy mode, this value defaults to 65535.<br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series (Advanced Mode Only)''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
Warning: Even though the scores are down-sampled to an 8-bit scale, a Hough transform adds an extra dimension to your dataset, so be sure you will have sufficient RAM if your movie and search space are large.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins | UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
'''Note''': Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30142Hough Circle Transform2017-04-18T21:26:42Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform'''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform'''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png|thumb|1000px|center|'''Hough Circle Transform GUI configurations''' ''Panel 1:'' Hough Circle transform - Easy Mode ''Panel 2:'' Hough Circle transform - Advanced Mode ''Panel 3:'' Local Hough Circle transform - Easy Mode ''Panel 4:'' Local Hough Circle transform - Advanced Mode ]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins |UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
'''Note''': Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=File:Hough_GUI2.png&diff=30141File:Hough GUI2.png2017-04-18T21:22:52Z<p>Llamero: Llamero uploaded a new version of File:Hough GUI2.png</p>
<hr />
<div>== Licensing ==<br />
{{cc-by-sa-4.0}}</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30136Hough Circle Transform2017-04-18T19:56:51Z<p>Llamero: /* Running the Hough Circle Transform Plugin */</p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space. The plugin can be cancelled at any time by either pressing the "Cancel" button in the GUI or pressing the "Escape" key.<br />
<br />
The plugin has two separate algorithms available:<br />
<br />
'''Full Hough Transform'''<br />
This algorithm performs a full Hough circle transform on every frame. The algorithm then searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, the Hough transform space is cleared out around the found circle to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
'''Local Hough Transform'''<br />
This algorithm is designed for high-speed tracking of circles in a time-lapse series. The algorithm performs the full Hough circle transform on the first frame to find the initial radius and position of each circle. In subsequent frames, the algorithm then only performs a Hough transform near the centroid of each circle in subsequent frames. If the number of found circles drops below the minimum number of specified circles, the algorithm performs a full Hough circle transform on the next frame to try and find any circles missed in the local search.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins |UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
'''Note''': Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=File:Data_Setup.png&diff=30115File:Data Setup.png2017-04-17T19:07:31Z<p>Llamero: Llamero uploaded a new version of File:Data Setup.png</p>
<hr />
<div>This figure shows the data processing steps performed to run a Hough circle transform. ''Panel 1'' shows an average intensity projection of an XYZ stack of fluorescent microspheres. ''Panel 2'' shows the derivative of panel 1 (i.e. "Find Edges"). ''Panel 3'' is a mask of panel 2. ''Panel 4'' shows the result of the plugin being run on panel 3.<br />
<br />
== Licensing ==<br />
{{cc-by-sa-4.0}}</div>Llamerohttps://imagej.net/index.php?title=Quiver_Plot&diff=30100Quiver Plot2017-04-12T03:04:05Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Quiver Plot<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source = {{GitHub|org=llamero|repo=Quiver_Plot}}<br />
| released = January 11<sup>th</sup>, 2017<br />
| latest version = March 17<sup>th</sup>, 2017 (v0.2.0)<br />
| status = stable, active<br />
| category = [[:Category:Visualization|Visualization]]<br />
}}<br />
<br />
== Introduction ==<br />
A quiver plot is a 2D array of vector arrows that can be used to visualize dynamic processes such as flow or wave propagation. Vectors have both magnitude and direction; therefore to generate a vector plot, there needs to be a corresponding 2D array of the direction of each vector, and a 2D array of the magnitude of each vector.<br />
<br />
[[File:Intro Quiver Plot Image.jpg|thumb|1000px|center|'''Intro to generating a quiver plot''' From left to right: The original data showing a wave moving through time (blue = start time, red = end time). Vector analysis was performed on the wave to generate a corresponding array of vector angles and vector speeds for points in space. (NOTE: The actual pixel values in these images needs to be the angle in degrees, and the magnitude of the vector). The Quiver Plot plugin was then used to make a quiver plot based off of the angle and speed arrays.]]<br />
<br />
== Running the Quiver Plot Plugin ==<br />
<br />
The Quiver Plot plugin needs two 32-bit images, one representing the vector angles (direction) and one representing the vector magnitude. When you run the plugin, you will see the following window:<br />
<br />
[[File:Quiver_Plot_Plugin_GUI.png]]<br />
<br />
There are two drop-down menus that list all of the currently open windows. Of these windows, select the images that correspond to the angle map and magnitude map (i.e. speed, intensity, etc.). NOTE: pixels with a value of NaN will generate erratic vectors. Make sure that there are no NaN values with your images before using the plugin.<br />
<br />
The third option allows you to set the resolution of plot (i.e. the pixel dimensions of the final plot.).<br />
<br />
The plugin will then search for the largest magnitude vector in the magnitude image, and scale all of the vectors relative to the largest vector. This means that the vector lengths are relative, and therefore the vector lengths between any two plots are not cross-comparable.<br />
<br />
This plugin is also recordable within ImageJ, and can be implemented as part of a macro.<br />
<br />
== Installing the Quiver Plot Plugin == <br />
<br />
The Quiver Plot plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins |UCB Vision Sciences | Quiver Plot}}.<br />
<br />
'''Note''': Quiver Plot is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Visualization]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=30092Hough Circle Transform2017-04-12T02:15:49Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is part of the [[UCB Vision Sciences]] library. To install it, you just need to [[How_to_follow_a_3rd_party_update_site#Add_update_sites | add]] the UCB Vision Sciences update site:<br />
<br />
1) Select {{bc | Help | Update...}} from the Fiji menu to start the updater.<br />
<br />
2) Click on ''Manage update sites''. This brings up a dialog where you can activate additional update sites.<br />
<br />
3) Activate the [[UCB Vision Sciences]] update site and close the dialog. Now you should see additional jar files for download.<br />
<br />
4) Click ''Apply changes'' and restart Fiji.<br />
<br />
You should now find the plugin under the sub-menu {{bc | Plugins |UCB Vision Sciences | Hough Circle Transform}}.<br />
<br />
'''Note''': Hough Circle Transform is only one of the plugins included in the [[UCB Vision Sciences]] suite. By following these installation steps, you will be installing as well the rest of plugins in the suite.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=29029Hough Circle Transform2017-03-18T07:11:46Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Local_Hough_Circle}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = March 18<sup>th</sup>, 2017 (v0.8.0)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is a stand alone plugin that needs to be installed manually. To install the plugin, use the following steps:<br />
<br />
1) Go to the [https://github.com/Llamero/Local_Hough_Circle/releases/tag/0.8.0 Github link] and download the file.<br />
<br />
2) Copy the file into the Plugins folder for ImageJ/FIJI.<br />
<br />
3) Restart ImageJ/FIJI and the plugin will automatically show up in the plugin menu: {{bc | Plugins |Hough Circle Transform}}.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Quiver_Plot&diff=29026Quiver Plot2017-03-18T07:00:09Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Quiver Plot<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source = {{GitHub|org=llamero|repo=Quiver_Plot}}<br />
| released = January 11<sup>th</sup>, 2017<br />
| latest version = March 17<sup>th</sup>, 2017 (v0.2.0)<br />
| status = stable, active<br />
| category = [[:Category:Visualization|Visualization]]<br />
}}<br />
<br />
== Introduction ==<br />
A quiver plot is a 2D array of vector arrows that can be used to visualize dynamic processes such as flow or wave propagation. Vectors have both magnitude and direction; therefore to generate a vector plot, there needs to be a corresponding 2D array of the direction of each vector, and a 2D array of the magnitude of each vector.<br />
<br />
[[File:Intro Quiver Plot Image.jpg|thumb|1000px|center|'''Intro to generating a quiver plot''' From left to right: The original data showing a wave moving through time (blue = start time, red = end time). Vector analysis was performed on the wave to generate a corresponding array of vector angles and vector speeds for points in space. (NOTE: The actual pixel values in these images needs to be the angle in degrees, and the magnitude of the vector). The Quiver Plot plugin was then used to make a quiver plot based off of the angle and speed arrays.]]<br />
<br />
== Running the Quiver Plot Plugin ==<br />
<br />
The Quiver Plot plugin needs two 32-bit images, one representing the vector angles (direction) and one representing the vector magnitude. When you run the plugin, you will see the following window:<br />
<br />
[[File:Quiver_Plot_Plugin_GUI.png]]<br />
<br />
There are two drop-down menus that list all of the currently open windows. Of these windows, select the images that correspond to the angle map and magnitude map (i.e. speed, intensity, etc.). NOTE: pixels with a value of NaN will generate erratic vectors. Make sure that there are no NaN values with your images before using the plugin.<br />
<br />
The third option allows you to set the resolution of plot (i.e. the pixel dimensions of the final plot.).<br />
<br />
The plugin will then search for the largest magnitude vector in the magnitude image, and scale all of the vectors relative to the largest vector. This means that the vector lengths are relative, and therefore the vector lengths between any two plots are not cross-comparable.<br />
<br />
This plugin is also recordable within ImageJ, and can be implemented as part of a macro.<br />
<br />
== Installing the Quiver Plot Plugin == <br />
<br />
The Quiver Plot plugin is a stand alone plugin that needs to be installed manually. To install the plugin, use the following steps:<br />
<br />
1) Go to the [https://github.com/Llamero/Quiver_Plot/releases/tag/0.2.0 Github link] and download the file: Quiver_Plot-0.2.0-SNAPSHOT.jar<br />
<br />
2) Copy the file into the Plugins folder for ImageJ/FIJI.<br />
<br />
3) Restart ImageJ/FIJI and the plugin will automatically show up in the plugin menu: {{bc | Plugins |Quiver Plot}}.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Visualization]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=27957Hough Circle Transform2017-02-09T00:35:32Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Hough_Circle_Multithread}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = February 7<sup>th</sup>, 2017 (v0.5.2)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is a stand alone plugin that needs to be installed manually. To install the plugin, use the following steps:<br />
<br />
1) Go to the [https://github.com/Llamero/Hough_Circle_Multithread/blob/master/Hough_Circle_Transform-0.5.2-SNAPSHOT.jar Github link] and download the file.<br />
<br />
2) Copy the file into the Plugins folder for ImageJ/FIJI.<br />
<br />
3) Restart ImageJ/FIJI and the plugin will automatically show up in the plugin menu: {{bc | Plugins |Hough Circle Transform}}.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Quiver_Plot&diff=27954Quiver Plot2017-02-09T00:34:51Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Quiver Plot<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source = {{GitHub|org=llamero|repo=Quiver_Plot}}<br />
| released = January 11<sup>th</sup>, 2017<br />
| latest version = January 11<sup>th</sup>, 2017 (v1.0.0)<br />
| status = stable, active<br />
| category = [[:Category:Visualization|Visualization]]<br />
}}<br />
<br />
== Introduction ==<br />
A quiver plot is a 2D array of vector arrows that can be used to visualize dynamic processes such as flow or wave propagation. Vectors have both magnitude and direction; therefore to generate a vector plot, there needs to be a corresponding 2D array of the direction of each vector, and a 2D array of the magnitude of each vector.<br />
<br />
[[File:Intro Quiver Plot Image.jpg|thumb|1000px|center|'''Intro to generating a quiver plot''' From left to right: The original data showing a wave moving through time (blue = start time, red = end time). Vector analysis was performed on the wave to generate a corresponding array of vector angles and vector speeds for points in space. (NOTE: The actual pixel values in these images needs to be the angle in degrees, and the magnitude of the vector). The Quiver Plot plugin was then used to make a quiver plot based off of the angle and speed arrays.]]<br />
<br />
== Running the Quiver Plot Plugin ==<br />
<br />
The Quiver Plot plugin needs two images, one representing the vector angles (direction) and one representing the vector magnitude. When you run the plugin, you will see the following window:<br />
<br />
[[File:Quiver_Plot_Plugin_GUI.png]]<br />
<br />
There are two drop-down menus that list all of the currently open windows. Of these windows, select the images that correspond to the angle map and magnitude map (i.e. speed, intensity, etc.). NOTE: pixels with a value of NaN will generate erratic vectors. Make sure that there are no NaN values with your images before using the plugin.<br />
<br />
The third option allows you to set the resolution of plot (i.e. the pixel dimensions of the final plot.).<br />
<br />
The plugin will then search for the largest magnitude vector in the magnitude image, and scale all of the vectors relative to the largest vector. This means that the vector lengths are relative, and therefore the vector lengths between any two plots are not cross-comparable.<br />
<br />
This plugin is also recordable within ImageJ, and can be implemented as part of a macro.<br />
<br />
== Installing the Quiver Plot Plugin == <br />
<br />
The Quiver Plot plugin is a stand alone plugin that needs to be installed manually. To install the plugin, use the following steps:<br />
<br />
1) Go to the [https://github.com/Llamero/Quiver_Plot Github link] and download the file: Quiver_Plot-1.0.0-SNAPSHOT.jar<br />
<br />
2) Copy the file into the Plugins folder for ImageJ/FIJI.<br />
<br />
3) Restart ImageJ/FIJI and the plugin will automatically show up in the plugin menu: {{bc | Plugins |Quiver Plot}}.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin was developed as part of the University of California, Berkeley Vision Sciences core grant NIH P30EY003176.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Visualization]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=27951Hough Circle Transform2017-02-08T06:31:44Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Hough_Circle_Multithread}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = February 7<sup>th</sup>, 2017 (v0.5.2)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output2.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is a stand alone plugin that needs to be installed manually. To install the plugin, use the following steps:<br />
<br />
1) Go to the [https://github.com/Llamero/Hough_Circle_Multithread/blob/master/Hough_Circle_Transform-0.5.2-SNAPSHOT.jar Github link] and download the file.<br />
<br />
2) Copy the file into the Plugins folder for ImageJ/FIJI.<br />
<br />
3) Restart ImageJ/FIJI and the plugin will automatically show up in the plugin menu: {{bc | Plugins |Hough Circle Transform}}.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=File:Radius_Output2.png&diff=27948File:Radius Output2.png2017-02-08T06:31:14Z<p>Llamero: </p>
<hr />
<div>== Licensing ==<br />
{{cc-by-sa-4.0}}</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=27940Hough Circle Transform2017-02-08T03:25:58Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Hough_Circle_Multithread}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = February 7<sup>th</sup>, 2017 (v0.5.2)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Plugin == <br />
<br />
The Hough Circle Transform plugin is a stand alone plugin that needs to be installed manually. To install the plugin, use the following steps:<br />
<br />
1) Go to the [https://github.com/Llamero/Hough_Circle_Multithread/blob/master/Hough_Circle_Transform-0.5.2-SNAPSHOT.jar Github link] and download the file.<br />
<br />
2) Copy the file into the Plugins folder for ImageJ/FIJI.<br />
<br />
3) Restart ImageJ/FIJI and the plugin will automatically show up in the plugin menu: {{bc | Plugins |Hough Circle Transform}}.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=27937Hough Circle Transform2017-02-08T03:24:10Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Hough_Circle_Multithread}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = February 7<sup>th</sup>, 2017 (v0.5.2)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius:''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment:''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found:''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold:''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution:''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio:''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution:''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output Options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough transform series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Hough Circle Transform Plugin == <br />
<br />
The Hough Circle Transform plugin is a stand alone plugin that needs to be installed manually. To install the plugin, use the following steps:<br />
<br />
1) Go to the [https://github.com/Llamero/Hough_Circle_Multithread/blob/master/Hough_Circle_Transform-0.5.2-SNAPSHOT.jar Github link] and download the file.<br />
<br />
2) Copy the file into the Plugins folder for ImageJ/FIJI.<br />
<br />
3) Restart ImageJ/FIJI and the plugin will automatically show up in the plugin menu: {{bc | Plugins |Hough Circle Transform}}.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=27934Hough Circle Transform2017-02-08T03:22:55Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Hough_Circle_Multithread}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = February 7<sup>th</sup>, 2017 (v0.5.2)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough Circle Transform Plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius:''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment:''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found:''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold:''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution:''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio:''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution:''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough Transform Series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Hough Circle Transform Plugin == <br />
<br />
The Hough Circle Transform plugin is a stand alone plugin that needs to be installed manually. To install the plugin, use the following steps:<br />
<br />
1) Go to the [https://github.com/Llamero/Hough_Circle_Multithread/blob/master/Hough_Circle_Transform-0.5.2-SNAPSHOT.jar Github link] and download the file.<br />
<br />
2) Copy the file into the Plugins folder for ImageJ/FIJI.<br />
<br />
3) Restart ImageJ/FIJI and the plugin will automatically show up in the plugin menu: {{bc | Plugins |Hough Circle Transform}}.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=27931Hough Circle Transform2017-02-08T03:20:50Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Hough_Circle_Multithread}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = February 7<sup>th</sup>, 2017 (v0.5.2)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough circle transform plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius:''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment:''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found:''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold:''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution:''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio:''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution:''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough Transform Series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Hough Circle Transform Plugin == <br />
<br />
The Hough Circle Transform plugin is a stand alone plugin that needs to be installed manually. To install the plugin, use the following steps:<br />
<br />
1) Go to the [https://github.com/Llamero/Hough_Circle_Multithread/blob/master/Hough_Circle_Transform-0.5.2-SNAPSHOT.jar Github link] and download the file.<br />
<br />
2) Copy the file into the Plugins folder for ImageJ/FIJI.<br />
<br />
3) Restart ImageJ/FIJI and the plugin will automatically show up in the plugin menu: {{bc | Plugins |Hough Circle Transform}}.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=27928Hough Circle Transform2017-02-08T02:51:16Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Hough_Circle_Multithread}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = February 7<sup>th</sup>, 2017 (v0.5.2)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough circle transform plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius:''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment:''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found:''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold:''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution:''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio:''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution:''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough Transform Series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Quiver Plot Plugin == <br />
<br />
The Quiver Plot plugin is a stand alone plugin that needs to be installed manually. To install the plugin, use the following steps:<br />
<br />
1) Go to the [https://github.com/Llamero/Hough_Circle_Multithread/blob/master/Hough_Circle_Transform-0.5.2-SNAPSHOT.jar Github link] and download the file.<br />
<br />
2) Copy the file into the Plugins folder for ImageJ/FIJI.<br />
<br />
3) Restart ImageJ/FIJI and the plugin will automatically show up in the plugin menu: {{bc | Plugins |Hough Circle Transform}}.<br />
<br />
== Acknowledgements ==<br />
<br />
This plugin is a modified version of the Hough circle transform implemented by [https://imagej.nih.gov/ij/plugins/hough-circles.html Hemerson Pistori and Eduardo Rocha Costa]. The transform algorithm was based off of an original implementation by [http://www.markschulze.net/ Mark Schulze].<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=27921Hough Circle Transform2017-02-08T02:22:29Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Hough_Circle_Multithread}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = February 7<sup>th</sup>, 2017 (v0.5.2)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough circle transform plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius:''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment:''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found:''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold:''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution:''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio:''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution:''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough Transform Series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Quiver Plot Plugin == <br />
<br />
The Quiver Plot plugin is a stand alone plugin that needs to be installed manually. To install the plugin, use the following steps:<br />
<br />
1) Go to the [https://github.com/Llamero/Hough_Circle_Multithread/blob/master/Hough_Circle_Transform-0.5.2-SNAPSHOT.jar Github link] and download the file.<br />
<br />
2) Copy the file into the Plugins folder for ImageJ/FIJI.<br />
<br />
3) Restart ImageJ/FIJI and the plugin will automatically show up in the plugin menu: {{bc | Plugins |Hough Circle Transform}}.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Analysis]], [[Category:Feature Extraction]]</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=27918Hough Circle Transform2017-02-08T02:21:42Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Hough_Circle_Multithread}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = February 7<sup>th</sup>, 2017 (v0.5.2)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough circle transform plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius:''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment:''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found:''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold:''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution:''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio:''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution:''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough Transform Series''====<br />
[[File:Raw Output.png|thumb|100px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.<br />
<br />
====''Circle centroid(s) marked on the original image''====<br />
[[File:Mask Output.png|thumb|100px|right| ]]<br />
This option will draw a cross-hair pattern on each centroid found within the image, overlaid on a mask of the original image. This output is especially useful for optimizing the Hough seach parameters. The header of the image contains the number of circles that were found within the image. If the inputted data was not a mask, it will calculate a mask with a threshold of 1.<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle radius at centroids (pixel intensity = circle radius)''====<br />
[[File:Radius Output.png|thumb|100px|right| ]]<br />
This option returns an image where the centroid of each circle is marked by a single pixel whose intensity is equal to the radius of the circle, with the header of the image showing the number of circles that was found. To save memory, the image is formatted to 16-bit, meaning that the largest radius it can show is 65535 pixels. If you need to export larger radii, export the results to a results table (see below).<br />
<br />
If the inputted data was a multi-frame stack, then the transform will return a stack, where the Z-dimension is each frame in the movie, and the header will show the number of circles found in each frame.<br />
<br />
====''Map of circle score at centroids (pixel intensity = circle score)''====<br />
This output is identical to the radius output (see above), however the pixel intensity is the Hough Score. To save memory, the image is formatted to 16-bit, meaning that the highest score it can show is 65535.<br />
<br />
====''Export measurements to the results table''====<br />
[[File:Results Output.png|thumb|250px|right| ]]<br />
This will output the results of the transform to the results table. The measurements exported are: 1) the X and Y coordinates of each centroid, 2) the radius (in pixels) of each circle, 3) the Hough score for each circle, 4) the number of circles found within that frame, 5) the actual resolution that the transform used (this is also effectively the highest Hough score possible), and 6) the frame in which the circle was found.<br />
<br />
If no circles were found in a frame, than that frame is excluded from the results table.<br />
<br />
== Installing the Quiver Plot Plugin == <br />
<br />
The Quiver Plot plugin is a stand alone plugin that needs to be installed manually. To install the plugin, use the following steps:<br />
<br />
1) Go to the [https://github.com/Llamero/Hough_Circle_Multithread/blob/master/Hough_Circle_Transform-0.5.2-SNAPSHOT.jar Github link] and download the file.<br />
<br />
2) Copy the file into the Plugins folder for ImageJ/FIJI.<br />
<br />
3) Restart ImageJ/FIJI and the plugin will automatically show up in the plugin menu: {{bc | Plugins |Hough Circle Transform}}.<br />
<br />
== License ==<br />
This program is '''free software'''; you can redistribute it and/or modify it under the terms of the '''GNU General Public License''' as published by the Free Software Foundation ([http://www.gnu.org/licenses/gpl.txt http://www.gnu.org/licenses/gpl.txt]).<br />
<br />
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. <br />
<br />
[[Category:Visualization]]</div>Llamerohttps://imagej.net/index.php?title=File:Results_Output.png&diff=27909File:Results Output.png2017-02-08T02:14:23Z<p>Llamero: </p>
<hr />
<div>== Licensing ==<br />
{{cc-by-sa-4.0}}</div>Llamerohttps://imagej.net/index.php?title=File:Radius_Output.png&diff=27902File:Radius Output.png2017-02-08T02:03:10Z<p>Llamero: </p>
<hr />
<div>== Licensing ==<br />
{{cc-by-sa-4.0}}</div>Llamerohttps://imagej.net/index.php?title=File:Mask_Output.png&diff=27889File:Mask Output.png2017-02-08T01:49:11Z<p>Llamero: </p>
<hr />
<div></div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=27884Hough Circle Transform2017-02-08T01:33:07Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Hough_Circle_Multithread}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = February 7<sup>th</sup>, 2017 (v0.5.1)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough circle transform plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====''Minimum/maximum search radius:''====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====''Radius search increment:''====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====''Maximum number of circles to be found:''====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====''Hough score threshold:''==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====''Hough transform resolution:''====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====''Clear neighbors radius ratio:''====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====''Reduce transform resolution:''====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.<br />
<br />
----<br />
<br />
===Output options:===<br />
The plugin contains several output options to both visualize the transform, as well as export the results of the analysis.<br />
<br />
====''Raw Hough Transform Series''====<br />
[[File:Raw Output.png|thumb|150px|right| ]]<br />
This option will output a stack where each slice is the transform for specified radius. Each slice is also labelled with the radius (in pixels) and resolution in the header. If the inputted data was a multi-frame stack,<br />
then the transform will return a hyperstack, where the Z-dimension is each radius tested, and the T-dimension is each frame in the movie.<br />
<br />
To save memory, the Hough scores are set to an 8-bit scale, with the highest score in the transform search space getting a value of 255 (i.e. no saturation). If the inputted data was a movie, each frame will be rescaled independently.</div>Llamerohttps://imagej.net/index.php?title=File:Raw_Output.png&diff=27869File:Raw Output.png2017-02-08T01:26:08Z<p>Llamero: </p>
<hr />
<div>== Licensing ==<br />
{{cc-by-sa-4.0}}</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=27862Hough Circle Transform2017-02-08T01:07:54Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Hough_Circle_Multithread}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = February 7<sup>th</sup>, 2017 (v0.5.1)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses. The transform effectively searches for objects with a high degree of radial symmetry, with each degree of symmetry receiving one "vote" in the search space. By searching a 3D Hough search space, the transform can measure the centroid and radius of each circlular object in an image.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough circle transform plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====Minimum/maximum search radius:====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====Radius search increment:====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====Maximum number of circles to be found:====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====Hough score threshold:==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====Hough transform resolution====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====Clear neighbors radius ratio:====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]<br />
<br />
====Reduce transform resolution:====<br />
Since all images will be pixels in a Cartesian coordinate system, transforms can only be to discrete integer coordinates (i.e. x=5,y=10). Therefore, with an infinitely fine resolution, then when the next step of a transform is rounded to the nearest integer coordinate, it is possible that these are the same coordinates as the previous transform step. This means that when the transform is performed, it will perform identical transformations for both these steps. <br />
<br />
To speed up a Hough transform, you can find and remove all of the redundant transform steps before performing the transform, keeping only the set of unique transform steps. The plugin performs this check by removing all redundant transform steps for the maximum search radius, and then setting this as the new resolution for the subsequent radii. This means the smaller radii will perform redundant transforms, but this is essential to ensure that each radius gets and equal number of voting rounds (or else large circles will always score higher than small circles).<br />
<br />
While speeding up the algorithm, the trade-off is that the transform steps are distributed anisotropically for the maximum radius (all subsequent radii will be isotropic). Unchecking this box will result in the transform perform all of the specified transform steps, which can be be very computationally intensive for high resolution values.</div>Llamerohttps://imagej.net/index.php?title=Hough_Circle_Transform&diff=27857Hough Circle Transform2017-02-08T00:43:55Z<p>Llamero: </p>
<hr />
<div>{{Infobox<br />
| name = Hough Circle Transform<br />
| software = plugin<br />
| author = {{Person|llamero}}<br />
| maintainer = {{Person|llamero}}<br />
| source ={{GitHub|org=llamero|repo=Hough_Circle_Multithread}}<br />
| released = February 4<sup>th</sup>, 2017<br />
| latest version = February 7<sup>th</sup>, 2017 (v0.5.1)<br />
| status = stable, active<br />
| category = [[:Category:Analysis|Analysis]], [[:Category:Feature Extraction|Feature Extraction]]<br />
}}<br />
<br />
== Introduction ==<br />
A [[wikipedia:Circle Hough Transform|Hough circle transform]] is an image transform that allows for circular objects to be extracted from an image, even if the circle is incomplete. The transform is also selective for circles, and will generally ignore elongated ellipses.<br />
<br />
[[File:Hough_Intro2.png|thumb|1000px|center|'''Hough circle transform is specific to circular objects.''' ''Left Panel:'' This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels).<br />
<br />
''Right Panel:'' This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.]]<br />
<br />
The method works by transforming an image around in a circle. Each time a transformed pixel with an intensity greater than zero lands on a Cartesian coordinate, that coordinate gets one vote. As the image continues to be transformed in a circle of a given radius, if a circle in the image has the same radius, then votes will accumulate at the centroid of this circle. Therefore, by finding the maxima in the transform (points with the highest number of votes) you can find the centroid of circles within the image. A Hough circle transform can also be used to find circles of an unknown radius by searching a 3D transform space, where the the third dimension is the range of radii to be tested. <br />
<br />
== Image Processing Workflow ==<br />
The Hough circle transform finds circles based on the rotational symmetry of the perimeter. Therefore, the data needs to be converted to this format for the transform to work.<br />
<br />
[[File:Data Setup.png|thumb|1000px|center|'''Data processing steps to perform a Hough circle transform on an XYZ stack.''' ''Panel 1:'' Create an average intensity projection of the XYZ stack to generate a 2D projection. ''Panel 2:'' Use the "Find Edges" tool to preserve just the perimeter of each object. ''Panel 3:'' Threshold the image from panel 2 and create a binary mask. ''Panel 4:'' Run the Hough circle transform.]]<br />
<br />
===Step 0: Convert XYZ(T) data to XY(T) data===<br />
If the data is a 3D stack, then collapse the data to 2D space using a maximum, sum, or average intensity projection. The plugin can handle multiple frames (time-points) in a stack, but it can only search in 2D space.<br />
<br />
===Step 1: Find Edges===<br />
If the circular objects are solid rather than hollow, take the derivative of the image by running: {{bc | Process | Find Edges}}. This will preserve just the perimeter of each object.<br />
<br />
===Step 2: Threshold===<br />
The algorithm does not weight the transform based on the intensity of the pixels, as this would result in bright, non-circular objects getting a very high score. Therefore, any pixel with an intensity > 0 is given one vote per transform. This means that any pixel you do not want to be part of the transform needs to be set to zero, which is best done by thresholding the image and creating a mask by running: {{bc | Image | Adjust | Threshold}}. After choosing the right threshold for the data press "Apply" to create a mask with an inverting LUT (0 is white, 255 is black). The LUT can be changed back to a normal gray-scale by going to {{bc | Image | Lookup Tables | Grays}}.<br />
<br />
===Step 3: Run the Hough Transform===<br />
Now you are ready to run the Hough transform (see below for detailed information on the various options). If the number of circles is unknown or varies from frame to frame, then the best option is to set the search to one circle and perform the transform with the output set to show the results table, and the centroids marked on the original image. This will give you the highest Hough score in the whole image, and will allow you to confirm that the circle found is correct and what its score was. If the circle is incorrect, adjust the search parameters to narrow the Hough search space. <br />
<br />
If the circle found is correct, then gradually reduce the threshold until all the circles in the image are found. This will give you the upper threshold bound. Continue to decrease the threshold until an errant circle is detected, this will give you the lower threshold bound. Set the threshold between the upper and lower bounds, and then run the transform on the full data set.<br />
<br />
== Running the Hough circle transform plugin ==<br />
The plugin runs on the current active image, and can also process stacks, but it cannot handle hyperstacks. The plugin is also recordable for macro implementation, and multi-threaded to fast searching on the 3D Hough space.<br />
<br />
A key component to this plugin is that it always searches for the highest scoring circle first, then the second highest, and so on. When a circle is found, all neighboring circles are removed to prevent the same circle from being found repeatedly. This parameter can be adjusted to allow for increasing degrees of overlap between neighboring circles.<br />
<br />
[[File:Hough GUI2.png]]<br />
<br />
=== Search Parameters ===<br />
The Hough circle plugin is designed to be adaptable to a variety of segmentation tasks, and as such, there are seven search parameters that can be adjusted to tune the search space.<br />
<br />
====Minimum/maximum search radius:====<br />
The minimum and maximum search radii are the lower and upper cutoff for the radii you expect to find in the image. Ideally, you want to make the Hough search space as specific as possible, so be sure to set these values to specifically the range of radii you expect to find in your data.<br />
<br />
====Radius search increment:====<br />
This determines the radius step size to use when creating the 3D Hough space from the minimum radius to the maximum radius. This allows a trade-off between speed and resolution, where larger steps will give a linear increase in speed, but also decrease the precision of the measured radii.<br />
<br />
====Maximum number of circles to be found:====<br />
This option sets the upper limit for the number of circles that can be found in the search. If there are fewer than the specified number of circles in the image with a score above the threshold (see below), then the algorithm will only return the number of circles that were above the threshold. <br />
<br />
====Hough score threshold:==== <br />
This option sets the minimum cutoff for the Hough score (i.e. number of votes) that a circle can have to count as a valid object. The search starts with the highest scoring circle, and then the second highest, and so on, so if there are a greater number of circles with a score above the threshold than the limit set in "Maximum number of circles to be found", only the highest scoring circles will be returned. <br />
<br />
NOTE: When the transform resolution is changed (see below) the scores will change to. This is because the resolution sets the number of rounds of voting. Therefore, as the number of voting rounds increases, the score per object will increase as well. <br />
<br />
====Hough transform resolution====<br />
This option sets the number of steps in each circle transform. To reduce unnecessary computation, if the resolution is set arbitrarily high (such as the default value of 1000), the algorithm will automatically find the nearest number of unique transforms possible (i.e. unique integer x,y coordinates) for the maximum radius, and will use this value as the actual resolution in the transform series. Reducing the resolution below the maximum value can greatly speed up the algorithm, but it will also decrease the transform's specificity and sensitivity.<br />
<br />
[[File:Resolution Figure.png|thumb|1000px|center|'''Effect of transform resolution on distinguishing various n-gons.''' <br />
''Panel 1'' shows a circle and three regular polygons: a 4-gon, 8-gon, and 16-gon.<br />
''Panel 2'' shows a Hough circle transform with four steps. Since all the shapes are radially symmetrical with 90° rotations, they all have an equal peak score at their centroids.<br />
<br />
''Panel 3'' shows a Hough circle transform with eight steps. Since the circle, 8-gon, and 16-gon radially symmetrical with 45° rotations, they all have an equal peak score at their centroids. These shapes have a higher score at their centroids than the 4-gon, because it lacks 45° radial symmetry.<br />
<br />
''Panel 4'' shows a Hough circle transform with sixteen steps. Only the circle and 16-gon are radially symmetrical at this resolution, so their centroids have equally high scores, while the 4-gon and 8-gon have significantly lower scores.<br />
<br />
''Panel 5'' shows a Hough circle transform with 400 steps. The centroid of the circle now has a higher score than all of the other shapes, allowing for the circle to be distinguished even from the 16-gon.]]<br />
<br />
====Clear neighbors radius ratio:====<br />
The 3D Hough search space approaches a local maxima. Therefore, when a circle is found, the space around the local maxima needs to be removed to prevent the circle from being found a second time. The radius of the Hough search space that is cleared is defined as a ratio of the radius of the circle found, meaning that large circles clear out more Hough search space than small circles. <br />
<br />
By default, this ratio is set to be one, meaning that a circle of the same size and location as the one found is cleared from the entire search space. This has the effect of eliminating all potential centroids within one radius of the found centroid. This effectively excludes overlapping circles of a similar radius from the search. To allow overlapping circles, this ratio can be reduced. A ratio of "0" will result in the same circle being found repeatedly. This means that perfectly concentric circles cannot be found in one run of the plugin, and rather need to be found iteratively by removing the found circles from the image and re-running the plugin.<br />
<br />
[[File:Clear Ratio2.png|thumb|1000px|center|'''Adjusting the clear radius ratio to find overlapping circles.''' <br />
<br />
The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps).<br />
<br />
The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found.<br />
<br />
The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.]]</div>Llamerohttps://imagej.net/index.php?title=File:Clear_Ratio2.png&diff=27854File:Clear Ratio2.png2017-02-08T00:43:01Z<p>Llamero: Adjusting the clear radius ratio to find overlapping circles. The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps). The top right p...</p>
<hr />
<div>== Summary ==<br />
Adjusting the clear radius ratio to find overlapping circles. The left panel shows the input data with a single circle on top and a pair of overlapping circles below. The next panel shows the resulting Hough circle transform (24 steps). The top right pair of panels show the effect of a clear ratio of 1.0, where when the first overlapping circle is found, the centroid of the neighboring circle is removed, resulting in only two high scoring circles being found. The bottom right pair of panels show the effect of a clear ratio of 0.2, where when the first overlapping circle is found, only its centroid is removed and the neighboring centroid is preserved for the neighboring circle to also be found, resulting in all three circles being found.<br />
== Licensing ==<br />
{{cc-by-sa-4.0}}</div>Llamerohttps://imagej.net/index.php?title=File:Hough_Intro2.png&diff=27849File:Hough Intro2.png2017-02-08T00:29:23Z<p>Llamero: Hough circle transform is specific to circular objects. Left Panel: This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor...</p>
<hr />
<div>Hough circle transform is specific to circular objects. Left Panel: This panel shown the input data for the Hough circle transform. The data includes (clockwise from top left) a circle (radius 37 pixels), a square (length 37 pixels), an ellipse (minor axis 37 pixels), and a sectored circle (radius 37 pixels). Right Panel: This panel shows the output of a 24 step Hough circle transform. As you can see, the circle and the sectored circle converge to local maxima, while the square and ellipse do not, show the specificity of the transform for circular objects.</div>Llamero