Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

dft and normalize

one image first do dft and then do a circle mask its frequency field, which means the pixel value is zero on the corner, after that, do inverse dft on it to back image. until now, every thing is OK, No problem.

but when I normailze the image and convert it to 16 bit. it is wrong. I do fft on the result image on imagej, and its corner is not zero.

normalize(clean_sf,clean_sf,0,1,CV_MINMAX); clean_sf.convertTo(result,CV_16UC1,65536);

dft and normalize

one image first do was processed by dft and then do a circle mask its frequency field, which means the pixel value is zero on the corner, after that, do inverse dft on it to back image. until now, every thing is OK, No problem.

but when I normailze the image and convert it to 16 bit. it is wrong. I do fft on the result image on imagej, and its corner is not zero.

normalize(clean_sf,clean_sf,0,1,CV_MINMAX); clean_sf.convertTo(result,CV_16UC1,65536);

dft and normalize

one image first was processed by dft and then do a circle mask its frequency field, which means the pixel value is zero on the corner, after that, do inverse dft on it to back image. until now, every thing is OK, No problem.

but when I normailze the image and convert it to 16 bit. it is wrong. I do fft on the result image on imagej, and its corner is not zero.

normalize(clean_sf,clean_sf,0,1,CV_MINMAX); clean_sf.convertTo(result,CV_16UC1,65536);

// My question is simple, probably I did describe clear. I do some operation on frequency field(binary mask, to keep the center part, set other to zero). then back to real space. image description when I do fourier transform on the result image, I find they are not zero, but lower value. image description

I think the problem of normalize, but I do not understand.

dft and normalize

one image first was processed by dft and then do a circle mask its frequency field, which means the pixel value is zero on the corner, after that, do inverse dft on it to back image. until now, every thing is OK, No problem.

but when I normailze the image and convert it to 16 bit. it is wrong. I do fft on the result image on imagej, and its corner is not zero.

normalize(clean_sf,clean_sf,0,1,CV_MINMAX); clean_sf.convertTo(result,CV_16UC1,65536);

// My question is simple, probably I did describe clear. I do some operation on frequency field(binary mask, to keep the center part, set other to zero). then back to real space. image description when I do fourier transform on the result image, I find they are not zero, but lower value. image description

I think the problem of normalize, but I do not understand.

//////////////// I tried to upload image, but failed.

dft and normalize

one image first was processed by dft and then do a circle mask its frequency field, which means the pixel value is zero on the corner, after that, do inverse dft on it to back image. until now, every thing is OK, No problem.

but when I normailze the image and convert it to 16 bit. it is wrong. I do fft on the result image on imagej, and its corner is not zero.

normalize(clean_sf,clean_sf,0,1,CV_MINMAX); clean_sf.convertTo(result,CV_16UC1,65536);

// My question is simple, probably I did describe clear. I do some operation on frequency field(binary mask, to keep the center part, set other to zero). then back to real space.

image description

when I do fourier transform on the result image, I find they are not zero, but lower value. image descriptionvalue.

I think the problem of normalize, but I do not understand.

//////////////// I tried to upload image, but failed.

dft and normalize

one image first was processed by dft and then do a circle mask its frequency field, which means the pixel value is zero on the corner, after that, do inverse dft on it to back image. until now, every thing is OK, No problem.

but when I normailze the image and convert it to 16 bit. it is wrong. I do fft on the result image on imagej, and its corner is not zero.

normalize(clean_sf,clean_sf,0,1,CV_MINMAX); clean_sf.convertTo(result,CV_16UC1,65536);

// My question is simple, probably I did describe clear. I do some operation on frequency field(binary mask, to keep the center part, set other to zero). then back to real space.

when I do fourier transform on the result image, I find they are not zero, but lower value.

I think the problem of normalize, but I do not understand.

//////////////// I tried to upload image, but failed.

///////////////////// I think there is a problem on DFT. step 1. do some operation in fourier space(fig.1 is the amplitude of it). step 2. dft back to real space

dft(clean_sf,clean_sf,DFT_INVERSE|DFT_REAL_OUTPUT);

step 3. dft back to fourier space and generate the amplitude spectrum(fig. 2)

void FftOperation(Mat & img, Mat & complexI)

