how do you add bit error rate after applying noise to an image, the code below explains it.?

3 次查看(过去 30 天)
I = imread('C:\Users\Vinayak Shukla\Documents\MATLAB\MATLAB PROJECTS\MASTER THESIS FOLDER 2023\happy15_encrpted4.bmp');
imshow(I);
J = imnoise(I,'gaussian',0.05);
imshow(J)
var = "message 1.txt";
double(char(var))
dec2bin('message 1.txt');
fid=fopen("message 1.txt","w");
fprintf(fid,"message1\n");
fclose(fid);
  3 个评论

请先登录,再进行评论。

回答(1 个)

Hitesh
Hitesh 2025-4-2
Hi Pranav,
Although I am not entirely sure what you are specifically seeking, it seems like you are interested in determining the bit error rate after adding noise to an image.
You need to compare the original and noisy images at the bit level for calculating the Bit Error Rate (BER) after applying noise to an image . Follow the below steps to get the bit error rate after adding noise to an image.
  • Convert Images to Binary: Convert both the original and noisy images to binary format.
  • Compare Bits: Compare each bit of the original image with the corresponding bit in the noisy image.
  • Calculate BER: Compute the BER as the ratio of the number of erroneous bits to the total number of bits.
Kindly refer to the revised code and mentioned comments for better understanding:
% Read the original image
imgData = imread('sample.bmp');
% Apply Gaussian noise
gaussianData = imnoise(imgData, 'gaussian', 0.05);
imshow(gaussianData);
% Convert images to binary format
imgData_bin = dec2bin(imgData(:), 8); % Convert each pixel to an 8-bit binary string
gaussianData_bin = dec2bin(gaussianData(:), 8);
% Calculate the number of bits
total_bits = numel(imgData_bin);
% Calculate the number of erroneous bits
error_bits = sum(imgData_bin(:) ~= gaussianData_bin(:));
% Calculate the Bit Error Rate (BER)
BER = error_bits / total_bits;
% Display the results
fprintf('Total bits: %d\n', total_bits);
fprintf('Error bits: %d\n', error_bits);
fprintf('Bit Error Rate (BER): %f\n', BER);
For more information regarding the "dec2bin" function, kindly refer to the following MATLAB documentation:

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by