I image dataset having 250 images , image size with 240*240 grayscale image. I want to remove noise using guassian filter all at once and want to store the images in folder. How can I do it.

 Accepted Answer

Please refer the link, how to call sequences of images from an folder?
Once the image call done (One By One)
for
image_data=imread(filename);
%% Applyfilter
filter_image=imfilter(....)
% Set the path to save the filtered image
imwrite(filter_image,path)
end
There are multiple Answers that are available for similar questions in MATLAB Answers
Steps:
  • Call the image form an folder (One by One)
  • Apply Filter
  • Save the filter image in diffeerent folder
:)

5 Comments

Hi sir,
Thanks alot for your help.
instead of guassian I have salt and pepper method. Please do check once this code. Further I am getting some errors while executing this code. please do help.
Error using medfilt2
Expected input number 1, A, to be two-dimensional.
Error in medfilt2>parse_inputs (line 107)
validateattributes(a, ...
Error in medfilt2 (line 48)
[a, mn, padopt] = parse_inputs(varargin{:});
Error in salt_and_pepper_noise_removal_grayscale (line 37)
medianFilteredImage = medfilt2(noisyImage, [3 3]);
clc;
clear;
close all;
imtool close all;
workspace;
fontSize = 15;
folder = fullfile(matlabroot, 'E:\matlab\croped image\benign');
baseFileName = '2.1.jpg';
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
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
grayImage = imread(fullFileName);
[rows columns numberOfColorBands] = size(grayImage);
subplot(2, 2, 1);
imshow(grayImage);
title('Original Gray Scale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize'));
noisyImage = imnoise(grayImage,'salt & pepper', 0.05);
subplot(2, 2, 2);
imshow(noisyImage);
title('Image with Salt and Pepper Noise', 'FontSize', fontSize);
medianFilteredImage = medfilt2(noisyImage, [3 3]);
noiseImage = (noisyImage == 0 | noisyImage == 255);
noiseFreeImage = noisyImage; % Initialize
noiseFreeImage(noiseImage) = medianFilteredImage(noiseImage); % Replace.
subplot(2, 2, 3);
imshow(noiseFreeImage);
title('Restored Image', 'FontSize', fontSize);
To remove the salt and pepper noise, you can do it several ways. This is also possible with MAX and MIN removal filters.
Note: medfilt2(image) performs median filtering of the image image in two dimensions
Or Apply on the individual planes, after that use cat(3,....) to combine all planes
sir but my image is gray scale
Please share the following (From Command Window)
>>whos noisyImage
Also, medfilt2 apply by default [3,3] window, no need to mention, though this is not the cause of the error

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!