{ Mat padded; //expand input image to optimal size int m = getOptimalDFTSize( img.rows ); int n = getOptimalDFTSize( img.cols ); // on the border add zero values copyMakeBorder(img, padded, 0, m - img.rows, 0, n - img.cols, BORDER_CONSTANT, Scalar::all(0)); //copyMakeBorder(img, img, img.rows/4, img.rows/4, img.cols/4, img.cols/4, BORDER_CONSTANT, Scalar::all(0));

padded = Mat_<float>(padded);
Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};   //Mat array, two Mats inside, Mat one is padded which include image, Mat two is zero mat.
//Mat complexI;
merge(planes, 2, complexI);         // Add to the expanded another plane with zeros, merge the two Mats into a Mat which has two channels(channel one is image, equal real part, channel two zero, equal imaginary part.).

dft(complexI, complexI);            // this way the result may fit in the source matrix,  for channel one store real part, channel two imaginary part(now is not zero).

 // crop the spectrum, if it has an odd number of rows or columns
//complexI = complexI(Rect(complexI.cols/6, complexI.rows/6, 2*complexI.cols/3, 2*complexI.rows/3));
complexI = complexI(Rect(0, 0, complexI.cols & -2, complexI.rows & -2));

SwitchQua(complexI);

}

fig.1 and fig.2 should the same. but it different.

fig.1 image description

fig.2 image description

dft and normalize

one image first was processed by dft and then do a circle mask its frequency field, which means the pixel value is zero on the corner, after that, do inverse dft on it to back image. until now, every thing is OK, No problem.

but when I normailze the image and convert it to 16 bit. it is wrong. I do fft on the result image on imagej, and its corner is not zero.

normalize(clean_sf,clean_sf,0,1,CV_MINMAX); clean_sf.convertTo(result,CV_16UC1,65536);

// My question is simple, probably I did describe clear. I do some operation on frequency field(binary mask, to keep the center part, set other to zero). then back to real space.

when I do fourier transform on the result image, I find they are not zero, but lower value.

I think the problem of normalize, but I do not understand.

//////////////// I tried to upload image, but failed.

///////////////////// I think there is a problem on DFT. step 1. do some operation in fourier space(fig.1 is the amplitude of it). step 2. dft back to real space

dft(clean_sf,clean_sf,DFT_INVERSE|DFT_REAL_OUTPUT);

step 3. dft back to fourier space and generate the amplitude spectrum(fig. 2)

void FftOperation(Mat & img, Mat & complexI)

{ Mat padded; //expand input image to optimal size int m = getOptimalDFTSize( img.rows ); int n = getOptimalDFTSize( img.cols ); // on the border add zero values copyMakeBorder(img, padded, 0, m - img.rows, 0, n - img.cols, BORDER_CONSTANT, Scalar::all(0)); //copyMakeBorder(img, img, img.rows/4, img.rows/4, img.cols/4, img.cols/4, BORDER_CONSTANT, Scalar::all(0));

padded = Mat_<float>(padded);
Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};   //Mat array, two Mats inside, Mat one is padded which include image, Mat two is zero mat.
//Mat complexI;
merge(planes, 2, complexI);         // Add to the expanded another plane with zeros, merge the two Mats into a Mat which has two channels(channel one is image, equal real part, channel two zero, equal imaginary part.).

dft(complexI, complexI);            // this way the result may fit in the source matrix,  for channel one store real part, channel two imaginary part(now is not zero).

 // crop the spectrum, if it has an odd number of rows or columns
//complexI = complexI(Rect(complexI.cols/6, complexI.rows/6, 2*complexI.cols/3, 2*complexI.rows/3));
complexI = complexI(Rect(0, 0, complexI.cols & -2, complexI.rows & -2));

SwitchQua(complexI);

}

fig.1 and fig.2 should the same. but it different.different.I mean the part out of circle in fig.2 should be zero, just like fig.1. but it is not.

fig.1 image descriptionimage description

fig.2 image descriptionimage description

dft and normalize

one image first was processed by dft and then do a circle mask its frequency field, which means the pixel value is zero on the corner, after that, do inverse dft on it to back image. until now, every thing is OK, No problem.

but when I normailze the image and convert it to 16 bit. it is wrong. I do fft on the result image on imagej, and its corner is not zero.

normalize(clean_sf,clean_sf,0,1,CV_MINMAX); clean_sf.convertTo(result,CV_16UC1,65536);

// My question is simple, probably I did describe clear. I do some operation on frequency field(binary mask, to keep the center part, set other to zero). then back to real space.

when I do fourier transform on the result image, I find they are not zero, but lower value.

