Adding Shaped Noise to a picture
6 ビュー (過去 30 日間)
古いコメントを表示
Hello Experts,
Given double image matrix, I need to add shaped noise to the image with given NxM size of the shape. It should be salt & pepper with given variance. The structure of the noise is also given with the matrix.
I need to add such noise to the picture say of the shape "+".
What I did refuse to work and I need your assistance:
I = imread('image file'); I = double(I)/255;
Defining N = zeros(size(I)); ni = imnoise(N,'salt & pepper', given alpha); ni = conv2(N,T,'same'); where T is the given shape of the noise.
ni1 = max(I,ni);
Please try to help me, Thanks a lot in advance.
0 件のコメント
採用された回答
Image Analyst
2012 年 5 月 6 日
I don't understand. Salt and pepper noise does not have a variance. What do you mean by "shape"? Do you mean that noise only occurs in a certain region of interest of the image, or do you mean that the noise has a certain spectrum (in which case it's not salt and pepper noise anymore)?
Demo if you want noise in a mask area that you draw:
clc; % Clear the command window.
clearvars;
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
format compact;
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Users\Mark\Documents\Temporary';
folder = 'D:\Downloads';
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
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.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, '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);
% Display the original gray scale image.
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')
promptMessage = sprintf('Click "Draw Mask" to draw a mask. Left click to anchor points, but right-click to finish it.\nor Cancel to quit.');
button = questdlg(promptMessage, 'Draw Mask', 'Draw Mask', 'Cancel', 'Draw Mask');
if strcmp(button, 'Cancel')
return;
end
[mask verticesX verticesY] = roipolyold();
% Re-display the original gray scale image in a small subplot
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Display the binary image.
subplot(2, 2, 2);
imshow(mask, []);
title('Binary Mask Image', 'FontSize', fontSize);
% Create an image with noise everywhere.
% (Not needed, just doing for fun.)
noisyImage = imnoise(grayImage, 'salt & pepper', 0.05);
% Display the noisy image.
subplot(2, 2, 3);
imshow(noisyImage, []);
% Display the mask outlines.
hold on;
plot(verticesX, verticesY, 'r-');
title('Noisy Image', 'FontSize', fontSize);
% Create a masked image where it's noisy only within the polygon they drew.
maskedImage = grayImage; % Initialize
maskedImage(mask) = noisyImage(mask);
% Display the masked noisy image.
subplot(2, 2, 4);
imshow(maskedImage, []);
title('Masked Noisy Image', 'FontSize', fontSize);
4 件のコメント
Image Analyst
2012 年 5 月 6 日
OK, see edited version above that now has demo code to add noise in a V-shaped polygon that you can draw.
その他の回答 (1 件)
Kiranraddi morab
2013 年 3 月 13 日
Hey i wanted to detect the noise type by using spectrum of noise ,is it possible to do if so please help me (how to detect noise type)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Processing Toolbox についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!