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!

 채택된 답변

Image Analyst
Image Analyst 2018년 6월 23일

1 개 추천

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

Wilbert Von
Wilbert Von 2018년 6월 23일
편집: Wilbert Von 2018년 6월 23일
Wow! Thanks!
How can I export the 6 images?
I mean, for export each one by separate.
Phew! I need a matlab certification or something similar.
Image Analyst
Image Analyst 2018년 6월 23일
편집: Image Analyst 2018년 6월 23일
You can use save() to save variables into a .mat file.
You can convert to integers and save to a standard image format file with imwrite().
To save axes and figures, you can use export_fig from the File Exchange. http://blogs.mathworks.com/pick/2010/05/28/creating-and-exporting-publication-quality-graphics/
Wilbert Von
Wilbert Von 2018년 6월 23일
Got another error.
>> imwrite(correctedRGBImage); Error using imwrite>parse_inputs (line 511) Wrong number of input arguments. Error in imwrite (line 418) [data, map, filename, format, paramPairs] = parse_inputs(varargin{:});
Image Analyst
Image Analyst 2018년 6월 23일
Why did you not give it a filename? How is it supposed to know what file name to use?????? Please look at the documentation for imwrite().
Wilbert Von
Wilbert Von 2018년 6월 24일
>> imwrite(correctedRGBImage,corrected); Undefined function or variable 'corrected'.
This is my first time using matlab. Sorry.
Help?
Wilbert Von
Wilbert Von 2018년 6월 24일
Oh! I got it!
Thanks a lot for the help and patience, my hero!
Image Analyst
Image Analyst 2018년 6월 29일
If the problem is solved, then normally one clicks the "Accept this answer" link to give the answerer credit for it. Thanks in advance.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2018년 6월 23일

0 개 추천

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

Wilbert Von
Wilbert Von 2018년 6월 23일
편집: Image Analyst 2018년 6월 23일
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?
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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

2018년 6월 22일

댓글:

2018년 6월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by