I think the problem of normalize, but I do not understand.

//////////////// I tried to upload image, but failed.

///////////////////// /////////////////////

I think there is a problem on DFT. DFT.

step 1. do some operation in fourier space(fig.1 is the amplitude of it). it).

step 2. dft back to real space

dft(clean_sf,clean_sf,DFT_INVERSE|DFT_REAL_OUTPUT);

step 3. dft back to fourier space and generate the amplitude spectrum(fig. 2)

void FftOperation(Mat & img, Mat & complexI)

{ complexI){ Mat padded; //expand input image to optimal size int m = getOptimalDFTSize( img.rows ); int n = getOptimalDFTSize( img.cols ); // on the border add zero values copyMakeBorder(img, padded, 0, m - img.rows, 0, n - img.cols, BORDER_CONSTANT, Scalar::all(0)); //copyMakeBorder(img, img, img.rows/4, img.rows/4, img.cols/4, img.cols/4, BORDER_CONSTANT, Scalar::all(0));

 padded = Mat_<float>(padded);
Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};   //Mat array, two Mats inside, Mat one is padded which include image, Mat two is zero mat.
//Mat complexI;
 merge(planes, 2, complexI);         // Add to the expanded another plane with zeros, merge the two Mats into a Mat which has two channels(channel one is image, equal real part, channel two zero, equal imaginary part.).
 
dft(complexI, complexI);            // this way the result may fit in the source matrix,  for channel one store real part, channel two imaginary part(now is not zero).

 // crop the spectrum, if it has an odd number of rows or columns
//complexI = complexI(Rect(complexI.cols/6, complexI.rows/6, 2*complexI.cols/3, 2*complexI.rows/3));
 complexI = complexI(Rect(0, 0, complexI.cols & -2, complexI.rows & -2));

SwitchQua(complexI);

}

fig.1 and fig.2 should the same. but it different.I mean the part out of circle in fig.2 should be zero, just like fig.1. but it is not.

fig.1 image description

fig.2 image description

dft and normalize

one image first was processed by dft and then do a circle mask its frequency field, which means the pixel value is zero on the corner, after that, do inverse dft on it to back image. until now, every thing is OK, No problem.

but when I normailze the image and convert it to 16 bit. it is wrong. I do fft on the result image on imagej, and its corner is not zero.

normalize(clean_sf,clean_sf,0,1,CV_MINMAX); clean_sf.convertTo(result,CV_16UC1,65536);

// My question is simple, probably I did describe clear. I do some operation on frequency field(binary mask, to keep the center part, set other to zero). then back to real space.

when I do fourier transform on the result image, I find they are not zero, but lower value.

I think the problem of normalize, but I do not understand.

//////////////// I tried to upload image, but failed.

/////////////////////

I think there is a problem on DFT.

step 1. do some operation in fourier space(fig.1 is the amplitude of it).

step 2. dft back to real space

dft(clean_sf,clean_sf,DFT_INVERSE|DFT_REAL_OUTPUT);

step 3. dft back to fourier space and generate the amplitude spectrum(fig. 2)

void FftOperation(Mat & img, Mat & complexI){ 
Mat padded;                           
int m = getOptimalDFTSize( img.rows );
int n = getOptimalDFTSize( img.cols ); 
copyMakeBorder(img, padded, 0, m - img.rows, 0, n - img.cols, BORDER_CONSTANT, Scalar::all(0));


padded = Mat_<float>(padded);
Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};  
merge(planes, 2, complexI);         

dft(complexI, complexI);            
complexI = complexI(Rect(0, 0, complexI.cols & -2, complexI.rows & -2));

SwitchQua(complexI);

}

void ShowMagnitude(string WindowName,Mat img) {

Mat planes[] = { Mat::zeros(img.size(),CV_32F), Mat::zeros(img.size(), CV_32F) };   

 //split 
split(img,planes);

//magintude
magnitude(planes[0],planes[1],planes[0]);
Mat magI = planes[0];

magI += Scalar::all(1);
log(magI,magI);

normalize(magI, magI, 0, 1, CV_MINMAX);
imshow(WindowName, magI);
Mat saveImg;
magI.convertTo(saveImg, CV_8UC1,255);
imwrite(WindowName+".tif", saveImg);

}

fig.1 and fig.2 should the same. but it different.I mean the part out of circle in fig.2 should be zero, just like fig.1. but it is not.

fig.1 image description

fig.2 image description