void analysisContrast(const cv::Mat & src,cv::Mat & dest) { cv::Scalar mean; cv::Scalar std; cv::Mat c1(src.rows,src.cols,src.type()); cv::Mat c2(src.rows+33,src.cols+33,src.type()); /// Filtra a imagem utilizando a funcao de sensitividade de contraste (CSF) no domínio espacial conv2D(src,c1,(cv::Mat_<float>(33,33) << 4.1243e-08,3.2397e-08,1.1371e-08,-2.0774e-08,-6.0455e-08,-1.1145e-07,-1.8157e-07,-2.6422e-07,-3.301e-07,-3.4356e-07,-2.856e-07,-1.6191e-07,-6.9515e-10,1.4841e-07,2.343e-07,2.5095e-07,2.4572e-07,2.5095e-07,2.343e-07,1.4841e-07,-6.9515e-10,-1.6191e-07,-2.856e-07,-3.4356e-07,-3.301e-07,-2.6422e-07,-1.8157e-07,-1.1145e-07,-6.0455e-08,-2.0774e-08,1.1371e-08,3.2397e-08,4.1243e-08, 3.2397e-08,2.2705e-08,9.2313e-09,-9.8996e-09,-4.9927e-08,-1.1915e-07,-1.9687e-07,-2.4966e-07,-2.6984e-07,-2.7684e-07,-2.7219e-07,-2.0553e-07,1.1891e-08,4.6019e-07,1.1197e-06,1.766e-06,2.0425e-06,1.766e-06,1.1197e-06,4.6019e-07,1.1891e-08,-2.0553e-07,-2.7219e-07,-2.7684e-07,-2.6984e-07,-2.4966e-07,-1.9687e-07,-1.1915e-07,-4.9927e-08,-9.8996e-09,9.2313e-09,2.2705e-08,3.2397e-08, 1.1371e-08,9.2313e-09,7.1241e-09,-1.0239e-08,-5.5309e-08,-1.0363e-07,-1.2772e-07,-1.5906e-07,-2.5775e-07,-4.0892e-07,-4.9915e-07,-4.3263e-07,-2.7198e-07,-2.4771e-07,-5.5069e-07,-1.0417e-06,-1.2882e-06,-1.0417e-06,-5.5069e-07,-2.4771e-07,-2.7198e-07,-4.3263e-07,-4.9915e-07,-4.0892e-07,-2.5775e-07,-1.5906e-07,-1.2772e-07,-1.0363e-07,-5.5309e-08,-1.0239e-08,7.1241e-09,9.2313e-09,1.1371e-08, -2.0774e-08,-9.8996e-09,-1.0239e-08,-3.2372e-08,-4.0323e-08,-1.2704e-08,-3.3299e-08,-2.0036e-07,-4.3824e-07,-5.3327e-07,-3.8192e-07,-7.8348e-08,3.1609e-07,9.8584e-07,2.1171e-06,3.3751e-06,3.9459e-06,3.3751e-06,2.1171e-06,9.8584e-07,3.1609e-07,-7.8348e-08,-3.8192e-07,-5.3327e-07,-4.3824e-07,-2.0036e-07,-3.3299e-08,-1.2704e-08,-4.0323e-08,-3.2372e-08,-1.0239e-08,-9.8996e-09,-2.0774e-08, -6.0455e-08,-4.9927e-08,-5.5309e-08,-4.0323e-08,3.1377e-08,4.4257e-08,-1.2201e-07,-2.9598e-07,-2.008e-07,5.2816e-08,2.2358e-08,-4.6194e-07,-1.0754e-06,-1.5256e-06,-1.945e-06,-2.4459e-06,-2.7024e-06,-2.4459e-06,-1.945e-06,-1.5256e-06,-1.0754e-06,-4.6194e-07,2.2358e-08,5.2816e-08,-2.008e-07,-2.9598e-07,-1.2201e-07,4.4257e-08,3.1377e-08,-4.0323e-08,-5.5309e-08,-4.9927e-08,-6.0455e-08, -1.1145e-07,-1.1915e-07,-1.0363e-07,-1.2704e-08,4.4257e-08,-8.2062e-08,-1.3261e-07,2.2502e-07,5.1969e-07,-1.0007e-07,-1.4557e-06,-2.2171e-06,-1.2838e-06,1.2671e-06,4.519e-06,7.2838e-06,8.3876e-06,7.2838e-06,4.519e-06,1.2671e-06,-1.2838e-06,-2.2171e-06,-1.4557e-06,-1.0007e-07,5.1969e-07,2.2502e-07,-1.3261e-07,-8.2062e-08,4.4257e-08,-1.2704e-08,-1.0363e-07,-1.1915e-07,-1.1145e-07, -1.8157e-07,-1.9687e-07,-1.2772e-07,-3.3299e-08,-1.2201e-07,-1.3261e-07,4.0958e-07,7.6089e-07,-3.1224e-07,-1.9059e-06,-1.7349e-06,3.1369e-07,1.6616e-06,1.5685e-07,-3.5292e-06,-6.9366e-06,-8.2415e-06,-6.9366e-06,-3.5292e-06,1.5685e-07,1.6616e-06,3.1369e-07,-1.7349e-06,-1.9059e-06,-3.1224e-07,7.6089e-07,4.0958e-07,-1.3261e-07,-1.2201e-07,-3.3299e-08,-1.2772e-07,-1.9687e-07,-1.8157e-07, -2.6422e-07,-2.4966e-07,-1.5906e-07,-2.0036e-07,-2.9598e-07,2.2502e-07,7.6089e-07,-3.6682e-07,-1.5158e-06,8.6586e-07,4.6284e-06,3.7091e-06,-2.1285e-06,-5.4078e-06,4.0555e-07,1.175e-05,1.7539e-05,1.175e-05,4.0555e-07,-5.4078e-06,-2.1285e-06,3.7091e-06,4.6284e-06,8.6586e-07,-1.5158e-06,-3.6682e-07,7.6089e-07,2.2502e-07,-2.9598e-07,-2.0036e-07,-1.5906e-07,-2.4966e-07,-2.6422e-07, -3.301e-07,-2.6984e-07,-2.5775e-07,-4.3824e-07,-2.008e-07,5.1969e-07,-3.1224e-07,-1.5158e-06,2.2473e-06,6.8127e-06,4.3871e-07,-1.3554e-05,-1.9554e-05,-1.1949e-05,4.8718e-07,7.2008e-06,8.2578e-06,7.2008e-06,4.8718e-07,-1.1949e-05,-1.9554e-05,-1.3554e-05,4.3871e-07,6.8127e-06,2.2473e-06,-1.5158e-06,-3.1224e-07,5.1969e-07,-2.008e-07,-4.3824e-07,-2.5775e-07,-2.6984e-07,-3.301e-07, -3.4356e-07,-2.7684e-07,-4.0892e-07,-5.3327e-07,5.2816e-08,-1.0007e-07,-1.9059e-06,8.6586e-07,6.8127e-06,-1.638e-06,-1.6904e-05,-5.9626e-06,2.2956e-05,3.319e-05,1.5353e-05,-1.1122e-05,-2.2544e-05,-1.1122e-05,1.5353e-05,3.319e-05,2.2956e-05,-5.9626e-06,-1.6904e-05,-1.638e-06,6.8127e-06,8.6586e-07,-1.9059e-06,-1.0007e-07,5.2816e-08,-5.3327e-07,-4.0892e-07,-2.7684e-07,-3.4356e-07, -2.856e-07,-2.7219e-07,-4.9915e-07,-3.8192e-07,2.2358e-08,-1.4557e-06,-1.7349e-06,4.6284e-06,4.3871e-07,-1.6904e-05,8.1807e-06,6.1551e-05,3.4991e-05,-5.5282e-05,-0.00010312,-5.199e-05,5.4491e-06,-5.199e-05,-0.00010312,-5.5282e-05,3.4991e-05,6.1551e-05,8.1807e-06,-1.6904e-05,4.3871e-07,4.6284e-06,-1.7349e-06,-1.4557e-06,2.2358e-08,-3.8192e-07,-4.9915e-07,-2.7219e-07,-2.856e-07, -1.6191e-07,-2.0553e-07,-4.3263e-07,-7.8348e-08,-4.6194e-07,-2.2171e-06,3.1369e-07,3.7091e-06,-1.3554e-05,-5.9626e-06,6.1551e-05,1.2939e-05,-0.00017577,-0.00022694,-0.00022987,-0.00011755,5.7546e-05,-0.00011755,-0.00022987,-0.00022694,-0.00017577,1.2939e-05,6.1551e-05,-5.9626e-06,-1.3554e-05,3.7091e-06,3.1369e-07,-2.2171e-06,-4.6194e-07,-7.8348e-08,-4.3263e-07,-2.0553e-07,-1.6191e-07, -6.9515e-10,1.1891e-08,-2.7198e-07,3.1609e-07,-1.0754e-06,-1.2838e-06,1.6616e-06,-2.1285e-06,-1.9554e-05,2.2956e-05,3.4991e-05,-0.00017577,-0.00014129,0.00014561,-0.00092767,-0.0022122,-0.0022718,-0.0022122,-0.00092767,0.00014561,-0.00014129,-0.00017577,3.4991e-05,2.2956e-05,-1.9554e-05,-2.1285e-06,1.6616e-06,-1.2838e-06,-1.0754e-06,3.1609e-07,-2.7198e-07,1.1891e-08,-6.9515e-10, 1.4841e-07,4.6019e-07,-2.4771e-07,9.8584e-07,-1.5256e-06,1.2671e-06,1.5685e-07,-5.4078e-06,-1.1949e-05,3.319e-05,-5.5282e-05,-0.00022694,0.00014561,-0.00034885,-0.0043642,-0.00615,-0.0045863,-0.00615,-0.0043642,-0.00034885,0.00014561,-0.00022694,-5.5282e-05,3.319e-05,-1.1949e-05,-5.4078e-06,1.5685e-07,1.2671e-06,-1.5256e-06,9.8584e-07,-2.4771e-07,4.6019e-07,1.4841e-07, 2.343e-07,1.1197e-06,-5.5069e-07,2.1171e-06,-1.945e-06,4.519e-06,-3.5292e-06,4.0555e-07,4.8718e-07,1.5353e-05,-0.00010312,-0.00022987,-0.00092767,-0.0043642,-0.0079703,0.002361,0.014145,0.002361,-0.0079703,-0.0043642,-0.00092767,-0.00022987,-0.00010312,1.5353e-05,4.8718e-07,4.0555e-07,-3.5292e-06,4.519e-06,-1.945e-06,2.1171e-06,-5.5069e-07,1.1197e-06,2.343e-07, 2.5095e-07,1.766e-06,-1.0417e-06,3.3751e-06,-2.4459e-06,7.2838e-06,-6.9366e-06,1.175e-05,7.2008e-06,-1.1122e-05,-5.199e-05,-0.00011755,-0.0022122,-0.00615,0.002361,0.043915,0.076061,0.043915,0.002361,-0.00615,-0.0022122,-0.00011755,-5.199e-05,-1.1122e-05,7.2008e-06,1.175e-05,-6.9366e-06,7.2838e-06,-2.4459e-06,3.3751e-06,-1.0417e-06,1.766e-06,2.5095e-07, 2.4572e-07,2.0425e-06,-1.2882e-06,3.9459e-06,-2.7024e-06,8.3876e-06,-8.2415e-06,1.7539e-05,8.2578e-06,-2.2544e-05,5.4491e-06,5.7546e-05,-0.0022718,-0.0045863,0.014145,0.076061,0.12044,0.076061,0.014145,-0.0045863,-0.0022718,5.7546e-05,5.4491e-06,-2.2544e-05,8.2578e-06,1.7539e-05,-8.2415e-06,8.3876e-06,-2.7024e-06,3.9459e-06,-1.2882e-06,2.0425e-06,2.4572e-07, 2.5095e-07,1.766e-06,-1.0417e-06,3.3751e-06,-2.4459e-06,7.2838e-06,-6.9366e-06,1.175e-05,7.2008e-06,-1.1122e-05,-5.199e-05,-0.00011755,-0.0022122,-0.00615,0.002361,0.043915,0.076061,0.043915,0.002361,-0.00615,-0.0022122,-0.00011755,-5.199e-05,-1.1122e-05,7.2008e-06,1.175e-05,-6.9366e-06,7.2838e-06,-2.4459e-06,3.3751e-06,-1.0417e-06,1.766e-06,2.5095e-07, 2.343e-07,1.1197e-06,-5.5069e-07,2.1171e-06,-1.945e-06,4.519e-06,-3.5292e-06,4.0555e-07,4.8718e-07,1.5353e-05,-0.00010312,-0.00022987,-0.00092767,-0.0043642,-0.0079703,0.002361,0.014145,0.002361,-0.0079703,-0.0043642,-0.00092767,-0.00022987,-0.00010312,1.5353e-05,4.8718e-07,4.0555e-07,-3.5292e-06,4.519e-06,-1.945e-06,2.1171e-06,-5.5069e-07,1.1197e-06,2.343e-07, 1.4841e-07,4.6019e-07,-2.4771e-07,9.8584e-07,-1.5256e-06,1.2671e-06,1.5685e-07,-5.4078e-06,-1.1949e-05,3.319e-05,-5.5282e-05,-0.00022694,0.00014561,-0.00034885,-0.0043642,-0.00615,-0.0045863,-0.00615,-0.0043642,-0.00034885,0.00014561,-0.00022694,-5.5282e-05,3.319e-05,-1.1949e-05,-5.4078e-06,1.5685e-07,1.2671e-06,-1.5256e-06,9.8584e-07,-2.4771e-07,4.6019e-07,1.4841e-07, -6.9515e-10,1.1891e-08,-2.7198e-07,3.1609e-07,-1.0754e-06,-1.2838e-06,1.6616e-06,-2.1285e-06,-1.9554e-05,2.2956e-05,3.4991e-05,-0.00017577,-0.00014129,0.00014561,-0.00092767,-0.0022122,-0.0022718,-0.0022122,-0.00092767,0.00014561,-0.00014129,-0.00017577,3.4991e-05,2.2956e-05,-1.9554e-05,-2.1285e-06,1.6616e-06,-1.2838e-06,-1.0754e-06,3.1609e-07,-2.7198e-07,1.1891e-08,-6.9515e-10, -1.6191e-07,-2.0553e-07,-4.3263e-07,-7.8348e-08,-4.6194e-07,-2.2171e-06,3.1369e-07,3.7091e-06,-1.3554e-05,-5.9626e-06,6.1551e-05,1.2939e-05,-0.00017577,-0.00022694,-0.00022987,-0.00011755,5.7546e-05,-0.00011755,-0.00022987,-0.00022694,-0.00017577,1.2939e-05,6.1551e-05,-5.9626e-06,-1.3554e-05,3.7091e-06,3.1369e-07,-2.2171e-06,-4.6194e-07,-7.8348e-08,-4.3263e-07,-2.0553e-07,-1.6191e-07, -2.856e-07,-2.7219e-07,-4.9915e-07,-3.8192e-07,2.2358e-08,-1.4557e-06,-1.7349e-06,4.6284e-06,4.3871e-07,-1.6904e-05,8.1807e-06,6.1551e-05,3.4991e-05,-5.5282e-05,-0.00010312,-5.199e-05,5.4491e-06,-5.199e-05,-0.00010312,-5.5282e-05,3.4991e-05,6.1551e-05,8.1807e-06,-1.6904e-05,4.3871e-07,4.6284e-06,-1.7349e-06,-1.4557e-06,2.2358e-08,-3.8192e-07,-4.9915e-07,-2.7219e-07,-2.856e-07, -3.4356e-07,-2.7684e-07,-4.0892e-07,-5.3327e-07,5.2816e-08,-1.0007e-07,-1.9059e-06,8.6586e-07,6.8127e-06,-1.638e-06,-1.6904e-05,-5.9626e-06,2.2956e-05,3.319e-05,1.5353e-05,-1.1122e-05,-2.2544e-05,-1.1122e-05,1.5353e-05,3.319e-05,2.2956e-05,-5.9626e-06,-1.6904e-05,-1.638e-06,6.8127e-06,8.6586e-07,-1.9059e-06,-1.0007e-07,5.2816e-08,-5.3327e-07,-4.0892e-07,-2.7684e-07,-3.4356e-07, -3.301e-07,-2.6984e-07,-2.5775e-07,-4.3824e-07,-2.008e-07,5.1969e-07,-3.1224e-07,-1.5158e-06,2.2473e-06,6.8127e-06,4.3871e-07,-1.3554e-05,-1.9554e-05,-1.1949e-05,4.8718e-07,7.2008e-06,8.2578e-06,7.2008e-06,4.8718e-07,-1.1949e-05,-1.9554e-05,-1.3554e-05,4.3871e-07,6.8127e-06,2.2473e-06,-1.5158e-06,-3.1224e-07,5.1969e-07,-2.008e-07,-4.3824e-07,-2.5775e-07,-2.6984e-07,-3.301e-07, -2.6422e-07,-2.4966e-07,-1.5906e-07,-2.0036e-07,-2.9598e-07,2.2502e-07,7.6089e-07,-3.6682e-07,-1.5158e-06,8.6586e-07,4.6284e-06,3.7091e-06,-2.1285e-06,-5.4078e-06,4.0555e-07,1.175e-05,1.7539e-05,1.175e-05,4.0555e-07,-5.4078e-06,-2.1285e-06,3.7091e-06,4.6284e-06,8.6586e-07,-1.5158e-06,-3.6682e-07,7.6089e-07,2.2502e-07,-2.9598e-07,-2.0036e-07,-1.5906e-07,-2.4966e-07,-2.6422e-07, -1.8157e-07,-1.9687e-07,-1.2772e-07,-3.3299e-08,-1.2201e-07,-1.3261e-07,4.0958e-07,7.6089e-07,-3.1224e-07,-1.9059e-06,-1.7349e-06,3.1369e-07,1.6616e-06,1.5685e-07,-3.5292e-06,-6.9366e-06,-8.2415e-06,-6.9366e-06,-3.5292e-06,1.5685e-07,1.6616e-06,3.1369e-07,-1.7349e-06,-1.9059e-06,-3.1224e-07,7.6089e-07,4.0958e-07,-1.3261e-07,-1.2201e-07,-3.3299e-08,-1.2772e-07,-1.9687e-07,-1.8157e-07, -1.1145e-07,-1.1915e-07,-1.0363e-07,-1.2704e-08,4.4257e-08,-8.2062e-08,-1.3261e-07,2.2502e-07,5.1969e-07,-1.0007e-07,-1.4557e-06,-2.2171e-06,-1.2838e-06,1.2671e-06,4.519e-06,7.2838e-06,8.3876e-06,7.2838e-06,4.519e-06,1.2671e-06,-1.2838e-06,-2.2171e-06,-1.4557e-06,-1.0007e-07,5.1969e-07,2.2502e-07,-1.3261e-07,-8.2062e-08,4.4257e-08,-1.2704e-08,-1.0363e-07,-1.1915e-07,-1.1145e-07, -6.0455e-08,-4.9927e-08,-5.5309e-08,-4.0323e-08,3.1377e-08,4.4257e-08,-1.2201e-07,-2.9598e-07,-2.008e-07,5.2816e-08,2.2358e-08,-4.6194e-07,-1.0754e-06,-1.5256e-06,-1.945e-06,-2.4459e-06,-2.7024e-06,-2.4459e-06,-1.945e-06,-1.5256e-06,-1.0754e-06,-4.6194e-07,2.2358e-08,5.2816e-08,-2.008e-07,-2.9598e-07,-1.2201e-07,4.4257e-08,3.1377e-08,-4.0323e-08,-5.5309e-08,-4.9927e-08,-6.0455e-08, -2.0774e-08,-9.8996e-09,-1.0239e-08,-3.2372e-08,-4.0323e-08,-1.2704e-08,-3.3299e-08,-2.0036e-07,-4.3824e-07,-5.3327e-07,-3.8192e-07,-7.8348e-08,3.1609e-07,9.8584e-07,2.1171e-06,3.3751e-06,3.9459e-06,3.3751e-06,2.1171e-06,9.8584e-07,3.1609e-07,-7.8348e-08,-3.8192e-07,-5.3327e-07,-4.3824e-07,-2.0036e-07,-3.3299e-08,-1.2704e-08,-4.0323e-08,-3.2372e-08,-1.0239e-08,-9.8996e-09,-2.0774e-08, 1.1371e-08,9.2313e-09,7.1241e-09,-1.0239e-08,-5.5309e-08,-1.0363e-07,-1.2772e-07,-1.5906e-07,-2.5775e-07,-4.0892e-07,-4.9915e-07,-4.3263e-07,-2.7198e-07,-2.4771e-07,-5.5069e-07,-1.0417e-06,-1.2882e-06,-1.0417e-06,-5.5069e-07,-2.4771e-07,-2.7198e-07,-4.3263e-07,-4.9915e-07,-4.0892e-07,-2.5775e-07,-1.5906e-07,-1.2772e-07,-1.0363e-07,-5.5309e-08,-1.0239e-08,7.1241e-09,9.2313e-09,1.1371e-08, 3.2397e-08,2.2705e-08,9.2313e-09,-9.8996e-09,-4.9927e-08,-1.1915e-07,-1.9687e-07,-2.4966e-07,-2.6984e-07,-2.7684e-07,-2.7219e-07,-2.0553e-07,1.1891e-08,4.6019e-07,1.1197e-06,1.766e-06,2.0425e-06,1.766e-06,1.1197e-06,4.6019e-07,1.1891e-08,-2.0553e-07,-2.7219e-07,-2.7684e-07,-2.6984e-07,-2.4966e-07,-1.9687e-07,-1.1915e-07,-4.9927e-08,-9.8996e-09,9.2313e-09,2.2705e-08,3.2397e-08, 4.1243e-08,3.2397e-08,1.1371e-08,-2.0774e-08,-6.0455e-08,-1.1145e-07,-1.8157e-07,-2.6422e-07,-3.301e-07,-3.4356e-07,-2.856e-07,-1.6191e-07,-6.9515e-10,1.4841e-07,2.343e-07,2.5095e-07,2.4572e-07,2.5095e-07,2.343e-07,1.4841e-07,-6.9515e-10,-1.6191e-07,-2.856e-07,-3.4356e-07,-3.301e-07,-2.6422e-07,-1.8157e-07,-1.1145e-07,-6.0455e-08,-2.0774e-08,1.1371e-08,3.2397e-08,4.1243e-08)); cv::copyMakeBorder(c1,c2,33,33,33,33,cv::BORDER_DEFAULT); for(int i = 0; i < src.rows; i++) { for(int j = 0; j < src.cols; j++) { cv::Mat block_ij(c2, cv::Rect(i, j, 67, 67)); /* Tamanho do bloco: 33 + 33 + 1 */ cv::meanStdDev(block_ij,mean,std); dest.at<float>(i,j) = std[0]/mean[0]; } } return ; }
void filterHantaoV(const cv::Mat & src,cv::Mat & dest) { conv2D(src,dest,(cv::Mat_<float>(5,5) << 1,1,1,1,1, 1,2,2,2,1, 0,0,0,0,0, 1,2,2,2,1, 1,1,1,1,1)); return ; }
void filterLawsV(const cv::Mat & src,cv::Mat & dest,float r) { conv2D(src,dest,(cv::Mat_<float>(5,5) << 1/r, 4/r, 6/r, 4/r, 1/r, 2/r, 8/r, 12/r, 8/r, 2/r, 0 , 0 , 0 , 0 , 0 , -2/r,-8/r,-12/r,-8/r,-2/r, -1/r,-4/r, -6/r,-4/r,-1/r)); return ; }
int main(int argc, char *argv[]) { DATA_TYPE *A; DATA_TYPE *B_outputFromGpu; ///////////////////////// size_t oldSizes[2] = { NI, NJ }; size_t newSizes[2]; getNewSizes(oldSizes, NULL, newSizes, NULL, "Convolution2D_kernel", 2); NI = newSizes[0]; NJ = newSizes[1]; ///////////////////////// A = (DATA_TYPE *)malloc(NI * NJ * sizeof(DATA_TYPE)); B_outputFromGpu = (DATA_TYPE *)malloc(NI * NJ * sizeof(DATA_TYPE)); init(A); platform = new Platform(PLATFORM_ID); context = platform->getContext(); Device device = platform->getDevice(DEVICE_ID); Queue queue = Queue(*context,device,Queue::EnableProfiling); cl_mem_init(A,queue); SourceFile kernelFile = KERNEL_DIRECTORY KERNEL_FILE_NAME; // Create a program from the kernel source Program program(context,kernelFile); if(!program.build(device)) { std::cout << "Error building the program: " << "\n"; std::cout << program.getBuildLog(device) << "\n"; return 1; } // Create the OpenCL kernel kernel = program.createKernel(kernelName.c_str()); cl_launch_kernel(queue); queue.readBuffer(*b_mem_obj,NI * NJ * sizeof(DATA_TYPE),(void*) B_outputFromGpu); queue.finish(); conv2D(A, B_outputFromGpu); free(A); free(B_outputFromGpu); cl_clean_up(); return 0; }
int main( int argc, char ** argv ) { // Normalize the kernel so that it produces correct colors. normalize(kernel); float *in_image, *out_image, *out_ref_image, *in_image1, *in_image2, *in_image3; int real_image = 0, repeat = 0; unsigned char info[54]; int size, color_table_size, color_size, x_dim, y_dim; unsigned char * color_table; if ( argc == 3 ) { x_dim = atoi(argv[1]); y_dim = atoi(argv[2]); repeat = 1; } else if ( argc == 2 ) { real_image = 1; repeat = 1; FILE* f = fopen(argv[1], "rb"); int check = fread(info, sizeof(unsigned char), 54, f); // Read the 54-byte info header color_table_size = *((int*)(info + 0x0a))- 54; color_table = (unsigned char *) malloc(sizeof(unsigned char) * color_table_size); check = fread(color_table, sizeof(unsigned char), color_table_size, f); color_size = *((int*)(info + 0x1c)); if (*((int*)(info + 0x0e)) != 40 || (color_size != 8 && color_size != 32) ) { printf( "Sorry this file format is not supported yet. Please use a different image!\nBMP pictures with 8 bits per pixel grayscale (may be different from seemingly grayscale pictures that actually uses 4 colors) and 32 bit per pixel color image.\n" ); return -1; } color_size /= 8; x_dim = *((int*)(info + 0x12)); y_dim = *((int*)(info + 0x16)); x_dim = (x_dim > 0) ? x_dim : -1 * x_dim; y_dim = (y_dim > 0) ? y_dim : -1 * y_dim; size = x_dim * y_dim; unsigned char data[size*color_size]; check = fread(data, sizeof(unsigned char), size * color_size, f); fclose(f); in_image = (float *) malloc(sizeof(float) * size); if (color_size > 1) { in_image1 = (float *) malloc(sizeof(float) * size); in_image2 = (float *) malloc(sizeof(float) * size); in_image3 = (float *) malloc(sizeof(float) * size); } out_image = (float *) malloc(sizeof(float) * size); out_ref_image = (float *) malloc(sizeof(float) * size); for (int i = 0; i < size; i++) { in_image[i] = ((float) data[i*color_size])/255; if (color_size > 1) { in_image1[i] = ((float) data[i*color_size+1]/255); in_image2[i] = ((float) data[i*color_size+2]/255); in_image3[i] = ((float) data[i*color_size+3]/255); } } } double total_Gflop_s = 0; double total_iterations = 0; for ( int counter = 0; counter < 10 && (repeat || (!counter)); counter++ ) { for ( int x = minimum; x < maximum; x+=step ) { for ( int y = minimum; y < maximum; y+=step ) { if (repeat) { x = x_dim; y = y_dim; maximum = ( x_dim > y_dim ) ? y_dim-1 : x_dim-1; } if (!real_image) { in_image = (float*) malloc( x * y * sizeof(float) ); out_image = (float*) malloc( x * y * sizeof(float) ); out_ref_image = (float*) malloc( x * y * sizeof(float) ); for( int i = 0; i < x * y; i++ ) in_image[i] = 2 * drand48() - 1; } // Clear the memory of reference and output to be used to check for correctness. memset( out_ref_image, 0, sizeof(float) * x * y ); reference( in_image, out_ref_image, x, y, kernel ); memset( out_image, 0, sizeof(float) * x * y ); conv2D( in_image, out_image, x, y, kernel ); // Subtract out the difference to figure out how large it is. If the difference is large enough, then error out. for ( int i = 0; i < x * y; i++ ) { float temp = out_image[i] - out_ref_image[i]; if ( temp * temp > 0.0001 ) { printf( "FAILURE: error in convolution calculation exceeds an acceptable margin.\n" ); printf( "Expected: %f, received: %f, with image size x = %d, y = %d at array location: %d\n", out_ref_image[i], out_image[i], x, y, i ); return -1; } } double Gflop_s, seconds = -1.0; for( int n_iterations = 1; seconds < 0.1; n_iterations *= 2) { /* warm-up */ conv2D( in_image, out_image, x, y, kernel); /* measure time */ struct timeval start, end; gettimeofday( &start, NULL ); for( int i = 0; i < n_iterations; i++ ) conv2D( in_image, out_image, x, y, kernel); gettimeofday( &end, NULL ); seconds = (end.tv_sec - start.tv_sec) + 1.0e-6 * (end.tv_usec - start.tv_usec); /* compute Gflop/s rate */ Gflop_s = 2e-9 * n_iterations * 2 * x * y * 9 / seconds; } printf( "Dimemsions: x = %d, y = %d \t Performance: %g Gflop/s\n", x, y, Gflop_s ); total_Gflop_s += Gflop_s; total_iterations++; if (!real_image) { free(in_image); free(out_image); free(out_ref_image); } } // End of y loop } // End of x loop } // End of counter loop double average = total_Gflop_s / total_iterations; printf( "Average Gflop/s = %g\n", average ); if (real_image) { unsigned char data[size*color_size]; float out_image1[size], out_image2[size]; if (color_size > 1) { conv2D( in_image1, out_image1, x_dim, y_dim, kernel); conv2D( in_image2, out_image2, x_dim, y_dim, kernel); } for (int i = 0; i < size; i++) { data[i*color_size] = (unsigned char) (out_image[i] * 255); if (color_size > 1) { data[i*color_size+1] = (unsigned char) (out_image1[i] * 255); data[i*color_size+2] = (unsigned char) (out_image2[i] * 255); data[i*color_size+3] = (unsigned char) (in_image3[i] * 255); } } FILE* f = fopen("out_img.bmp", "wb"); fwrite(info, sizeof(unsigned char), 54, f); fwrite(color_table, sizeof(unsigned char), color_table_size, f); fwrite(data, sizeof(unsigned char), size*color_size, f); fclose(f); free(in_image); free(out_image); free(out_ref_image); free(color_table); if (color_size > 1) { free(in_image1); free(in_image2); free(in_image3); } } // End of real image storing return 0; } // End of main
void xwMigr3d(complex *src, complex *rec, float *velocity, float vmin, int oplx, int oply, int order, int McC, float om, int nterms, int filter_inc, int ntap, int tap_opt, Area *area, int zomigr, int method) { /* Extrapolate the data */ if (!zomigr) { if (method == 1) { conv2D(src,velocity,oplx,oply,om,area,1); conv2D(rec,velocity,oplx,oply,om,area,-1); } else if (method == 2) { if (McC == 1) { conv2DMcC(src,velocity,order,om,area,1); conv2DMcC(rec,velocity,order,om,area,-1); } else if (McC == 2) { conv2DMcC_2(src,velocity,order,om,area,1); conv2DMcC_2(rec,velocity,order,om,area,-1); } } else if (method == 3) { conv_kxw_sr(src,rec,velocity,om,ntap,area); } /* else if (method == 4) { conv_FD( rec, velocity, vmin, om, nterms, filter_inc, area, -1); conv_FD( src, velocity, vmin, om, nterms, filter_inc, area, 1); } */ if (ntap) { taperedges(tap_opt, ntap, rec, area); taperedges(tap_opt, ntap, src, area); } } else { if (method == 1) { conv2D(rec,velocity,oplx,oply,om,area,-1); } else if (method == 2) { if (McC == 1) { conv2DMcC(rec,velocity,order,om,area,-1); } else if (McC == 2) { conv2DMcC_2(rec,velocity,order,om,area,-1); } } else if (method == 3) { conv_kxw(rec,velocity,om,ntap,area,-1); } /* else if (method == 4) { conv_FD( rec, velocity, vmin, om, nterms, filter_inc, area, -1); } */ if (ntap) { taperedges(tap_opt, ntap, rec, area); } } return; }