Adding Shaped Noise to a picture
조회 수: 3 (최근 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!