Borrar filtros
Borrar filtros

How to Fourier Phase Scramble a specific area of an image?

19 visualizaciones (últimos 30 días)
Neuro
Neuro el 7 de Abr. de 2023
Comentada: Neuro el 4 de Mayo de 2023
Hi. I have a set of face images that I want to Fourier Phase scramble, excluding the pixels outside of the face contour. This is a sample image (see below): All the pixels outside the fase contour have the same RGB values. I need to Fourier Phase scramble only the pixels inside the contour; in other words, the pixels that belong to the face. Could anyone help me with the code? I'm not very experienced at image processing! Thanks so much in advance!
  2 comentarios
Image Analyst
Image Analyst el 7 de Abr. de 2023
The masking is easy. Can you give us your phase scrambling code?
Neuro
Neuro el 4 de Mayo de 2023
Thanks! How can you apply the mask so both the original photo and the scrambled one have that gray in the background?
Here is the code, as shared by @Nayan
im = imread('image.jpg');
% Convert the image to grayscale
im_gray = im2gray(im);
% Compute the Fourier transform of the image
im_fft = fft2(double(im_gray));
% Extract the magnitude and phase information
im_mag = abs(im_fft);
im_phase = angle(im_fft);
% Randomize the phase information
[N,M] = size(im_phase);
rand_phase = exp(2*pi*1i*rand(N,M));
im_phase_scrambled = im_phase.*rand_phase;
% Combine the randomized phase information with the original magnitude information
im_scrambled_fft = im_mag.*exp(1i*im_phase_scrambled);
% Compute the inverse Fourier transform to obtain the phase-scrambled image
im_scrambled = ifft2(im_scrambled_fft);
% Convert the phase-scrambled image back to uint8 data type
im_scrambled = uint8(real(im_scrambled));
% Display the original and phase-scrambled images side by side
subplot(1,2,1), imshow(im_gray), title('Original');
subplot(1,2,2), imshow(im_scrambled), title('Phase-scrambled');

Iniciar sesión para comentar.

Respuesta aceptada

Nayan
Nayan el 11 de Abr. de 2023
Hi,
As I understand you need to perform phase scrambling on the image. Phase scrambling is a technique used in signal processing to disrupt the phase information of a signal while preserving its power spectrum. In Matlab, you can perform phase scrambling on a signal using the following basic steps :-
  1. Read the image using "imread(filename)".
  2. Calculate the FFT of the image using fft2(X)
  3. Extract the magnitude and phase information from the obtained FFT.
  4. Scramble the phase by multiplying with a random phase.
  5. Recreate the FFT by multiplying the random phase with the magnitude of the original image.
  6. Taking in IFFT using ifft2(x) will provide the phase scrambled image.
Hope this helps!
Refer the following code sinppet for help.
im = imread('image_file_name');
% Convert the image to grayscale
im_gray = rgb2gray(im);
% Compute the Fourier transform of the image
im_fft = fft2(double(im_gray));
% Extract the magnitude and phase information
im_mag = abs(im_fft);
im_phase = angle(im_fft);
% Randomize the phase information
[N,M] = size(im_phase);
rand_phase = exp(2*pi*1i*rand(N,M));
im_phase_scrambled = im_phase.*rand_phase;
% Combine the randomized phase information with the original magnitude information
im_scrambled_fft = im_mag.*exp(1i*im_phase_scrambled);
% Compute the inverse Fourier transform to obtain the phase-scrambled image
im_scrambled = ifft2(im_scrambled_fft);
% Convert the phase-scrambled image back to uint8 data type
im_scrambled = uint8(real(im_scrambled));
% Display the original and phase-scrambled images side by side
subplot(1,2,1), imshow(im_gray), title('Original');
subplot(1,2,2), imshow(im_scrambled), title('Phase-scrambled');
  1 comentario
Neuro
Neuro el 4 de Mayo de 2023
Thanks so much for the code! I had use the function im2gray instead of rgb2gray (see line 3). But it should be the same, right?

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by