此函数是上一篇的改进,生成32通道的填边,可以直接替换上一篇的这两个函数
//填边宽 1 + maxModelX
//填边高 1 + maxModelY
int outCell(float * NL18, float * LB, float * des, int srcW, int srcH, int maxModelX, int maxModelY)
{
int desW = srcW - 2;
int desH = srcH - 2;
int outW = srcW + 2 * maxModelX;
int outH = srcH + 2 * maxModelY;
int offsetX = maxModelX + 1;
int offsetY = maxModelY + 1;
int lBx = 0;
int lBy = 0;
int LbW = srcW - 1;
int LbH = srcH - 1;
int i,j,k;
int srcIndex;
float temp;
float Plb1, Plb2, Plb3, Plb4;
float Tpl1, Tpl2, Tpl3, Tpl4;
float sumPlb1, sumPlb2, sumPlb3, sumPlb4;
for(i = 0; i < outH; i ++)
{
for(j = 0; j < outW; j ++)
{
if(i < offsetY || j < offsetX || i >= offsetY + desH || j >= offsetX + desW)
{
for(k = 0; k < 31; k ++)
{
des[(i * outW + j) * 32 + k] = 0.0f;
}
des[(i * outW + j) * 32 + 31] = 1.0f;
}else
{
sumPlb1 = 0.0f;
sumPlb2 = 0.0f;
sumPlb3 = 0.0f;
sumPlb4 = 0.0f;
srcIndex = ((i + 1 - offsetY) * srcW + (j + 1 - offsetX)) * 18;
lBx = j - offsetX;
lBy = i - offsetY;
for(k = 0; k < 18; k ++)
{
Plb1 = min(NL18[srcIndex + k] * LB[lBy * LbW + lBx], 0.2f);
Plb2 = min(NL18[srcIndex + k] * LB[(lBy) * LbW + lBx + 1], 0.2f);
Plb3 = min(NL18[srcIndex + k] * LB[(lBy + 1) * LbW + lBx], 0.2f);
Plb4 = min(NL18[srcIndex + k] * LB[(lBy + 1) * LbW + lBx + 1], 0.2f);
des[(i * outW + j) * 32 + k] = (Plb1 + Plb2 + Plb3 + Plb4) * 0.5f;
sumPlb1 += Plb1;
sumPlb2 += Plb2;
sumPlb3 += Plb3;
sumPlb4 += Plb4;
}
for(k = 0; k < 9; k ++)
{
temp = NL18[srcIndex + k] + NL18[srcIndex + k + 9];
Tpl1 = min(temp * LB[lBy * LbW + lBx], 0.2f);
Tpl2 = min(temp * LB[(lBy) * LbW + lBx + 1], 0.2f);
Tpl3 = min(temp * LB[(lBy + 1) * LbW + lBx], 0.2f);
Tpl4 = min(temp * LB[(lBy + 1) * LbW + lBx + 1], 0.2f);
des[(i * outW + j) * 32 + 18 + k] = (Tpl1 + Tpl2 + Tpl3 + Tpl4) * 0.5f;
}
des[(i * outW + j) * 32 + 27] = sumPlb1 * 0.2357f;
des[(i * outW + j) * 32 + 28] = sumPlb2 * 0.2357f;
des[(i * outW + j) * 32 + 29] = sumPlb3 * 0.2357f;
des[(i * outW + j) * 32 + 30] = sumPlb4 * 0.2357f;
des[(i * outW + j) * 32 + 31] = 0.0f;
}
}
}
return 0;
}
int ImageOutCell(float * src, float * des, int width, int height, int maxModelX, int maxModelY)
{
float * NL;
float * L;
float *LB;
float * NL18;
int sbin = 4;
int cellW = round((float)width / 4);
int cellH = round((float)height / 4);
NL = (float *)malloc(width * height * sizeof(float) * 2);
NL18 = (float *)malloc(cellW * cellH * sizeof(float) * 18);
getNL(src, NL, width, height);
nlTo18(NL, NL18, width, height, cellW, cellH, sbin);
//计算L模长
L = (float *)malloc(cellW * cellH * sizeof(float));
LB = (float *)malloc((cellW - 1) * (cellH - 1) * sizeof(float));
countL(NL18, L, cellW, cellH);
// 计算block
countLB(L, LB, cellW, cellH, cellW - 1, cellH - 1);
outCell(NL18, LB, des, cellW, cellH, maxModelX, maxModelY);
free(NL);
free(NL18);
free(L);
free(LB);
return 0;
}
32 通道填边
最新推荐文章于 2020-08-18 20:48:41 发布