# Efficient FPGA Implementation of Automatic Nuclei Detection in Histopathology Images
## 2 Materials and Methods
### Regional Maxima Calculation  
Regional maxima are connected components of pixels with a constant grayscale value, \(t\), whose external boundary pixels all have a value less than \(t\)[5; 6]. As the regional maxima in a gLoG filter response map \(I\) are usually around the nuclei centers, they are detected in this module and considered as candidate pixels to calculate the nuclei centers.  
The principle of regional maxima calculation used in this paper is shown in Figure 6. In Figure 6a, the response map \(I\) (denoted by dotted lines) is used as the mask image. A marker image \(J=I-1\) (shown by full lines) is generated and stored in an FPGA block RAM (if \(J<0\), it is set to 0). A _hybrid grayscale reconstruction_ algorithm [6], described below, is then performed on the marker image \(J\), and let the output be denoted by \(J^{\prime}\). After that, \(I-J^{\prime}\) is calculated, and where the outcome value is 1, the corresponding pixel is considered as the regional maxima. This is illustrated in Figure 6b.  
Figure 7 shows the block schematic of the _Regional Maxima_ module, which has 3 parts: _Marker generation_, _Grayscale Reconstruction_ and _Subtraction_. Function of _Marker Generation_ (\(J=I-1\)) and _Subtraction_ (\(I-J^{\prime}\)) parts are mentioned in the previous paragraph. The _Grayscale Reconstruction_ of the marker image \(J\) is done in 3 steps, _Raster scan_, _Anti-raster scan_ and _Propagation_, which are explained in the following.  
Figure 5: Ten 2-D gLoG filters with different orientations.  
Figure 6: Principle of regional maxima calculation. (**a**) dotted lines, \(I\), shows Mask, shaded portion shows Marker \(J\), (**b**) \(J^{\prime}\) indicates the reconstruction of \(J\).  
After generating the mask \(I\) and the marker \(J\), a raster scan of these two images is performed. Let \(p\) denote pointer of the current pixel in the scanning, and \(q\) denote its neighbor's pixel positions.  
The eight neighbors of \(p\) are denoted as \(N(p)\) (see Figure 8a). The 4 neighbors reached before \(p\) in a scan order are denoted as \(N^{+}(p)\) (see Figure 8b). The maximum value of \(\{J(p),J(q),\,q\in N^{+}(p)\}\) is then calculated and denoted as \(s\). Finally, the \(J(p)\) is updated with \(\min\{s,I(p)\}\). After the raster scan, an anti-raster scan (scanning from the bottom pixel) of \(I\) (i.e., the original image) and updated \(J\) is performed in a similar way. This time, it checks if for a pixel \(p\), there exists a pixel \(q\) (\(q\in N^{+}(p)\) such that \(J(q)<J(p)\) and \(J(q)<I(q)\), the \(q\) value is stored in the FIFO (First In First Out) queue.  
After the anti-raster scan, the propagation step is performed on the FIFO structure. In the beginning, the FIFO is checked, if it is empty, the process of grayscale reconstruction is completed; if it is not, the point which is at the beginning of the FIFO is popped out and denoted as \(p\). The values of \(I(p),J(p),I(q)\) and \(I(q)\), \(q\in N(p)\) are read from images \(I\) and \(J\). If there exist any \(q\in N(p)\), such that \(J(q)<J(p)\) and \(J(q)\
eq I(q)\), the minimum value between \(J(p)\) and \(I(q)\) is given to \(J(q)\) and the \(q\) is put into the queue. Then another round of the loop begins. This process continues until there are no data in the queue. The updated \(J\) is the grayscale reconstructed marker image and is denoted as \(J^{\prime}\).  
Finally, a binary response map \(R=I-J^{\prime}\) is calculated for each gLoG output, and stored in the FPGA RAM, where a binary value of 1 indicates the regional maxima.