using the noise function J = imnoise(I,'gaussian',m,v) ,how can i estimate the percentage of noise ????
MATLAB: How can i determine the percentage of noise given the variance of imnoise ?
image processingImage Processing Toolbox
Related Solutions
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;format compact;fontSize = 20;%===============================================================================
% Read in a standard MATLAB gray scale demo image.
folder = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
baseFileName = 'cameraman.tif';% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);% Check if file exists.
if ~exist(fullFileName, 'file') % File doesn't exist -- didn't find it there. Check the search path for it.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file') % Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName); uiwait(warndlg(errorMessage)); return; endendgrayImage = imread(fullFileName);% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);if numberOfColorBands > 1 % It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end% Display the original gray scale image.
subplot(1, 2, 1);imshow(grayImage, []);title('Original Grayscale Image', 'FontSize', fontSize);% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off') % Initialize an output image.
noisyImage = grayImage; % Initialize
% Get 5,000 random locations
noiseIndexes = randperm(numel(grayImage), 5000);% Add noise
noisyImage(noiseIndexes) = 255;% Display the noisy image.
subplot(1, 2, 2);imshow(noisyImage, []);title('Noisy Image', 'FontSize', fontSize);axis on;
I guess because it expects the output to be the same type as the input, and imnoise expects that if a double is being passed in it has to have a range of 0-1, so it clips anything less than 0 to 0. You would have to use randn() if you wanted negative values in a floating point image. Here is the corrected code:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;format compact;fontSize = 20;originalImage = zeros(255);noisyImage = imnoise(originalImage, 'Gaussian', 0, 0.01);% Display the image.
subplot(2, 2, 1);imshow(noisyImage, []);title('Noisy Image with imnoise()', 'FontSize', fontSize, 'Interpreter', 'None');% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off') % Let's compute and display the histogram.
subplot(2, 2, 2); histogram(noisyImage);grid on;title('Histogram of noisy image from imnoise()', 'FontSize', fontSize, 'Interpreter', 'None');xlabel('Gray Level', 'FontSize', fontSize);ylabel('Pixel Count', 'FontSize', fontSize);noisyImage = originalImage + 0.01 * randn(size(originalImage));% Display the image.subplot(2, 2, 3);imshow(noisyImage, []);title('Noisy Image with randn()', 'FontSize', fontSize, 'Interpreter', 'None');% Let's compute and display the histogram.subplot(2, 2, 4); histogram(noisyImage);grid on;title('Histogram of noisy image with randn()', 'FontSize', fontSize, 'Interpreter', 'None');xlabel('Gray Level', 'FontSize', fontSize);ylabel('Pixel Count', 'FontSize', fontSize);
Best Answer