## 3 High-Speed RoI Extraction through Grid Virtual Division
### Grid Virtual Division Scheme
Afterwards, we compare the grayscale values sampled in the collection to the threshold in turn, recording the number of blocks of pixels with higher grayscale values. Benefiting from the advantages of the previous step, when sampling pixels in a certain block, it is only necessary to divide the rows and columns of the original image by the partition sizes \(n\) and \(m\) to locate this area quickly. To be precise, the pixels sampling step calls the SEARCHPIXEL and SAMPLE functions in Algorithm 1 after the virtual grid has been established in the frame. SEARCHPIXEL function filters the randomly sampled pixels  
Figure 5: Flow chart of the proposed algorithm. in the SAMPLE function and stores the block number that meets the requirements in the results container. As mentioned before, we sample the pixels in the left, center and right areas of each block's middle row. As illustrated in Figure 4, the cyan-marked numbers in the frame indicate the block number that satisfies the condition after calling the SEARCHPIXEL function and the SAMPLE function in Algorithm 1. ```
1:Image, \(n\), \(m\), threshold
2:Vector\({}_{rect}\)
3:functionSearchPixel(\(Image,n,m\))
4:for\(block_{num}=1\to n*m\)do
5:\(pixel_{left}\gets Sample(Image,block_{num},left)\)
6:\(pixel_{center}\gets Sample(Image,block_{num},center)\)
7:\(pixel_{right}\gets Sample(Image,block_{num},right)\)
8:if\(pixel_{left}\) or \(pixel_{center}\) or \(pixel_{right}>\)thresholdthen
9: Store \(block_{num}\) in container \(result_{vec}\)
10:endif
11:\(block_{num}++\)
12:endfor
13:return\(result_{vec}\)
14:endfunction
15:functionImageCompose(\(result_{vec},Image,n,m\))
16:\(n\gets result_{vec}\).size
17:for\(i=0\to n\)do
18:if At least one of the upper, lower, left and right blocks of the \(result_{vec}[i]\) block is stored in container \(result_{vec}\)then
19: Concatenate adjacent blocks
20: Calculate the \(rect_{x}\), \(rect_{y}\), \(rect_{width}\), \(rect_{height}\) of the new combined block
21: Store coordinates in container \(Vector_{rect}\)
22:\(i++\)
23:else
24: Calculate the \(rect_{x}\), \(rect_{y}\), \(rect_{width}\), \(rect_{height}\) of the original block
25: Store coordinates in container \(Vector_{rect}\)
26:\(i++\)
27:endif
28:endfor
29:return\(Vector_{rect}\)
30:endfunction
31:functionSample(\(Image,block_{num},location\))
32:\(h\gets Image.rows/n\)
33:\(w\gets Image.cols/m\)
34:if\(location==left\)then
35:\(result\gets random.sample(range((block_{num}\%m-1)*w,(block_{num}\%m-1)*w+w/3),1)\)
36:elseif\(location==center\)then
37:\(result\gets random.sample(range((block_{num}\%m-1)*w+w/3,(block_{num}\%m-1)*w+2w/3),1)\)
38:else
39:\(result\gets random.sample(range((block_{num}\%m-1)*w+2w/3,(block_{num}\%m-1)*w+w),1)\)
40:endif
41:return\(result\)
42:endfunction
```  
**Algorithm 1** Grid virtual division algorithm
Step 3--Multi-block Stitching: After obtaining the block number at the area where the optical signal is easily concentrated, this step first needs to determine the position relationship between the block number reserved in the previous step. If a complete ROI is segmented, the divided sub-Rols must be adjacent. Therefore, it is possible to determine whether a block belongs to the following four situations according to this criterion:  
* There are only upper and lower adjacent blocks;
* There are only left and right adjacent blocks;
* There are both upper and lower adjacent blocks and left and right adjacent blocks;
* There are neither upper and lower adjacent blocks nor left and right adjacent blocks. More specifically, if the result of the current block number, plus or minus the number of columns, exists in the container, it is treated as the first case, because the upper and lower adjacent blocks are in the same column as the current block. For example, the result of the block number labeled \"11\" (current block number) plus \"6\" (number of columns) in Figure 4d exists in the container, so the block number \"17\" is the lower adjacent block of \"11\".