MATLAB: Scanning background noise filtering

background correctionfilterImage Processing Toolbox

Hello everybody. I am an absolutly newbie at mathlab.
I am looking for a way for removal scanning background noise for this kind of noise.
I have found some works titled "Marginal noise removal of document images", but dont know how to performe it at matlab.
I'm attaching an example of the scanning background noise talking about.
The background noise is basically at the top of the scanned image.
Thanks!

Best Answer

OK, just try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
%=======================================================================================
% Read in image.
fullFileName = fullfile(pwd, 'jpg1.jpg');
[folder, baseFileName, ext] = fileparts(fullFileName);
rgbImage = imread(fullFileName);
% Shrink it to speed it up
% rgbImage = imresize(rgbImage, 0.75);
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(rgbImage);
% Display the original image.
subplot(2, 3, 1);
imshow(rgbImage, []);
axis on;
caption = sprintf('Original Color Image, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.



% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Convert to a grayscale image by taking the weighted average of all 3 color channels.
grayImage = rgb2gray(rgbImage);
% Display the gray scale image.
subplot(2, 3, 2);
imshow(grayImage, []);
axis on;
caption = sprintf('Gray Scale Image, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Compute the histogram
subplot(2, 3, 3);
histogram(grayImage, 'BinWidth', 1);
grid on;
title('Histogram of entire image', 'FontSize', fontSize, 'Interpreter', 'None');
% Get the vertical profile.
verticalProfile = mean(double(grayImage(:, 1:80)), 2); % Sum of 80 left most columns.
% Normalize to get a percentage of the brightest line
verticalProfile = verticalProfile / max(verticalProfile);
subplot(2, 3, 4);
plot(verticalProfile, 'b-', 'LineWidth', 2);
title('Vertical Profile', 'FontSize', fontSize, 'Interpreter', 'None');
grid on;
xlabel('Row (Line)', 'FontSize', fontSize, 'Interpreter', 'None');
title('Mean Intensity', 'FontSize', fontSize, 'Interpreter', 'None');
% Create a percentage image
percentageImage = repmat(verticalProfile, [1, columns]); % Gray scale
% Display the percentage image.
subplot(2, 3, 5);
imshow(percentageImage, []);
axis on;
title('Percentage Image', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Make 3-D RGB version.
percentageImage = cat(3, percentageImage, percentageImage, percentageImage);
% Divide the original RGB image by this:
correctedRGBImage = uint8(double(rgbImage) ./ percentageImage);
% Display the corrected RGB image.
subplot(2, 3, 6);
imshow(correctedRGBImage, []);
axis on;
title('Corrected RGB Image', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.