Adding Gausian Noise to Video

10 vues (au cours des 30 derniers jours)
Matt Alvarez
Matt Alvarez le 30 Juin 2022
Réponse apportée : Siraj le 27 Sep 2023
Hello! i am using a Video Compression Code made by "naveen V"
below is the code they used for the video compression
ImFolder=uigetdir;
pngFile = dir(strcat(ImFolder,'\*.png'));
S = [pngFile(:).datenum];
[~,S] = sort(S);
pngFiles = pngFile(S);
VideoFile=strcat(ImFolder,'\Video');
writeObj = VideoWriter(VideoFile);
fps= 15;
writeObj.FrameRate = fps;
open(writeObj);
for t= 1:length(pngFiles)
Frame=imread(strcat(ImFolder,'\',pngFiles(t).name));
writeVideo(writeObj,im2frame(Frame));
end
close(writerObj);
I would like to ask how to apply gaussian noise and reed solomon FEC into the code for the purpose of measuing BER of the system.
  3 commentaires
Matt Alvarez
Matt Alvarez le 30 Juin 2022
Modifié(e) : Matt Alvarez le 30 Juin 2022
i apologize for my lack of understanding but i would like to ask how to implement that here. This was the code that was used to turn the video into multiple frames as i understodd from you comment that i should add gaussian noise per image.
when i tried changing it from "Frame" to "frames" it gave me an error shown below
Error using +
Integers can only be combined with
integers of the same class, or scalar
doubles.
vid=VideoReader('videopart.mp4');
no=vid.NumberOfFrames;
for i=1:1:no
frames=read(vid,i);
base=sprintf('Image%d.png',i);
ful=fullfile(pwd,base);
frames=frames+round(4*randn(size(frames)))
imwrite(frames,ful);
im(i)=image(frames);
end
Jonas
Jonas le 30 Juin 2022
interesting, i don't have problems doing this this (2022a). What is the class of frames? if it is e.g. uint16 you can also use
Frame=Frame+uint16(factor*randn(size(Frame)))
if it is uint8
Frame=Frame+uint8(factor*randn(size(Frame)))

Connectez-vous pour commenter.

Réponses (1)

Siraj
Siraj le 27 Sep 2023
Hi!
I understand that you're trying to make a video from PNG files, add Gaussian noise to the frames, and analyze the Bit Error Rate (BER). However, you're running into an error that says, "Error using +: Integers can only be combined with integers of the same class, or scalar doubles." This error hints at a data type mismatch between your image data and the noise you're adding. To resolve this, ensure that the data types match when you're adding the noise to the frames.
To overcome this issue, you can utilize the "imnoise" function, which allows you to introduce noise to an image. This function offers control over the type of noise you want to apply and lets you adjust the noise's intensity. For more detailed information about the "imnoise" function, you can refer to the following link.
I've included the code below for improved clarity.
% Prompt the user to select a folder containing PNG files
ImFolder = uigetdir;
% List all PNG files in the selected directory
pngFile = dir(fullfile(ImFolder, '*.png'));
% Sort the PNG files by modification date
S = [pngFile(:).datenum];
[~, S] = sort(S);
pngFiles = pngFile(S);
% Define the path for the output video
VideoFile = fullfile(ImFolder, "Video");
% Create a VideoWriter object for video creation
writeObj = VideoWriter(VideoFile);
% Set the frames per second (fps) for the video
fps = 15;
writeObj.FrameRate = fps;
% Open the VideoWriter object to start writing the video
open(writeObj);
% Loop through each PNG file in the sorted list
for t = 1:length(pngFiles)
% Read the PNG file
Frame = imread(fullfile(ImFolder, pngFiles(t).name));
% Add Gaussian noise to the frame
NoisyFrame = imnoise(Frame, "gaussian");
% Convert the noisy frame and write it to the video
writeVideo(writeObj, im2frame(NoisyFrame));
end
% Close the VideoWriter object to save the video
close(writeObj);
Hope this helps.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by