Linear difference of CLAHE algorithm in FPGA image processing
INDUSTRIAL LCD DISPLAYS / IGBT MODULES DISTRIBUTOR

Infineon / Mitsubishi / Fuji / Semikron / Eupec / IXYS

Linear difference of CLAHE algorithm in FPGA image processing

Posted Date: 2024-01-22

Linear difference of CLAHE algorithm.

Let's first take a look at the effect of the CLAHE algorithm without linear difference.

It can be seen that the pictures are all block by block. This is because the corresponding histogram data is counted in each block. This results in different mapping tables for histogram statistics in different blocks, so it appears. Patches of spots.

The solution to this problem is linear interpolation.

The entire image can be divided into the following parts:

The entire 8*8 has a total of 64 blocks, and then no linear interpolation is performed for the four red corner points, linear interpolation is performed for the four blue sides, and bilinear interpolation is performed for the white part in the middle.

The side length of the red square is half the side length of the block.

Let’s zoom in on a part to see how the calculation is performed. For example, zoom in on the upper left corner to get a 3*3 block, and use a solid black line to represent each block. Then use blue dotted lines to connect half of each block, thus dividing each block into 4*4 small blocks.

The small block in the upper left corner does not perform linear interpolation. The corresponding code is as follows. It determines whether it is at the four corner points. If it is a corner point, perform histogram equalization directly.

if i = w - bw // 2: he(i)(j) = sk_list(block - 1)(img(i)(j)) elif i >= h - bh // 2 and j = h - bh / / 2 and j >= w - bw // 2: he(i)(j) = sk_list(block * block - 1)(img(i)(j))

The first point located in the blue area requires linear interpolation to get the final result.

You can see that this point is located in the first block. Assuming that its distance from the center line of the first block is P, then the weight of the first block is 1-P/block_width, and the weight of the second block is P/block_width. If this point is exactly at the intersection of the first and second blocks, then the weights of both blocks are 0.5. So the calculation method for this point is to multiply the result of histogram equalization in the first block by the weight of the first block, plus the result of histogram equalization in the second block multiplied by the second The weight of a block.

For example, the following reference code first calculates which block this point is located in, then calculates the corresponding weight, and finally performs histogram equalization and adds the results.

num_j = (j - bw // 2) // bw p = (j - num_j * bw - bw // 2) / bw q = 1 - p he(i)(j) = sk_list(num_j)(img(i )(j)) * q + sk_list(num_j + 1)(img(i)(j)) * p

For the last case, which is the point located in the middle white area, he needs to perform bilinear interpolation. You can see that the entire point is located in the fourth block, so he needs to calculate the histogram equalization results and corresponding weights on the first, second, fourth and fifth blocks respectively. The reference code is as follows:

num_i = (i - bh // 2) // bh num_j = (j - bw // 2) // bw m = (i - num_i * bh - bh // 2) / bh v = 1 - m p = (j - num_j * bw - bw // 2) / bw q = 1 - p he(i)(j) = sk_list(num_i * block + num_j)(img(i)(j)) * q * v + sk_list(( num_i * block) + block + num_j)( img(i)(j)) * q * m + sk_list(num_i * block + num_j + 1)(img(i)(j)) * p * v + sk_list(( num_i * block) + block + num_j + 1)(img(i)(j)) * p * m

The calculation method is the same for verilog, and the results are calculated separately through different points.

case (switch_ff(23))

4'd0, 4'd1, 4'd2, 4'd3: begin cand_tx_pipe_1(0)

The DSP automatic inference method is used here, and these multiplications will be automatically inferred as DSP.

The data is patted before calculation, and part of the registers will be absorbed by the DSP unit, so there is no need to worry about the timing issue of this multiplication.

always @(posedge clk ) begin cand_rd_data_1_ff(0)

Look at the final result, there are no more spots.

This is the CLAHE algorithm, which is divided into the following steps:

Divide the entire image into blocks, and then perform histogram equalization on each block.

Perform CLIP operation when performing histogram equalization

perform linear interpolation

Review Editor: Huang Fei


#Linear #difference #CLAHE #algorithm #FPGA #image #processing