how do i create 1/f visual noise on matlab
9 次查看(过去 30 天)
显示 更早的评论
how do i create 1/f visual noise in matlab
please help
0 个评论
回答(1 个)
Leepakshi
2025-3-5
编辑:Leepakshi
2025-3-5
Hello Bhagya,
1/f noise often referred to as "pink noise", has a power spectral density inversely proportional to the frequency.
Please refer to the following MATLAB Answers post regarding the generation of 1/f noise using MATLAB:
But it only plots the pink noise. If with “visual” you mean pink noise in image, please proceed with the following steps in MATLAB.
% Define the size of the noise image
imageSize = [256, 256];
% Create a grid of frequencies
[u, v] = meshgrid(1:imageSize(2), 1:imageSize(1));
u = u - mean(u(:));
v = v - mean(v(:));
% Calculate the frequency magnitude
freqMagnitude = sqrt(u.^2 + v.^2);
freqMagnitude(1,1) = 1; % To avoid division by zero
% Create a 1/f power spectrum
powerSpectrum = 1 ./ freqMagnitude;
% Generate random phase
randomPhase = exp(1i * 2 * pi * rand(imageSize));
% Combine magnitude and phase to create the Fourier transform
fourierTransform = powerSpectrum .* randomPhase;
% Perform the inverse Fourier transform to obtain the spatial domain image
spatialDomainImage = real(ifft2(ifftshift(fourierTransform)));
% Normalize the image to the range [0, 1]
spatialDomainImage = (spatialDomainImage - min(spatialDomainImage(:))) / ...
(max(spatialDomainImage(:)) - min(spatialDomainImage(:)));
% Display the image
imshow(spatialDomainImage, []);
title('1/f Visual Noise');
Above will be the output image. This code snippet creates a 1/f noise image by first defining a frequency grid and calculating a 1/f power spectrum. A random phase is added to the spectrum, and an inverse Fourier transform is performed to convert it back to the spatial domain. The resulting image is normalized and displayed.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Signal Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!