# Efficient FPGA Implementation of Automatic Nuclei Detection in Histopathology Images
## 2 Materials and Methods
### Mean-Shift Clustering  
For one nuclear region, there can be more than one candidate nuclei in S [1]. As the candidates corresponding to a nucleus are geometrically close, they can be clustered to obtain one center for each nucleus. In this paper, the nuclei candidates are clustered using a mean-shift (MS) clustering algorithm [7], and center for each nucleus is obtained by calculating the mean coordinate of members of the corresponding cluster. The MS clustering is like a hill climbing algorithm which involves shifting a certain type of kernel iteratively to a higher density region until convergence. This is illustrated in Figure 9, where the nuclei candidates are shown with red dots. To start the algorithm, pick any unvisited candidate, let it be A and place the kernel center at A. Check if any other candidates are within the kernel (of radius \(r\)). In this example, candidate B is within the kernel (see Figure 9b). Calculate the mean of A, B and shift the kernel center to mean position (see Figure 9c). Now re-check if any new candidate is included within the kernel. Figure 9c shows that candidate C is within the kernel. The mean of {A, B, C} is calculated, and the kernel is shifted to the new mean position. The iteration continues until the kernel is settled and no new candidate is included. After convergence, all candidates within the kernel are clustered and the center of the kernel is considered as the nucleus for that cluster. The MS clustering then picks up another unvisited candidate and generates a cluster in a similar manner. The process is continued until all the candidates are clustered. The overall flowchart of the MS clustering is shown in Figure 10.  
Figure 9: Mean shift clustering principles, (**a**) candidates in a binary image, (**b**) Kernel centered at A, (**c**) Kernel centered at mean of A and B, (**d**) kernel centered at mean of A, B and C, (**e**) kernel centered at mean of A, B, C and D. Finally, A, B, C and D clustered into one nucleus. In this paper, the MS kernel is defined as a circle with radius \(r=8\) pixels. The implemented architecture of the MS clustering is shown in Figure 11. The architecture has four modules: _Flag operator_, _Iterator_, _Merger_ and _Data table_. The _Data table_ structure is shown in Table 1, which stores the seed candidates, four intermediate parameters for each candidate (_visit-flag_, _current-round votes_, _maximum votes and cluster number_) and _identified Nuclei_. _Visit-Flag_ identifies candidates that are visited in the clustering process (flag is set to 1 for visited candidates and 0 for unvisited candidates). _Current-round votes_\(V_{c}\) indicate the number of iterations done in current clustering when a candidate is within the kernel geometry. \(V_{c}\) is set to zero at the beginning of each cluster generation. _Maximum votes_\(V_{M}\) store the maximum value of _current-round votes_ a candidate has achieved in all previous cluster generation and the _cluster number_ (\(L\)) denotes the cluster that has obtained maximum votes for a seed candidate. The table entries are updated at the end of each cluster generation. _Identified nuclei_ (\(N\)) stores the center of each converged cluster. In the beginning, the flag operator checks the _visit-flags_ table. If there are any unvisited candidates (whose visit-flag is 0), it picks one of those unvisited candidates randomly (\(S_{i}\)) and gives it to the _iterator_. The _iterator_ places the kernel center at candidate \(S_{i}\) and finds all the candidates within the kernel geometry (i.e., distance < r). For those candidates (within the kernel), _visit flag_ is set to 1 and _current-round vote_ value is increased by 1. The iteration is repeated with the center of kernel shifted to mean position of candidates within the kernel. The process repeats until kernel center is converged (i.e., no change in mean position). The final converged point \(C_{k}\) is then sent to the _Merger_ module. Figure 10: Flowchart of implemented mean-shift (MS) clustering.