[英]Possibility of finding two max values(with difference of more than one) from an array while filling it simultaneously
我試圖同時填充它從數組中找到最大值和最大值+ 3值。 我嘗試了以下代碼,但這不是正確的算法。
for(x = image_height; x--; ){
for(y = image_width; y--; ){
if(*((in_image + x * image_width )+ y)){
for(theta = -90; theta <= 180; theta++){
rho = x * mycos(theta) + y * mysin(theta);
if(rho > 0 && rho < MAX_POSSIBLE_RHO){
g_hough_array[(int)rho][(int)theta + 90]++;
if(rho == 0) continue;
if(max_intensity < g_hough_array[(int)rho][(int)theta + 90]){
max_intensity = g_hough_array[(int)rho][(int)theta + 90];
*max_theta = theta;
*max_rho = rho;
}else{
if(theta < (*max_theta) + 3 && theta > (*max_theta) - 3) continue;
if(max_intensity2 < g_hough_array[(int)rho][(int)theta + 90]){
max_intensity2 = g_hough_array[(int)rho][(int)theta + 90];
*max_theta2 = theta;
*max_rho2 = rho;
if(max_intensity2 == max_intensity){
float temp = (*max_theta);
(*max_theta) = (*max_theta2);
(*max_theta2) = temp;
temp = (*max_rho);
(*max_rho) = (*max_rho2);
(*max_rho2) = temp;
}
}
}
}
}
}
}
}
我在想是否有可能在填充數組的同時找到這種兩個值? 我想避免多余的循環來找到第二個最大值。
建議:
捕獲前兩個值作為最大值
每當新輸入值超過兩個捕獲值中的最小值時,請用新值替換該最小值。
完成后,兩個捕獲的值將是最大值和最大值附近。
您可以輕松擴展此值,以要求兩個值之間的差值至少為3。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.