我有一个CV_32FC1
类型的矩阵,其大小为32x32
,其值与此类似:
1.93694e-008 3.07071e-008 4.94021e-008 7.62369e-008 1.18962e-007 1.76913e-007 2.59968e-007 3.67334e-007 4.95609e-007 6.40923e-007 7.78457e-007 8.7465e-007 9.11251e-007 8.31488e-007 6.44493e-007 3.5359e-007 1.04311e-012 -3.53588e-007 -6.44492e-007 -8.31487e-007 -9.1125e-007 -8.74649e-007 -7.78456e-007 -6.40922e-007 -4.95609e-007 -3.67334e-007 -2.59968e-007 -1.76913e-007 -1.18962e-007 -7.62369e-008 -4.94021e-008 -3.07071e-008
3.06892e-008 5.09824e-008 8.35426e-008 1.35964e-007 2.16775e-007 3.37835e-007 5.13594e-007 7.49976e-007 1.05257e-006 1.40219e-006 1.74842e-006 2.03448e-006 2.14198e-006 2.01039e-006 1.57129e-006 8.70235e-007 2.60888e-012 -8.62696e-007 -1.57507e-006 -2.00502e-006 -2.15194e-006 -2.02933e-006 -1.75414e-006 -1.40072e-006 -1.05049e-006 -7.50281e-007 -5.11113e-007 -3.37139e-007 -2.16334e-007 -1.35222e-007 -8.36318e-008 -5.08201e-008
4.92612e-008 8.35269e-008 1.43107e-007 2.39115e-007 3.9693e-007 6.44434e-007 1.01118e-006 1.54809e-006 2.24752e-006 3.09694e-006 4.02846e-006 4.76226e-006 5.19854e-006 4.91817e-006 3.91087e-006 2.13266e-006 5.87056e-012 -2.22993e-006 -3.90748e-006 -4.91911e-006 -5.15612e-006 -4.7527e-006 -3.97984e-006 -3.0987e-006 -2.24102e-006 -1.54625e-006 -1.02186e-006 -6.43699e-007 -4.02441e-007 -2.39679e-007 -1.44198e-007 -8.37019e-008
7.60845e-008 1.3579e-007 2.39106e-007 4.18485e-007 7.25225e-007 1.21709e-006 2.01066e-006 3.17691e-006 4.7935e-006 6.89156e-006 9.13404e-006 1.12809e-005 1.2473e-005 1.21505e-005 9.77994e-006 5.51596e-006 1.40501e-011 -5.44681e-006 -9.79417e-006 -1.21135e-005 -1.25166e-005 -1.12539e-005 -9.15874e-006 -6.88435e-006 -4.78444e-006 -3.17864e-006 -2.00114e-006 -1.21546e-006 -7.23496e-007 -4.16641e-007 -2.39246e-007 -1.35427e-007
1.17695e-007 2.16794e-007 3.94831e-007 7.2493e-007 1.28815e-006 2.29012e-006 3.89558e-006 6.44857e-006 1.01646e-005 1.50314e-005 2.0827e-005 2.63105e-005 2.98054e-005 2.97086e-005 2.40412e-005 1.36533e-005 3.31313e-011 -1.35655e-005 -2.41156e-005 -2.93022e-005 -2.9738e-005 -2.61076e-005 -2.06374e-005 -1.50235e-005 -1.01053e-005 -6.43866e-006 -3.91845e-006 -2.27538e-006 -1.30584e-006 -7.19624e-007 -3.99035e-007 -2.16132e-007
1.76896e-007 3.37326e-007 6.44178e-007 1.21603e-006 2.28783e-006 4.19597e-006 7.48731e-006 1.29483e-005 2.10391e-005 3.25671e-005 4.61848e-005 6.00322e-005 6.96929e-005 7.00884e-005 5.77746e-005 3.27704e-005 7.11531e-011 -3.32494e-005 -5.77843e-005 -7.02775e-005 -6.95844e-005 -6.01547e-005 -4.60997e-005 -3.26031e-005 -2.10729e-005 -1.29365e-005 -7.52144e-006 -4.19446e-006 -2.29502e-006 -1.21847e-006 -6.44452e-007 -3.37835e-007
2.57106e-007 5.12948e-007 1.00677e-006 2.00376e-006 3.89464e-006 7.47791e-006 1.39647e-005 2.49364e-005 4.25078e-005 6.76395e-005 9.88971e-005 0.000132626 0.000155259 0.000161028 0.000132103 7.82914e-005 1.46644e-010 -7.3509e-005 -0.000132428 -0.000157919 -0.000155513 -0.00013163 -9.86906e-005 -6.75702e-005 -4.23211e-005 -2.49209e-005 -1.39393e-005 -7.4401e-006 -3.907e-006 -1.98798e-006 -1.01118e-006 -5.10933e-007
3.66412e-007 7.50641e-007 1.54256e-006 3.17864e-006 6.4339e-006 1.29365e-005 2.49279e-005 4.6617e-005 8.16626e-005 0.00013382 0.000200838 0.000271401 0.000324457 0.00033432 0.000278377 0.000160663 2.93506e-010 -0.000159074 -0.000279156 -0.00033313 -0.000324805 -0.000271655 -0.000200502 -0.000134051 -8.16492e-005 -4.65018e-005 -2.50238e-005 -1.28558e-005 -6.4671e-006 -3.16087e-006 -1.54726e-006 -7.49108e-007
4.96402e-007 1.05131e-006 2.24852e-006 4.7824e-006 1.01559e-005 2.10192e-005 4.24649e-005 8.1663e-005 0.000147894 0.000248684 0.00037868 0.000520104 0.000625421 0.000644914 0.000542007 0.000308816 4.94443e-010 -0.000308816 -0.000542006 -0.000644913 -0.00062542 -0.000520103 -0.00037868 -0.000248684 -0.000147894 -8.1663e-005 -4.24649e-005 -2.10192e-005 -1.01559e-005 -4.7824e-006 -2.24852e-006 -1.05131e-006
6.37726e-007 1.40331e-006 3.08887e-006 6.87106e-006 1.50463e-005 3.2414e-005 6.76818e-005 0.000133569 0.000248639 0.000422184 0.00065146 0.000894996 0.00107579 0.00111096 0.000927537 0.000532558 7.58324e-010 -0.000530046 -0.000931273 -0.00110873 -0.0010804 -0.000894512 -0.000651227 -0.000422419 -0.000247185 -0.000133338 -6.72535e-005 -3.21678e-005 -1.50196e-005 -6.79725e-006 -3.09339e-006 -1.39594e-006
7.8135e-007 1.75357e-006 4.00828e-006 9.16832e-006 2.07321e-005 4.62177e-005 9.87761e-005 0.000200804 0.000378899 0.000651439 0.00101715 0.001382 0.00170613 0.00172519 0.0014902 0.000907568 1.27805e-009 -0.000711667 -0.00145754 -0.00165562 -0.00166379 -0.00137544 -0.00100386 -0.000651477 -0.000377943 -0.00020075 -9.89828e-005 -4.61232e-005 -2.08348e-005 -9.12724e-006 -4.02846e-006 -1.74893e-006
8.75488e-007 2.03129e-006 4.77681e-006 1.12062e-005 2.63779e-005 5.97129e-005 0.000132279 0.000271243 0.000518719 0.000895067 0.00138363 0.00187817 0.0023045 0.00226795 0.0020538 0.00102006 1.72359e-009 -0.00121603 -0.00207708 -0.00234277 -0.00233372 -0.00188639 -0.00138955 -0.000894997 -0.000516362 -0.000271206 -0.000131383 -5.95909e-005 -2.62789e-005 -1.11659e-005 -4.77324e-006 -2.02753e-006
9.03581e-007 2.15238e-006 5.13994e-006 1.25092e-005 2.9738e-005 6.96191e-005 0.000155494 0.000324651 0.000626541 0.00107783 0.00170289 0.00231382 0.00289925 0.00319172 0.00261321 0.00238429 1.36055e-009 -0.000849137 -0.0024097 -0.00265846 -0.00264856 -0.00225427 -0.00162514 -0.00107645 -0.000618912 -0.000324755 -0.000155024 -6.93965e-005 -2.98054e-005 -1.23755e-005 -5.17234e-006 -2.13743e-006
8.27761e-007 2.00502e-006 4.91775e-006 1.20539e-005 2.95986e-005 6.97392e-005 0.000158433 0.00033465 0.000639953 0.00111074 0.00175592 0.00230024 0.00322278 0.00300945 0.00326031 0.00219442 4.62512e-009 -0.000912749 -0.00310091 -0.0025526 -0.00304301 -0.00225057 -0.00171355 -0.00111096 -0.000643998 -0.000334534 -0.000160302 -6.98654e-005 -2.97312e-005 -1.20909e-005 -4.91752e-006 -2.00764e-006
6.38724e-007 1.57426e-006 3.89932e-006 9.75503e-006 2.41757e-005 5.78145e-005 0.000132428 0.000279769 0.000540863 0.000931931 0.00145754 0.00207555 0.00251042 0.00324973 0.00201045 0.00161779 7.41874e-011 -0.000522181 -0.00181798 -0.00263501 -0.00225157 -0.00201341 -0.0013802 -0.000930472 -0.000533438 -0.000280075 -0.000131644 -5.78408e-005 -2.40784e-005 -9.69801e-006 -3.90271e-006 -1.56684e-006
3.44954e-007 8.62074e-007 2.17136e-006 5.37491e-006 1.35922e-005 3.23668e-005 7.29956e-005 0.00016042 0.000302819 0.000531468 0.000975368 0.00121603 0.00232883 0.00300655 0.00149493 0.000624032 7.95393e-012 -5.55596e-007 -0.000888571 -0.000432224 -0.00123506 -0.000952354 -0.000728262 -0.000531968 -0.000312754 -0.000160104 -7.88826e-005 -3.3019e-005 -1.36507e-005 -5.51597e-006 -2.12216e-006 -8.69612e-007
5.44375e-013 1.17471e-012 2.91405e-012 6.54259e-012 1.4955e-011 3.40302e-011 6.7263e-011 1.31421e-010 2.25234e-010 3.41047e-010 4.01706e-010 7.48939e-010 2.73395e-010 1.42528e-009 1.58768e-011 2.8661e-012 0 -1.#IND -1.#IND -1.#IND 0 0 0 0 0 0 0 0 0 0 0 0
-3.44955e-007 -8.69609e-007 -2.12216e-006 -5.51595e-006 -1.36507e-005 -3.30189e-005 -7.88824e-005 -0.000160104 -0.000312753 -0.000531968 -0.000728261 -0.000952353 -0.00123506 -0.000432223 -0.00088857 -5.55596e-007 -1.78564e-012 0.000624032 0.00149493 0.00300655 0.00232883 0.00121603 0.000975369 0.000531468 0.000302819 0.000160421 7.29957e-005 3.23669e-005 1.35922e-005 5.37492e-006 2.17136e-006 8.62078e-007
-6.38724e-007 -1.56684e-006 -3.90271e-006 -9.698e-006 -2.40784e-005 -5.78408e-005 -0.000131644 -0.000280074 -0.000533438 -0.000930472 -0.0013802 -0.00201341 -0.00225157 -0.00263501 -0.00181798 -0.000522181 -1.66549e-011 0.00161779 0.00201045 0.00324973 0.00251042 0.00207555 0.00145754 0.000931931 0.000540864 0.00027977 0.000132428 5.78145e-005 2.41758e-005 9.75504e-006 3.89932e-006 1.57426e-006
-8.27762e-007 -2.00764e-006 -4.91751e-006 -1.20909e-005 -2.97312e-005 -6.98654e-005 -0.000160302 -0.000334534 -0.000643998 -0.00111096 -0.00171354 -0.00225057 -0.00304301 -0.0025526 -0.00310091 -0.000912749 -1.03833e-009 0.00219442 0.00326031 0.00300945 0.00322278 0.00230024 0.00175592 0.00111074 0.000639954 0.00033465 0.000158433 6.97392e-005 2.95986e-005 1.20539e-005 4.91775e-006 2.00503e-006
-9.03582e-007 -2.13743e-006 -5.17234e-006 -1.23755e-005 -2.98054e-005 -6.93965e-005 -0.000155024 -0.000324755 -0.000618912 -0.00107645 -0.00162514 -0.00225427 -0.00264856 -0.00265846 -0.0024097 -0.000849137 -3.05441e-010 0.00238428 0.00261321 0.00319172 0.00289925 0.00231382 0.00170289 0.00107783 0.000626541 0.000324651 0.000155494 6.96191e-005 2.9738e-005 1.25092e-005 5.13994e-006 2.15238e-006
-8.75488e-007 -2.02753e-006 -4.77324e-006 -1.11659e-005 -2.62789e-005 -5.95909e-005 -0.000131383 -0.000271206 -0.000516362 -0.000894997 -0.00138955 -0.00188639 -0.00233372 -0.00234277 -0.00207708 -0.00121603 -3.86942e-010 0.00102006 0.00205379 0.00226795 0.0023045 0.00187817 0.00138363 0.000895067 0.000518719 0.000271243 0.000132279 5.97129e-005 2.63779e-005 1.12062e-005 4.77681e-006 2.03129e-006
-7.8135e-007 -1.74893e-006 -4.02846e-006 -9.12724e-006 -2.08348e-005 -4.61232e-005 -9.89828e-005 -0.00020075 -0.000377943 -0.000651477 -0.00100386 -0.00137544 -0.00166379 -0.00165562 -0.00145754 -0.000711667 -2.86921e-010 0.000907568 0.0014902 0.00172519 0.00170613 0.001382 0.00101715 0.000651439 0.000378899 0.000200805 9.87761e-005 4.62178e-005 2.07321e-005 9.16832e-006 4.00828e-006 1.75357e-006
-6.37726e-007 -1.39594e-006 -3.09339e-006 -6.79725e-006 -1.50196e-005 -3.21678e-005 -6.72535e-005 -0.000133338 -0.000247185 -0.000422419 -0.000651227 -0.000894512 -0.0010804 -0.00110873 -0.000931273 -0.000530046 -1.70242e-010 0.000532558 0.000927537 0.00111096 0.00107579 0.000894996 0.00065146 0.000422184 0.000248639 0.000133569 6.76818e-005 3.2414e-005 1.50463e-005 6.87106e-006 3.08887e-006 1.40331e-006
-4.96402e-007 -1.05131e-006 -2.24852e-006 -4.7824e-006 -1.01559e-005 -2.10192e-005 -4.24649e-005 -8.1663e-005 -0.000147894 -0.000248684 -0.00037868 -0.000520104 -0.00062542 -0.000644914 -0.000542007 -0.000308816 -1.11001e-010 0.000308816 0.000542006 0.000644914 0.00062542 0.000520104 0.00037868 0.000248684 0.000147894 8.1663e-005 4.24649e-005 2.10192e-005 1.01559e-005 4.7824e-006 2.24852e-006 1.05131e-006
-3.66412e-007 -7.49107e-007 -1.54726e-006 -3.16087e-006 -6.4671e-006 -1.28558e-005 -2.50238e-005 -4.65018e-005 -8.16492e-005 -0.000134051 -0.000200502 -0.000271655 -0.000324805 -0.00033313 -0.000279156 -0.000159074 -6.58915e-011 0.000160663 0.000278377 0.00033432 0.000324457 0.000271401 0.000200838 0.00013382 8.16626e-005 4.6617e-005 2.49279e-005 1.29365e-005 6.4339e-006 3.17864e-006 1.54256e-006 7.50641e-007
-2.57106e-007 -5.10933e-007 -1.01118e-006 -1.98798e-006 -3.907e-006 -7.4401e-006 -1.39393e-005 -2.49209e-005 -4.23211e-005 -6.75702e-005 -9.86906e-005 -0.00013163 -0.000155513 -0.00015792 -0.000132428 -7.35091e-005 -3.29212e-011 7.82913e-005 0.000132103 0.000161028 0.000155259 0.000132626 9.88971e-005 6.76395e-005 4.25078e-005 2.49364e-005 1.39647e-005 7.47791e-006 3.89464e-006 2.00376e-006 1.00677e-006 5.12948e-007
-1.76896e-007 -3.37835e-007 -6.44452e-007 -1.21847e-006 -2.29502e-006 -4.19446e-006 -7.52144e-006 -1.29365e-005 -2.10729e-005 -3.26031e-005 -4.60997e-005 -6.01547e-005 -6.95844e-005 -7.02776e-005 -5.77843e-005 -3.32494e-005 -1.59737e-011 3.27703e-005 5.77745e-005 7.00883e-005 6.96929e-005 6.00322e-005 4.61848e-005 3.25671e-005 2.10391e-005 1.29483e-005 7.48731e-006 4.19597e-006 2.28783e-006 1.21603e-006 6.44178e-007 3.37326e-007
-1.17695e-007 -2.16132e-007 -3.99035e-007 -7.19624e-007 -1.30584e-006 -2.27538e-006 -3.91845e-006 -6.43866e-006 -1.01053e-005 -1.50235e-005 -2.06374e-005 -2.61076e-005 -2.9738e-005 -2.93022e-005 -2.41156e-005 -1.35655e-005 -7.43791e-012 1.36532e-005 2.40412e-005 2.97086e-005 2.98054e-005 2.63105e-005 2.0827e-005 1.50314e-005 1.01646e-005 6.44857e-006 3.89558e-006 2.29012e-006 1.28815e-006 7.2493e-007 3.94831e-007 2.16794e-007
-7.60845e-008 -1.35427e-007 -2.39246e-007 -4.16641e-007 -7.23496e-007 -1.21546e-006 -2.00114e-006 -3.17864e-006 -4.78444e-006 -6.88435e-006 -9.15875e-006 -1.12539e-005 -1.25166e-005 -1.21135e-005 -9.79418e-006 -5.44681e-006 -3.15423e-012 5.51595e-006 9.77993e-006 1.21505e-005 1.2473e-005 1.12809e-005 9.13404e-006 6.89155e-006 4.79349e-006 3.17691e-006 2.01066e-006 1.21709e-006 7.25225e-007 4.18485e-007 2.39106e-007 1.3579e-007
-4.92612e-008 -8.37019e-008 -1.44198e-007 -2.39679e-007 -4.02441e-007 -6.43699e-007 -1.02186e-006 -1.54625e-006 -2.24102e-006 -3.0987e-006 -3.97984e-006 -4.7527e-006 -5.15612e-006 -4.91911e-006 -3.90748e-006 -2.22994e-006 -1.31793e-012 2.13266e-006 3.91087e-006 4.91817e-006 5.19854e-006 4.76226e-006 4.02846e-006 3.09694e-006 2.24752e-006 1.54809e-006 1.01118e-006 6.44434e-007 3.9693e-007 2.39115e-007 1.43107e-007 8.35269e-008
-3.06892e-008 -5.08201e-008 -8.36318e-008 -1.35222e-007 -2.16334e-007 -3.37139e-007 -5.11114e-007 -7.50282e-007 -1.05049e-006 -1.40072e-006 -1.75414e-006 -2.02933e-006 -2.15195e-006 -2.00503e-006 -1.57507e-006 -8.62697e-007 -5.85689e-013 8.70233e-007 1.57129e-006 2.01038e-006 2.14198e-006 2.03448e-006 1.74842e-006 1.40219e-006 1.05257e-006 7.49976e-007 5.13594e-007 3.37835e-007 2.16775e-007 1.35964e-007 8.35426e-008 5.09824e-008
获得总结后:
float sum = cv::sum(inputMat)[0];
结果是-1.#IND
,我知道这意味着无限期。为了仔细检查,我甚至尝试在循环中逐个像素地获取总和,但它再次返回-1.#IND
。但是在Matlab中,相同的矩阵求和给出了0.0254
。有没有办法在OpenCV中获得相同的结果?谢谢。
修改
以下是获取inputMat
的代码:
cv::Mat image = cv::imread("test.png", CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat blkimg = image.rowRange(0, 24).colRange(0, 24);
cv::Mat blk;
blkimg.copyTo(blk);
// get kernel mat from outside
cv::multiply(blk, kernel, blk);
cv::Mat padded, blkfft;
cv::copyMakeBorder(blk, padded, 0, 8, 0, 8, cv::BORDER_CONSTANT, cv::Scalar::all(0));
cv::Mat planes[] = { cv::Mat_<float>(padded), cv::Mat::zeros(padded.size(), CV_32FC1) };
cv::Mat complexBlk;
cv::merge(planes, 2, complexBlk);
cv::dft(complexBlk, blkfft);
cv::split(blkfft, dftChannels);
cv::Mat mul1, mul2;
cv::multiply(dftChannels[0], dBPass, mul1); // dBPass comes from outside, of size 32x32
cv::multiply(dftChannels[1], dBPass, mul2); // dBPass comes from outside, of size 32x32
cv::Mat blkfftAbs = getAbs(mul1, mul2);
cv::Mat inputMat;
cv::multiply(blkfftAbs, blkfftAbs, inputMat);
cv::multiply(inputMat, sth, inputMat); // sth mat comes from outside, of size 32x32, with type CV_32FC1;
函数getAbs
定义如下:
cv::Mat getAbs(cv::Mat ch1, cv::Mat ch2)
{
int rows = ch1.rows;
int cols = ch1.cols;
cv::Mat absMat = cv::Mat(rows, cols, ch1.type());
int count = 0;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
float realVal = ch1.at<float>(i, j);
float imVal = ch2.at<float>(i, j);
float absVal = std::sqrt(realVal*realVal + imVal*imVal);
absMat.at<float>(i, j) = absVal;
}
}
return absMat;
}