how do you add bit error rate after applying noise to an image, the code below explains it.?
3 views (last 30 days)
Show older comments
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 Comments
Divyansh
on 5 Apr 2023
Hey Pranav, can you please exlplain your issue? Are there any errors that are getting with this code?
Answers (1)
Hitesh
on 2 Apr 2025
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:
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!