i need matrix n which generated
5 次查看(过去 30 天)
显示 更早的评论
snr=mean2(I./n)=0.5 ;where I is original image matrix and n is a noise matrix of same size of I.
if i have 'I',i need matrix n which generated using n=mm+sqrt(vv)*randn(size(I)) such i can get snr=0.5.
2 个评论
Image Analyst
2013-1-3
Lots of things (click on his name), but he has never asked the right questions until now. He may have it right now, but I'm not sure.
采纳的回答
Image Analyst
2013-1-3
编辑:Image Analyst
2013-1-3
If n = 2*I, on average, then the SNR will be 1/2. So what do you get if you scale n so that the mean of n equals twice the mean of I? Give that a shot.
[Edit/addition]
Haven't heard from you so I guess you're having trouble. Here, run this code for a demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
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 = 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, 3, 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')
colorbar;
% Get the mean of the image
meanGL = mean2(grayImage)
% Specify the variance, it can be anything at all. It doesn't matter.
% Ask user for a number.
defaultValue = 50;
titleBar = 'Enter a value';
userPrompt = 'Enter the standard deviation (it will not affect the SNR)';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
desiredStandardDeviation = str2num(cell2mat(caUserInput));
% Check for a valid number.
if isnan(desiredStandardDeviation)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
desiredStandardDeviation = defaultValue;
message = sprintf('I said it had to be an integer.\nI will use %d and continue.', desiredStandardDeviation);
uiwait(warndlg(message));
end
desiredvariance = desiredStandardDeviation ^2;
% Create the noise image using his formula:
noiseImage = 2 * meanGL + sqrt(desiredvariance)*randn(size(grayImage));
% Don't allow noise to be negative
noiseImage = max(noiseImage, 0);
% Display the image.
subplot(2, 3, 2);
imshow(noiseImage, []);
colorbar;
title('Noise Image', 'FontSize', fontSize);
% Calculate the SNR
SNR = mean2(double(grayImage) ./ noiseImage)
% Add them together
noisyImage = double(grayImage) + noiseImage;
% Display the image.
subplot(2, 3, 3);
imshow(noisyImage, []);
colorbar;
caption = sprintf('Noise Image with SNR = %.4f', SNR);
title(caption, 'FontSize', fontSize);
message = sprintf('The SNR for these images is %.4f', SNR);
uiwait(helpdlg(message));
% Because it's random, you can't make it exactly 0.5 until you know what it actually is.
noiseImage2 = noiseImage * SNR / 0.5;
% Display the image.
subplot(2, 3, 5);
imshow(noiseImage2, []);
colorbar;
title('Noise Image', 'FontSize', fontSize);
% Add them together
noisyImage2 = double(grayImage) + noiseImage2;
% Now it should be 0.5
% Calculate the SNR
SNR2 = mean2(double(grayImage) ./ noiseImage2)
% Display the image.
subplot(2, 3, 6);
imshow(noisyImage2, []);
colorbar;
caption = sprintf('Noise Image with SNR = %.4f', SNR2);
title(caption, 'FontSize', fontSize);
message = sprintf('The SNR for these images is %.4f', SNR2);
helpdlg(message);
7 个评论
Image Analyst
2013-1-6
I had that case and I got inf, so you can see that I changed the min allowable value to 0.01. Doing that didn't affect the SNR much as compared to ignoring that pixel totally because there were so few pixels it affected.
Image Analyst
2013-1-7
You might try checking out this File Exchange submission: http://www.mathworks.com/matlabcentral/fileexchange/25645
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing and Computer Vision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!