#include <iostream>
#include <ctime>
#include"FFTROISource.h"
#include<DSP_GEN.H>
#include "DSP_LIB.H"
#include "DSP_gEN.H"
#include<DSP_GEN.h>
#include<windows.h>
#include<FILE.H>
#include"A2D.h"
#include<ipp.h>
#include "cuda_runtime.h"
#include "cufft.h" //??cuda?????????,??????lib?
#include "device_launch_parameters.h"
using namespace std;
int main()
{
IMG_WORD wsts = 0;
IMG_UBBUF
ubbImg;//read img
IMG_SIZE
szImSize;
IppiSize SrcROISize;
IMG_COORD
coDoff = {0,0};
int StepBytes;
A2D_COMPLEX_IMG stCImg;
IMG_UBYTE pubFilePath[] = "4096R.bmp";
if (OK != (wsts = FILE_ImageSize(pubFilePath, &szImSize)))// get img size
{
printf("get img size error!\n");
return wsts;
}
ubbImg.size = szImSize;
ubbImg.linestep = szImSize.x;
if (NULL == (ubbImg.ptr = ippiMalloc_8u_C1(szImSize.x, szImSize.y, &StepBytes))) //SrcImg melloc
{
printf("SrcImg melloc error!\n");
return A2D_ERR_MALLOC;
}
if (OK != (wsts = FILE_LoadImageExt2(pubFilePath, &coDoff, &szImSize, &ubbImg, 1)))//read img
{
printf("read img error!\n");
return wsts;
}
else
{
cout << "success to read image" << endl;
}
if (NULL == (stCImg.m_prRe = ippiMalloc_32f_C1(szImSize.x, szImSize.y, &StepBytes)))
{
printf("m_prRe melloc error!\n");
return A2D_ERR_MALLOC;
}
if (NULL == (stCImg.m_prIm = ippiMalloc_32f_C1(szImSize.x, szImSize.y, &StepBytes)))
{
printf("m_prIm melloc error!\n");
return A2D_ERR_MALLOC;
}
stCImg.size = szImSize;
stCImg.uwlinestep = stCImg.size.x;
SrcROISize.height = szImSize.y;
SrcROISize.width = szImSize.x;
ippiConvert_8u32f_C1R(ubbImg.ptr, ubbImg.linestep, stCImg.m_prRe, szImSize.x * sizeof(Ipp32f), SrcROISize);
clock_t start = clock();
//SYS_TimerObjectClick("CUDA_FFT_start");
cudaSetDevice(0);
//IMG_REAL* h_DataRead = (IMG_REAL*)ubbImg.ptr;
IMG_REAL* h_DataRead=(IMG_REAL*)asm_malloc((szImSize.x * szImSize.y) * sizeof(IMG_REAL));
for (IMG_UWORD uwY = 0; uwY < szImSize.y; ++uwY)
{
for (IMG_UWORD uwX = 0; uwX < szImSize.x; ++uwX)
{
h_DataRead[uwY*szImSize.x + uwX] = ubbImg.ptr[uwY*(szImSize.x) + uwX];
}
}
cufftComplex* h_DataComplex;
const int dataH = szImSize.x;//?
const int dataW = szImSize.y;//?
h_DataComplex = (cufftComplex*)asm_malloc(dataH*dataW * sizeof(cufftComplex));//????
for (int i = 0; i < dataH*dataW; i++)
{
h_DataComplex[i].x = h_DataRead[i];
h_DataComplex[i].y = 0.0f;
}
cufftComplex
*d_data,
*d_DataSpectrum,
*d_Result,
*h_Result;
cufftHandle fftPlanFwd;//, fftPlanInv;
h_Result = (cufftComplex*)asm_malloc(dataH*dataW * sizeof(cufftComplex));
cudaMalloc((void**)&d_DataSpectrum, dataH*dataW * sizeof(cufftComplex));
cudaMalloc((void**)&d_data, dataH*dataW * sizeof(cufftComplex));
cudaMalloc((void**)&d_Result, dataH*dataW * sizeof(cufftComplex));
//?????
cudaMemcpy(d_data, h_DataComplex, dataH*dataW * sizeof(cufftComplex), cudaMemcpyHostToDevice);
//????
/**
* cufftPlan2d(??????,?,?,????)????
* cufftPlan1d(??????,?,????,?)????
* ????:C2C(?????)? R2C(?????)? C2R(?????)
* CUFFT_FORWARD:????
*/
//cufftPlan2d(&fftPlanFwd, dataH, dataW, CUFFT_C2C);//????
cufftPlan1d(&fftPlanFwd, dataW, CUFFT_C2C, dataH);//????
cufftExecC2C(fftPlanFwd, (cufftComplex*)d_data, (cufftComplex*)d_DataSpectrum, CUFFT_FORWARD);
//?????
cudaMemcpy(h_Result, d_DataSpectrum, dataH*dataW * sizeof(cufftComplex), cudaMemcpyDeviceToHost);
std::cerr << (double)(clock() - start) << "\n";
//SYS_TimerObjectClick("CUDA_FFT_END");
//SYS_TimerObjectDump("TimeLog.txt");
Ipp32fc* pfc;
IMG_SIZE
szImFFTColSize = {0};
//A2D_COMPLEX_IMG * pstDstImg = NULL;
//if (NULL == (pstDstImg = (A2D_COMPLEX_IMG*)asm_malloc(sizeof(A2D_COMPLEX_IMG))))
// return A2D_ERR_MALLOC;
//pstDstImg->size.x = 512;
//pstDstImg->size.y = 512;
//pstDstImg->uwlinestep = pstDstImg->size.x;
//if (NULL == (pstDstImg->m_prRe = ippiMalloc_32f_C1(pstDstImg->size.x, pstDstImg->size.y, &StepBytes))) //?????????
//{
// printf("pstDstImg[i].m_prRe melloc error!\n");
// return A2D_ERR_MALLOC;
//}
//if (NULL == (pstDstImg->m_prIm = ippiMalloc_32f_C1(pstDstImg->size.x, pstDstImg->size.y, &StepBytes))) //?????????
//{
// printf("pstDstImg[i].m_prIm melloc error!\n");
// return A2D_ERR_MALLOC;
//}
szImFFTColSize = szImSize;
if (NULL == (pfc = ippiMalloc_32fc_C1(szImFFTColSize.x, szImFFTColSize.y, &StepBytes)))
{
printf("puMemory melloc error!\n");
return -2;
}
//for (int i = 0; i < szImFFTColSize.y; ++i)
//{
// for (int j = 0; j < szImFFTColSize.x; ++j)
// {
// /*pfc[i*szImFFTColSize.x + j].re = pstDstImg[0].m_prRe[i*szImFFTColSize.x + j];
// pfc[i*szImFFTColSize.x + j].im = pstDstImg[0].m_prIm[i*szImFFTColSize.x + j];*/
// pfc[i*szImFFTColSize.x + j].re = pstDstImg[0].m_prRe[i*szImFFTColSize.x + j];
// pfc[i*szImFFTColSize.x + j].im = 0;
// //pfc2[i*szImFFTColSize.x + j].re = pstDstImg[1].m_prRe[i*szImFFTColSize.x + j];
// //pfc2[i*szImFFTColSize.x + j].im = pstDstImg[1].m_prIm[i*szImFFTColSize.x + j];
// }
//}
for (int i = 0; i < dataH; i++) {
for (int j = 0; j < dataW; j++) {
pfc[j].re = h_Result[i*dataW + j].x;
//pfc[j].im = h_Result[i*dataW + j].y;
pfc[j].im = 0;
}
}
IppiSize ImgSize;
IMG_RBUF rbRowFFTbuf;
rbRowFFTbuf.linestep = szImFFTColSize.x;
rbRowFFTbuf.size = szImFFTColSize;
rbRowFFTbuf.ptr = (IMG_REAL*)pfc;
ImgSize.height = rbRowFFTbuf.size.y;
ImgSize.width = rbRowFFTbuf.size.x;
Ipp32f* prFftModule;
if (NULL == (prFftModule = ippiMalloc_32f_C1(rbRowFFTbuf.size.x, rbRowFFTbuf.size.y, &StepBytes)))//remember free mem
{
printf("puMemory melloc error!\n");
return -2;
}
ippiMagnitude_32fc32f_C1R((Ipp32fc*)rbRowFFTbuf.ptr, rbRowFFTbuf.linestep * sizeof(Ipp32fc), prFftModule, rbRowFFTbuf.linestep * sizeof(Ipp32f), ImgSize);
Ipp32f MaxPixe, MinPixe;
//ippiMax_32f_C1R(prFftModule, rbRowFFTbuf.linestep * sizeof(Ipp32f), ImgSize, &MaxPixe);
//ippiMin_32f_C1R(prFftModule, rbRowFFTbuf.linestep * sizeof(Ipp32f), ImgSize, &MinPixe);
//Magnitude+1 avoid ln(0)
ippiAddC_32f_C1IR(1.0, prFftModule, rbRowFFTbuf.linestep * sizeof(Ipp32f), ImgSize);
//ln
ippiLn_32f_C1IR(prFftModule, rbRowFFTbuf.linestep * sizeof(Ipp32f), ImgSize);
ippiMax_32f_C1R(prFftModule, rbRowFFTbuf.linestep * sizeof(Ipp32f), ImgSize, &MaxPixe);
ippiMin_32f_C1R(prFftModule, rbRowFFTbuf.linestep * sizeof(Ipp32f), ImgSize, &MinPixe);
IMG_UBBUF ubboutImg;
ubboutImg.linestep = rbRowFFTbuf.linestep;
ubboutImg.size = rbRowFFTbuf.size;
if (NULL == (ubboutImg.ptr = ippiMalloc_8u_C1(rbRowFFTbuf.size.x, rbRowFFTbuf.size.y, &StepBytes)))//remember free mem
{
printf("puMemory melloc error!\n");
return -2;
}
ippiConvert_32f8u_C1R(prFftModule, rbRowFFTbuf.linestep * sizeof(Ipp32f), ubboutImg.ptr, ubboutImg.linestep, ImgSize, ippRndNear);
IMG_UBYTE uHdrImageName1[] = "512x512FFTROI.bmp";
if (OK != (wsts = FILE_SaveImage(&ubboutImg, &coDoff, &ubboutImg.size, uHdrImageName1)))
{
ippiFree(ubboutImg.ptr);
ippiFree(ubbImg.ptr);
printf("save image error!\n");
return 0;
}
cudaFree(d_Result);
cudaFree(d_data);
cudaFree(d_DataSpectrum);
cufftDestroy(fftPlanFwd);
asm_free(h_Result);
asm_free(h_DataComplex);
cudaDeviceReset();
ippiFree(prFftModule);
//asm_free(pstDstImg);
system("pause");
return 0;
}
11111111111111111111111111111
需积分: 6 27 浏览量
2022-11-07
18:54:09
上传
评论
收藏 177.82MB ZIP 举报
Indulgeinthedeam
- 粉丝: 24
- 资源: 8
最新资源
- 基于STM32单片机空气监测系统设计源码+详细文档+配套全部资料(毕业设计).zip
- rdf0412-kcu116-pcie-c-2019-1.zip(XILINX KCU116 源码)
- 基于C#语言的winform界面火车票订票系统(源码+实验报告)
- 【华为OD部分真题及讲解】华为OD部分真题及讲解
- 基于Python+Django的京东商品比价系统源码+全部资料(毕业设计).zip
- G460 G560 Z460 Z560的最新BIOS 2.18版(无白名单)
- MetaJUI v0.4
- 基于Python+Django的京东商品比价系统源码+全部资料(毕业设计).zip
- linux常用命令大全
- 立体相机标定-使用OpenCV+Cpp对立体相机进行标定-calibration-附项目源码+流程教程-优质项目实战.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