imnoise normalization
古いコメントを表示
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 月 16 日
採用された回答
その他の回答 (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);
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.
カテゴリ
ヘルプ センター および File Exchange で Image Preview and Device Configuration についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!