Adding Gausian Noise to Video

8 visualizaciones (últimos 30 días)
Matt Alvarez
Matt Alvarez el 30 de Jun. de 2022
Respondida: Siraj el 27 de Sept. de 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 comentarios
Matt Alvarez
Matt Alvarez el 30 de Jun. de 2022
Editada: Matt Alvarez el 30 de Jun. de 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 el 30 de Jun. de 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)))

Iniciar sesión para comentar.

Respuestas (1)

Siraj
Siraj el 27 de Sept. de 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.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by