Skip to content

Commit a420ca6

Browse files
committed
speed_filter2d_in_rgb_image.cpp
1 parent 7534952 commit a420ca6

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

Algorithm optimization/speed_filter2d_in_rgb_image.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,33 @@ void get_Pad(int pad_Height, int pad_Width, int row, int col, int channel, float
3939
}
4040
}
4141

42+
//pad_A的转换,以适用于Openblas
43+
void convert_A(float *A_convert, const int OutHeight, const int OutWidth, const int convAw, const int pad_Height, const int pad_Width, int channel, float *A_pad) {
44+
int pad_one_channel = pad_Height * pad_Width;
45+
int seg = channel * convAw;
46+
for (int c = 0; c < channel; c++) {
47+
for (int i = 0; i < OutHeight; i++) {
48+
for (int j = 0; j < OutWidth; j++) {
49+
int index = c * convAw + i * OutHeight * seg + j * seg;
50+
int col1 = c*pad_one_channel + i * pad_Height + j;
51+
A_convert[index] = A_pad[col1];
52+
A_convert[index + 1] = A_pad[col1 + 1];
53+
A_convert[index + 2] = A_pad[col1 + 2];
54+
55+
int col2 = c*pad_one_channel + (i + 1) * pad_Height + j;
56+
A_convert[index + 3] = A_pad[col2];
57+
A_convert[index + 4] = A_pad[col2 + 1];
58+
A_convert[index + 5] = A_pad[col2 + 2];
59+
60+
int col3 = c*pad_one_channel + (i + 2) * pad_Height + j;
61+
A_convert[index + 6] = A_pad[col3];
62+
A_convert[index + 7] = A_pad[col3 + 1];
63+
A_convert[index + 8] = A_pad[col3 + 2];
64+
}
65+
}
66+
}
67+
}
68+
4269

4370
int main() {
4471
//RGB图
@@ -77,5 +104,10 @@ int main() {
77104
const int pad_Width = col + 2 * pad;
78105
float *A_pad = new float[pad_Height * pad_Width * channel];
79106
get_Pad(pad_Height, pad_Width, row, col, channel, A_pad, A);
80-
//
107+
//定义被卷积矩阵宽高
108+
const int convAw = KernelHeight * KernelWidth;
109+
const int convAh = OutHeight * OutWidth;
110+
//转换被卷积矩阵
111+
float *A_convert = new float[convAh * convAw * channel];
112+
convert_A(A_convert, OutHeight, OutWidth, convAw,pad_Height, pad_Width, channel, A_pad);
81113
}

0 commit comments

Comments
 (0)