Scanning background noise filtering

5 views (last 30 days)
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!

Accepted Answer

Image Analyst
Image Analyst on 23 Jun 2018
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.
  7 Comments
Wilbert Von
Wilbert Von on 24 Jun 2018
Oh! I got it!
Thanks a lot for the help and patience, my hero!
Image Analyst
Image Analyst on 29 Jun 2018
If the problem is solved, then normally one clicks the "Accept this answer" link to give the answerer credit for it. Thanks in advance.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 23 Jun 2018
The image is shaded at the top. Because the image has gray scale images in it, we can't just assume that all pixels darker than a certain amount should be set to white. So what I'd do it to get the average vertical profile of the N left most columns to look for that shading:
grayImage = rgb2gray(rgbImage);
verticalProfile = sum(grayImage(:, 1:50), 2); % Sum of 50 left most columns.
% Normalize to get a percentage of the brightest line
verticalProfile = verticalProfile / max(verticalProfile);
Now divide each column in the RGB image by that percentage. Cast to double, divide each color channel, cast back to uint8. Should be simple. Give it a try.
  2 Comments
Wilbert Von
Wilbert Von on 23 Jun 2018
Edited: Image Analyst on 23 Jun 2018
Hello. Thanks for the reply.
I got an error about the codes:
>> imread('jpg1.jpg');
>> grayImage = rgb2gray(rgbImage);
verticalProfile = sum(grayImage(:, 1:50), 2); % Sum of 50 left most columns.
% Normalize to get a percentage of the brightest line
verticalProfile = verticalProfile / max(verticalProfile);
Undefined function or variable 'rgbImage'.
Any help?
Image Analyst
Image Analyst on 23 Jun 2018
I fixed your formatting. You can do it after you read this link.
You need to read the image into a variable. You can't just call imread() and not accept the data into any variable. Do this:
rgbImage = imread('jpg1.jpg');
[rows, columns, numColorChannels] = size(rgbImage);
if numColorChannels == 3
grayImage = rgb2gray(rgbImage);
else
grayImage = rgbImage;
end

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!