基于时间阈值的Zynq7000图像灰度化精度分配公式需求
Hey there! Let's work through this problem step by step to get the exact formula you need, plus verify it with your example to make sure it checks out.
First, define all key variables
Let's start by mapping out everything we need to quantify:
T_full_high: Total time to process the entire image with high-precision (floating-point) arithmetic (e.g., 10 seconds in your example)T_full_low: Total time to process the entire image with low-precision (fixed-point) arithmetic (e.g., 5 seconds in your example)N_total: Total number of pixels in the imageT_threshold: Your allowed time limit (e.g., 7.5 seconds in your example)N_high: Number of pixels to process with high-precision arithmetic (what we want to calculate)N_low: Number of pixels to process with low-precision arithmetic (and since every pixel is processed one way or the other,N_low = N_total - N_high)
Derive the formula
First, calculate the time per pixel for each method:
- Time per high-precision pixel:
t_high = T_full_high / N_total - Time per low-precision pixel:
t_low = T_full_low / N_total
The total time used will be the sum of time spent on high-precision pixels and low-precision pixels, which needs to equal your threshold:
(N_high * t_high) + (N_low * t_low) = T_threshold
Substitute N_low = N_total - N_high, t_high, and t_low into the equation:
N_high*(T_full_high/N_total) + (N_total - N_high)*(T_full_low/N_total) = T_threshold
Multiply both sides by N_total to eliminate denominators:
N_high*T_full_high + (N_total - N_high)*T_full_low = T_threshold*N_total
Expand and rearrange terms to isolate N_high:
N_high*T_full_high + N_total*T_full_low - N_high*T_full_low = T_threshold*N_total N_high*(T_full_high - T_full_low) = N_total*(T_threshold - T_full_low)
Finally, solve for N_high:
N_high = N_total * (T_threshold - T_full_low) / (T_full_high - T_full_low)
And for N_low, it's simply:
N_low = N_total - N_high = N_total * (T_full_high - T_threshold) / (T_full_high - T_full_low)
Verify with your example
Let's plug in your numbers to confirm:
T_full_high = 10s,T_full_low =5s,T_threshold=7.5sN_high = N_total*(7.5 -5)/(10-5) = N_total*(2.5/5) = 0.5*N_total
Perfect—this gives exactly half the pixels for high-precision, which matches your expected result.
Edge cases to consider
Don't forget to handle these boundary scenarios in your code:
- If
T_threshold >= T_full_high: Use high-precision for all pixels (N_high = N_total,N_low=0) - If
T_threshold <= T_full_low: Use low-precision for all pixels (N_high=0,N_low=N_total)
内容的提问来源于stack exchange,提问作者KritikakisEmman

