How to reconstruct an image from Real and Imaginary part?

22 Ansichten (letzte 30 Tage)
Peter Phan
Peter Phan am 16 Dez. 2021
Bearbeitet: Peter Phan am 16 Dez. 2021
Hi everyone,
I am very new to Matlab and image processing. I have an image of phantom('Modified Shepp-Logan',200).Then, I use Fourier transformation to extract the Real and the Imaginary. After all, I want to modify the Real part as well as the Imaginary part by multiply each of them with a weighting score.
The out put is look like this.
I would like to ask how do I do that?
Thank you

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 16 Dez. 2021
filename = 'cameraman.tif';
img = imread(filename);
fimg = fft2(img);
sfimg = fftshift(fftshift(fimg,2),1);
rsf = real(sfimg);
isf = imag(sfimg);
contour(rsf)
title('fft2 real part'); colorbar
contour(isf)
title('fft2 imaginary part'); colorbar
real_weights = rand(size(rsf));
real_weights = real_weights + flipud(real_weights) + fliplr(real_weights) + fliplr(flipud(real_weights));
imag_weights = rand(size(isf));
imag_weights = imag_weights + flipud(imag_weights) + fliplr(imag_weights) + fliplr(flipud(imag_weights));
contour(real_weights);
title('real weights'); colorbar();
contour(imag_weights);
title('imaginary weights'); colorbar();
mod_sreal = rsf .* real_weights;
mod_simag = isf .* imag_weights;
mod_real = fftshift(fftshift(mod_sreal,2),1);
mod_imag = fftshift(fftshift(mod_simag,2),1);
reconstructed_fimg = complex(mod_real, mod_imag);
reconstructed_img = ifft2(reconstructed_fimg);
whos
Name Size Bytes Class Attributes filename 1x13 26 char fimg 256x256 1048576 double complex imag_weights 256x256 524288 double img 256x256 65536 uint8 isf 256x256 524288 double mod_imag 256x256 524288 double mod_real 256x256 524288 double mod_simag 256x256 524288 double mod_sreal 256x256 524288 double real_weights 256x256 524288 double reconstructed_fimg 256x256 1048576 double complex reconstructed_img 256x256 1048576 double complex rsf 256x256 524288 double sfimg 256x256 1048576 double complex
rr8 = uint8(real(reconstructed_img));
ri8 = uint8(imag(reconstructed_img));
imshow(rr8)
title('reconstructed after weights, real part')
imshow(ri8)
title('reconstructed after weights, imag part')
I fftshift the fft2 results in order to center the ffts; in theory the result should be symmetric.
I then construct random weights. The random weights must maintain the symmetric nature of the shifted data. The bit where I sum flipped versions of the weights is an attempt to get back a matrix that is symmetric against both diagonals. It looks like I did not succeed -- if I had succeeded then there would be no imaginary components in the reconstructed image.
  1 Kommentar
Peter Phan
Peter Phan am 16 Dez. 2021
Bearbeitet: Peter Phan am 16 Dez. 2021
Oh, it worked for me.
Really thanks
Actually, why don;t you just give me only :
reconstructed_fimg = complex(realpart, imagpart);
reconstructed_img = ifft2(reconstructed_fimg);
Then it work fine to me :)
Thank you so much for your help

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by