"dots" removal/blur/connect

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
coolice
Posts: 3
Joined: 2013-09-10T03:42:12-07:00
Authentication code: 6789

"dots" removal/blur/connect

Post by coolice »

Hi!

I would like to ask your help in a special problem I am fighting with days now:

I have an image, I capture in a given interval. This is an example of it :

https://www.dropbox.com/s/cgh2tpf4hqg6ke5/test.jpg

It might seems a bad quality image, but actually it is in a perfect quality, JUST it is built from stupid "dots". If I invert (-negate) the image, it is much better visible:

https://www.dropbox.com/s/s8htklpx3wvpgtz/test2.jpg

My problem/question is:

- How could I remove the "dots", keeping the numbers quality sharp with imagemagick cmd parameters ?

I need to do this, to make the OCR recognition possible, as it isnt now with these horrible "dots".

All your help would be very much appreciated!

Many Thanks,

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

Re: "dots" removal/blur/connect

Post by snibgo »

Blurring will merge pixel colours. I've named your original "dotNumbers.jpg". Windows script, with a bit of processing after the blur:

Code: Select all

convert ^
  dotNumbers.jpg ^
  -blur 0x1.5 ^
  -contrast-stretch 50x0%% ^
  -unsharp 0x2 ^
  dnb.png
You'll need to experiment to find what your OCR will accept.
snibgo's IM pages: im.snibgo.com
coolice
Posts: 3
Joined: 2013-09-10T03:42:12-07:00
Authentication code: 6789

Re: "dots" removal/blur/connect

Post by coolice »

Thank you for your quick help. I tried it, but it seems, that I can not make it good enough to teh OCR to read.

BUT

May I ask an other quetsion, which could be a perfect work around ?

I have an image style, what is consistent all the time, and tested to work with OCR perfectly:

https://www.dropbox.com/s/xwcayf8c9t6k64p/A.jpg

So, my question is. Is there any "compare" feature of ImageMagick, which could identify if very similar image shown (only numbers are different), and not this ?:

https://www.dropbox.com/s/6wkde7dtrifouy2/B.jpg

BIG thanks for your help, in advance,

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

Re: "dots" removal/blur/connect

Post by snibgo »

I don't understand the question.

I suppose IM could do the OCR work itself, perhaps with "compare" or "-morphology", provided the font and stroke thickness was constant. But that would be quite difficult.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "dots" removal/blur/connect

Post by fmw42 »

coolice
Posts: 3
Joined: 2013-09-10T03:42:12-07:00
Authentication code: 6789

Re: "dots" removal/blur/connect

Post by coolice »

Forgive me, if I wasnt clear enough.
So:

Let say, i capture 1 image every second, so 60 image in 1 minute.

59 of them will be similar to this: https://www.dropbox.com/s/6wkde7dtrifouy2/B.jpg

BUT

1 will be similar to this:https://www.dropbox.com/s/xwcayf8c9t6k64p/A.jpg

So, my question:

is there any way to to be able to select this 1 image with some "comapre" feature ?

Many Thanks,

Moore
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "dots" removal/blur/connect

Post by fmw42 »

compare successive images until you get one that does not compare favorably. all the rest should give a zero or small error value (rmse).

However perhaps I do not understand. If the images move slightly or are shifted, then the compare will think they are different. So if the camera or the object move, then the compare will fail even though the number are the same, since they will be in different positions.

If it is only a shift and not a scale or rotation, then you could pad one image to twice its size and use the second image as the smaller of the two in a subimage-search mode for compare.

Perhaps you can explain your situation in a bit more detail.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: "dots" removal/blur/connect

Post by snibgo »

coolice wrote:Let say, i capture 1 image every second, so 60 image in 1 minute. ... is there any way to to be able to select this 1 image with some "comapre" feature ?
In general, I would do this:

Code: Select all

compare -metric RMSE frame_{n}.png frame_{n+1}.png NULL:
This sends a number to stdout. If the number is less than a threshold, I consider the frames to be (roughly) equal. If it exceeds the threshold, I consider them to be different.

I work with video, where the frames are always slightly different, so I adaptively establish a threshold. If your frames are computer-generated, the threshold may be zero.

Other techniques may be possible and more appropriate. In your two examples, the second image contains lots of light grey (almost white); the first contains none.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "dots" removal/blur/connect

Post by fmw42 »

Other techniques may be possible and more appropriate. In your two examples, the second image contains lots of light grey (almost white); the first contains none.
If the one image is different enough, you could just compute the mean of each image successively and difference them and look for sudden changes.

convert frame_{n}.png frame_{n+1}.png -format "%[fx:abs(u.mean - v.mean)]" info:

That should be faster than compare -metric rmse.
Post Reply