# Adding Gausian Noise to Video

4 ビュー (過去 30 日間)
Matt Alvarez 2022 年 6 月 30 日

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)
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 件のコメント1 件の古いコメントを表示1 件の古いコメントを非表示
Matt Alvarez 2022 年 6 月 30 日

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.
no=vid.NumberOfFrames;
for i=1:1:no
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 2022 年 6 月 30 日
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)))

サインインしてコメントする。

### 回答 (1 件)

Siraj 2023 年 9 月 27 日
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)
% 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.

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeMotion Detection についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by