image analysis (colored or mostly b/w, text, tables, ...)

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Locked
s.moser
Posts: 2
Joined: 2013-11-22T03:05:01-07:00
Authentication code: 6789

image analysis (colored or mostly b/w, text, tables, ...)

Post by s.moser »

Hello,

I need to analyse an image if they image is:
- colored or mostly black/white
- contains text
- contains tables

Can I do that with ImageMagick?
If yes, how I get this managed?

Thanks,
Sebastian

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: image analysis (colored or mostly b/w, text, tables, ...

Post by snibgo »

Q1: coloured or mostly black and white?

The following finds the mean saturation, a number between 0 and 1.

Code: Select all

convert input.png -colorspace HSL -format %[fx:mean.g] info:
"0" means input.png is monochrome, or at least very very close. Any greater number means there is colour.


Q2: contains text?

I don't think IM by itself can do this. You could strip out things that are clearly not text and feed it to OCR.


Q3: contains tables?

I suppose a table contains many horizontal and vertical lines. IM could count these. But this could easily be fooled by an image that contains many random horizontal and vertical lines.
snibgo's IM pages: im.snibgo.com

s.moser
Posts: 2
Joined: 2013-11-22T03:05:01-07:00
Authentication code: 6789

Re: image analysis (colored or mostly b/w, text, tables, ...

Post by s.moser »

I suppose a table contains many horizontal and vertical lines. IM could count these.
>> Whats the IM command for that?

I don't think IM by itself can do this. You could strip out things that are clearly not text and feed it to OCR.
>> You have some steps for me, how to feed the "OCR"?

Regards,
Sebastian

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: image analysis (colored or mostly b/w, text, tables, ...

Post by snibgo »

I would use "-morphology" to count lines.

Many programs are available for OCR (Optical Character Recognition). ImageMagick doesn't do OCR.
snibgo's IM pages: im.snibgo.com

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: image analysis (colored or mostly b/w, text, tables, ...

Post by anthony »

On the other hand if the background is well defined... Freds "multicrop" script can extract retangular blocks of non-background areas.
http://www.fmwconcepts.com/imagemagick/ ... /index.php

These blocks should be pictures. and can be extracted. After that text is essentually lots of thin lines. A small morphological 'dilate' of a white background should essentially remove text, while a 'erode' will expand the text into either large blocks or lines. This could be used to find solid areas that should be text.

Yes it could be fooled, but then it really depends on what type of images you are trying to process. Without a (small) sample image it is very hard to give anything more definite.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Locked