noise detector in images
Mostra commenti meno recenti
i have an image which has salt and pepper noise ...i just want to write a code for noise detector.. please help me out .. i have benn through the dead pixel removal concept and want to learn a bit of more basics
Risposte (2)
Image Analyst
il 15 Nov 2011
I've posted this demo before. Apparently it didn't turn up in your searches so I'll post it again:
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 15;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'peppers.png';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% 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.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(3, 4, 1);
imshow(rgbImage);
title('Original color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Display the individual red, green, and blue color channels.
subplot(3, 4, 2);
imshow(redChannel);
title('Red Channel', 'FontSize', fontSize);
subplot(3, 4, 3);
imshow(greenChannel);
title('Green Channel', 'FontSize', fontSize);
subplot(3, 4, 4);
imshow(blueChannel);
title('Blue Channel', 'FontSize', fontSize);
% Generate a noisy image. This has salt and pepper noise independently on
% each color channel so the noise may be colored.
noisyRGB = imnoise(rgbImage,'salt & pepper', 0.05);
subplot(3, 4, 5);
imshow(noisyRGB);
title('Image with Salt and Pepper Noise', 'FontSize', fontSize);
% Extract the individual red, green, and blue color channels.
redChannel = noisyRGB(:, :, 1);
greenChannel = noisyRGB(:, :, 2);
blueChannel = noisyRGB(:, :, 3);
% Display the noisy channel images.
subplot(3, 4, 6);
imshow(redChannel);
title('Noisy Red Channel', 'FontSize', fontSize);
subplot(3, 4, 7);
imshow(greenChannel);
title('Noisy Green Channel', 'FontSize', fontSize);
subplot(3, 4, 8);
imshow(blueChannel);
title('Noisy Blue Channel', 'FontSize', fontSize);
% Median Filter the channels:
redMF = medfilt2(redChannel, [3 3]);
greenMF = medfilt2(greenChannel, [3 3]);
blueMF = medfilt2(blueChannel, [3 3]);
% Find the noise in the red.
noiseImage = (redChannel == 0 | redChannel == 255);
% Get rid of the noise in the red by replacing with median.
noiseFreeRed = redChannel;
noiseFreeRed(noiseImage) = redMF(noiseImage);
% Find the noise in the green.
noiseImage = (greenChannel == 0 | greenChannel == 255);
% Get rid of the noise in the green by replacing with median.
noiseFreeGreen = greenChannel;
noiseFreeGreen(noiseImage) = greenMF(noiseImage);
% Find the noise in the blue.
noiseImage = (blueChannel == 0 | blueChannel == 255);
% Get rid of the noise in the blue by replacing with median.
noiseFreeBlue = blueChannel;
noiseFreeBlue(noiseImage) = blueMF(noiseImage);
% Reconstruct the noise free RGB image
rgbFixed = cat(3, noiseFreeRed, noiseFreeGreen, noiseFreeBlue);
subplot(3, 4, 9);
imshow(rgbFixed);
title('Restored Image', 'FontSize', fontSize);
9 Commenti
Ndoum ekanga Steve willy
il 27 Nov 2015
This answer is just then for image affected with salt and pepper noise, but if we want to load any image and detect the noise on it by a pop up message box then we can select a filter on the button we have created. This is for guide. How to do that??
Walter Roberson
il 27 Nov 2015
You would replace the lines
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'peppers.png';
with
[baseFileName, folder] = uigetfile('Select an image');
Image Analyst
il 27 Nov 2015
I'd use MAGIC: http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component You can have a listbox of images, then click on one to display it. There is a button that will process all images selected in the listbox - you insert that custom code into the AnalyzeSingleImage() function. Your custom code can then read in the image and determine what kind of noise is there and do whatever kind of noise removal you think would improve the image. I don't know what kind of noises you want to try to repair, and I don't have any general purpose denoising software that works with all possible images, so you're mostly on your own there.
ndoum ekanga steve willy
il 28 Nov 2015
the code below only work with color image, not greyscale image. and if image is already affected by noise it wont remove it. How to do in case of grayscale image or image already affected by the noise.
Image Analyst
il 28 Nov 2015
There is no code below. What code are you talking about?
Walter Roberson
il 28 Nov 2015
[baseFileName, folder] = uigetfile('Select a noisy image');
fullFileName = fullfile(folder, baseFileName);
noisyRGB = imread(fullFileName);
Now continue on in the program from the line after
title('Image with Salt and Pepper Noise', 'FontSize', fontSize);
Image Analyst
il 28 Nov 2015
See my attached Salt and Pepper noise demos, one for color and one for gray scale.
ndoum ekanga steve willy
il 28 Nov 2015
Thank you. But in case the image you loaded has already noise like the image below. the restoration of image will still have salt and pepper noise. it will just remove the one added. is it possible to separate noise on image, my lecturer said i should use standard deviation to detect what type of noise are in image, then i can apply corresponding filter. i'm stack. thank you. example only on one image the rest i can do.
Image Analyst
il 28 Nov 2015
Huh? What image below? You didn't attach any. And for the demos I attached, the images do not still have salt and pepper noise so, again, I don't know what image you're talking about.
Rather than hijack Max's four year old discussion, why don't you first read this and then start a new question where you attach your images and attach the ranges that you want to check the standard deviation for, like 4-9, 9-23, or whatever. By the way, the standard deviation will not detect the type of noise you have, only the magnitude of it - not the type. Lots of different types of noise could have the same standard deviation, and if your image is not a solid uniform image, then the standard deviation of even noiseless pixels would be non-zero.
Koustav Biswas
il 19 Ott 2022
0 voti
teroi maa ki chut
Categorie
Scopri di più su Get Started with Computer Vision Toolbox in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!