我试着用fftw和qt从图像列表中计算一个像素向量的快速傅立叶变换,并对所有图像的所有像素重复这个处理;向量包含im1的pix1.1,im2的pix1.1,imN的...pix1.1,问题是当图像数量很大时,程序会崩溃
const int Npoints(widget.imagelistWidget->count());
fftw_complex *in, *out;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*Npoints);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*Npoints);
double resfft;
fftw_plan p;
QList<QImage*> imageList;
QImage *imagef ;
for(int k=0;k<liste.size();k++)
{
imagef = new QImage;
imagef->load(liste[k]);
imageList.append(imagef);
}
for(int i=0;i<imagef->width();i++)
{
for(int j=0;j<imagef->height();j++)
{
for(int k=0;k<liste.size();k++)
{
imagef =imageList.at(k);
QRgb pixelfft=imagef->pixel(i,j);
double moyp= qGray(pixelfft);
in[k][0] = moyp;
in[k][1] = 0.0;
}
p = fftw_plan_dft_1d(Npoints, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(p);
//resultat
QVector<qreal> realV;
QVector<qreal> imgV;
for (int s = 0; s < Npoints; s++)
{
realV.append(out[s][0]);
imgV.append(out[s][1]);
}
for(int l=0;l<liste.size();++l)
{
resfft = sqrt((realV[l] * realV[l]) + (imgV[l] * imgV[l]));
imagef=imageList.at(l);
imagef->setPixel(i,j,qGray(qRgb(resfft,resfft,resfft)));
}
}
} 发布于 2016-01-29 00:09:31
我认为这就是@bibi的评论的意思,但这部分看起来是错的:
for(int i=0;i<imagef->width();i++)
{
for(int j=0;j<imagef->height();j++)
{
for(int k=0;k<liste.size();k++)
{
imagef =imageList.at(k);
QRgb pixelfft=imagef->pixel(i,j);
double moyp= qGray(pixelfft);
in[k][0] = moyp;
in[k][1] = 0.0;
} 您的循环似乎顺序错误。当您调用width和height时,您不会在内部循环中的当前图像上调用它们。相反,您可能需要的是:
for(int k=0;k<liste.size();k++)
{
//Get the current image from the list
imagef = imageList.at(k);
//Loop over every pixel in the image
for(int i=0;i<imagef->width();i++)
{
for(int j=0;j<imagef->height();j++)
{
QRgb pixelfft=imagef->pixel(i,j);
double moyp= qGray(pixelfft);
in[k][0] = moyp;
in[k][1] = 0.0;
}
}
/*...*/https://stackoverflow.com/questions/35065617
复制相似问题