フィルターのクリア

Adding Noise to the Image

3 ビュー (過去 30 日間)
Steve
Steve 2014 年 7 月 17 日
コメント済み: Steve 2014 年 7 月 22 日
How do I apply "salt" noise to the grey - scale image. Function need to generate salt noise only not the pepper.

採用された回答

Image Analyst
Image Analyst 2014 年 7 月 17 日
編集済み: Image Analyst 2014 年 7 月 17 日
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;
end
end
grayImage = 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;
  1 件のコメント
Steve
Steve 2014 年 7 月 22 日
Thank you

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

その他の回答 (1 件)

Arun Kumar
Arun Kumar 2014 年 7 月 17 日
%Prepare workspace
clear ; clc; close all;
%Read Imag
I=imread('cameraman.tif');
%create a random matrix
randM=rand(size(I));
% default density
d=.05;
%saturated value
randM(randM<d)=255;
%Add noise
I=uint8(double(I)+randM);
%show image
imshow(I)
  1 件のコメント
Steve
Steve 2014 年 7 月 22 日
Thank you

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

カテゴリ

Help Center および File ExchangeExplore and Edit Images with Image Viewer App についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by