Page 1 of 1

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

Posted: 2013-11-22T03:12:53-07:00
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

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

Posted: 2013-11-22T04:48:17-07:00
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.

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

Posted: 2013-11-22T08:19:35-07:00
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

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

Posted: 2013-11-22T08:40:26-07:00
by snibgo
I would use "-morphology" to count lines.

Many programs are available for OCR (Optical Character Recognition). ImageMagick doesn't do OCR.

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

Posted: 2013-11-26T17:01:56-07:00
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.