how do i create 1/f visual noise on matlab

조회 수: 11 (최근 30일)
Bhagya Lakshmi Marella
Bhagya Lakshmi Marella 2016년 11월 23일
편집: Leepakshi 2025년 3월 5일
how do i create 1/f visual noise in matlab
please help

답변 (1개)

Leepakshi
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!

카테고리

Help CenterFile Exchange에서 Signal Processing Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by