Page 1 of 1

"dots" removal/blur/connect

Posted: 2013-09-10T03:52:00-07:00
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

Re: "dots" removal/blur/connect

Posted: 2013-09-10T04:54:34-07:00
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.

Re: "dots" removal/blur/connect

Posted: 2013-09-10T14:23:16-07:00
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

Re: "dots" removal/blur/connect

Posted: 2013-09-10T16:09:11-07:00
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.

Re: "dots" removal/blur/connect

Posted: 2013-09-10T16:09:32-07:00
by fmw42

Re: "dots" removal/blur/connect

Posted: 2013-09-11T16:28:33-07:00
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

Re: "dots" removal/blur/connect

Posted: 2013-09-11T17:03:30-07:00
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.

Re: "dots" removal/blur/connect

Posted: 2013-09-11T18:04:59-07:00
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.

Re: "dots" removal/blur/connect

Posted: 2013-09-11T18:27:27-07:00
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.