Segmentation of scanned pages on text and image blocks

2 visualizaciones (últimos 30 días)
Zyx
Zyx el 12 de En. de 2018
Comentada: Zyx el 13 de En. de 2018
I need to write the code. Can someone write me what steps should I do? If someone has an example, put it, I would be grateful. Attached is the pictures of how it should look. Thanks

Respuesta aceptada

Image Analyst
Image Analyst el 12 de En. de 2018
Editada: Image Analyst el 12 de En. de 2018
OK, try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = 'image1.png';
folder = fileparts(which(baseFileName)); % Determine where demo folder is (works with all versions).
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
%=======================================================================================
% Read in demo image.
rgbImage = imread(fullFileName);
% 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');
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')
drawnow;
% Get a gray scale version
grayImage = rgb2gray(rgbImage);
% Display the mask image.
subplot(2, 3, 2);
imshow(grayImage, []);
axis on;
title('Gray Scaled Image', 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Show histogram of range image.
subplot(2, 3, 3);
histogram(grayImage);
grid on;
title('Histogram of Gray Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Get a mask of the colored images, which have high range.
binaryImage = grayImage < 220;
% Do an opening to break connections of text to photo.
binaryImage = imopen(binaryImage, ones(5));
% Fill in holes.
binaryImage = imfill(binaryImage, 'holes');
% Filter out blobs smaller than 50 pixels by 50 pixels.
binaryImage = bwareafilt(binaryImage, [50*50, inf]);
% Display the mask image.
subplot(2, 3, 4);
imshow(binaryImage, []);
title('Photo Regions', 'FontSize', fontSize, 'Interpreter', 'None');
% Get a mask of the dark stuff.
darkStuff = rgb2gray(rgbImage) < 250;
% Display the text regions.
subplot(2, 3, 5);
imshow(darkStuff, []);
title('Dark Regions', 'FontSize', fontSize, 'Interpreter', 'None');
% Enlarge the photo region somewhat.
photoRegion = imdilate(binaryImage, ones(15));
% Mask out the photo regions.
textRegions = darkStuff & ~photoRegion;
% Connect things horizontally, like words that are spaced far apart.
textRegions = imclose(textRegions, ones(1, 9));
% Fill in holes and get convex hull.
textRegions = bwconvhull(textRegions, 'objects');
% Display the mask image.
subplot(2, 3, 6);
imshow(textRegions, []);
axis on;
title('Text Regions', 'FontSize', fontSize, 'Interpreter', 'None');
Does that do what you want, or at least fairly far along the way?
Hopefully there's at least some work left for you to do so that you'll feel at least some ownership of the code.
  3 comentarios
Image Analyst
Image Analyst el 13 de En. de 2018
Of course. Writing such a scanning program can take decades. Adobe has been working on it for probably 30 years or more. It's no easy feat. Why are you doing it? Who hired you to do it, rather than just using some existing program to do it? If you really need it done, just use an existing program. If you're just doing it to practice programming, well that's another matter, but don't expect to get something robust yourself after a week of programming that other teams of programmers have spent decades perfecting.
Zyx
Zyx el 13 de En. de 2018
Of course. I try to learn from examples because it is so easy for me. In this way, I'm better acquainted with matlab. Thanks for the code, many things have become clearer to me.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 12 de En. de 2018
Well how much do you know already? If you know nothing about how to write MATLAB code, see these links:
If you already know how to program well, but just aren't familiar with the specific Image Processing functions that need to be called, then tell us that.
  5 comentarios
Image Analyst
Image Analyst el 12 de En. de 2018
Editada: Image Analyst el 12 de En. de 2018
Assuming the images are all color, I'd scan the image and look for where the values of the red, green, and blue channels are more than a few gray levels apart. Then I'd threshold that and fill the blob with imfill.
Then I'd use those color images regions to mask them out (turn to white) in your original image. Then I'd make sure the image is gray scale and call imerode() and then threshold and fill. This should get the text regions. Then combine the text region mask with the color images mask to get the overall mask. See if you can program that up. I'll check back and look at your code later today.
Zyx
Zyx el 12 de En. de 2018
I really can not write code. Although it seems very simple, it's not like that. Is there some example here?

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by