imnoise normalization
조회 수: 9 (최근 30일)
이전 댓글 표시
Dear Matlab-community,
currently i am working with the function imnoise, however i don't fully understand why is it needed to normalize both the input images and the optional arguments to the range [0,1]. Since i would like to preserve the mean gray value of the images after noise addition (which should be at least close to the mean gray value of the noiseless image), i would like to skip normalization.
When i use the following two functions (see below) before and after imnoise for both the noiseless image and the input parameters i get noisy images which are completely offscale, i.e. the mean gray value is totally different from the orginal one.
For any hint thanks in advance, Jaime
function output = rescale(orig_image, input)
output = ( input - min(orig_image(:)) )./( max(orig_image(:)) - min(orig_image(:)) );
end
function output = rescale_back(sc_image, input)
output = input.*( max(sc_image(:)) - min(sc_image(:)) ) + min(sc_image(:));
end
댓글 수: 2
Image Analyst
2012년 4월 15일
What is syntim? Wouldn't you just multiply by 255 and cast to uint8 to get your normalized image back to 0-255?
채택된 답변
Jaime
2012년 4월 25일
댓글 수: 1
Walter Roberson
2012년 4월 25일
Correct, imnoise does internally move negative values up to 0.
The code for adding gaussian noise is simple: the noise is randn() times sqrt(variance), plus the mean.
If you had a particular negative value that you wanted to clip against, set the mean to be abs() of that, run imnoise, and subtract that abs() back off. This will of course still be biased, as true gaussian noise can produce down to -inf.
추가 답변 (2개)
Image Analyst
2012년 4월 15일
Use im2double. Try this demo and I think you'll see how to do it. I do it for two different levels of noise and display the original and the two noisy images, and calculate the mean of all three images.
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
clearvars;
fontSize = 20;
format compact;
% Read in a standard MATLAB gray scale demo image.
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.
subplot(2, 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')
% Calculate the mean
mean0 = mean(grayImage(:))
% Add noise to image
normalizedGrayImage = im2double(grayImage);
noiseStDev = 0.01;
noisyImage1 = uint8(255 * imnoise(normalizedGrayImage,'gaussian', 0, 0.01));
% Display the image.
subplot(2,2,2);
imshow(noisyImage1, []);
noiseGrayLevels = noiseStDev * 255.
caption = sprintf('Image with added noise of\n%.2f * 255 = %.2f',...
noiseStDev, noiseGrayLevels);
title(caption, 'FontSize', fontSize);
% Calculate the mean
mean1 = mean(noisyImage1(:))
% Add noise to image
noiseStDev = 0.04;
noisyImage2 = uint8(255 * imnoise(normalizedGrayImage,'gaussian', 0, noiseStDev));
% Display the image.
subplot(2,2,3);
imshow(noisyImage2, []);
noiseGrayLevels = noiseStDev * 255.
caption = sprintf('Image with added noise of\n%.2f * 255 = %.2f',...
noiseStDev, noiseGrayLevels);
title(caption, 'FontSize', fontSize);
% Calculate the mean
mean2 = mean(noisyImage2(:))
message = sprintf('Original mean = %.3f\nImage1 mean = %.3f\nImage2 mean = %.3f',...
mean0, mean1, mean2);
msgbox(message);
댓글 수: 0
Jaime
2012년 4월 17일
댓글 수: 1
Image Analyst
2012년 4월 17일
How much are they off? You are adding noise so the mean won't be EXACTLY the same, but it should be close.
참고 항목
카테고리
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!