Brownian motion

The quick brown fox jumps over the lazy dog

 

Archive for 27 October 2009

Bats and echolocation

We all know that bats prey for a tiny pieces of «meal» with echolocation — they cry loadly and listen to echoed signal.

Sounds good :О)

Lets try to look at numbers a bit closer.

Unfortunately, English Wikipedia does not show these numbers, but Ukrainian page about bats says that «bats emit short sounds with frequency of 20–120kHz and duration of 0.2–100 ms».

So, duration of sound «pattern» may vary, I don’t know why and what is the reason, anyway — I’ll use relatively short impulse length, one milisecond.

Now we will remember what is the speed of sound in air — it is about 343 m/s.

These numbers give us typical impulse length — 34.3 cm.

Well… The length of an impulse is the precision of «measurement» — bats can not measure more precise then «somewhere there, 30 cm left or right»… And… I’ve used one millisecond impulse, not 100…

Actually, everything is far more optimistic and funny — bats «cry» signals with varying frequency, catch echoed signal and… calculate convolution. They obtain Dirac delta function, short peak. Bats know what is «radar jamming», linear-frequency modulated signal, they can deal with integrals. A lot like «real» radar jamming and deception (sorry, I’m confused! — what is «real» radar jamming now?-).

Moreover, they can switch their receiver off while transmitter emits sound — to protect their receiver…

But… I can not understand, anyway, how they can distinguish — with this fantastic speed and precision — between insect and thin branch or little flower… They fly very beautifully between branches and catch insects.

How?.. :-)

“Tweaking” photographed text pages

This time we have this task: we need to print badly taken digital pictures, so we have to improve them in some way — raise contrast, sharpen, make them «looking better».

As always, this result can be achieved going both easy (easy-to-use) and hard (where-am-i?..) way — we will pass both.

(Surely, below is not a single algorithm to do this job.)

Contents

  1. «Easy» — graphical — way
  2. «Hard» — from a command-line
  3. Conclusion

«Easy» way

  1. Launch your favotire graphical editor and open image:
    01-open-image
    If your camera give you horizontal image, you need to rotate it, of course.
  2. Duplicate background in a new layer:
    02-duplicate-layer
  3. Blur newly created (upper) layer a lot:
    03-blur-layer
    I’ve choosen value of 20 for blur radius, but this may be increased — have a try. I’ve been using up to 250 for some particular (rather large) images.
  4. Select «Division» as a composition mode for this layer:
    04-compose-divide
    After these steps we have:
    05-composed-result
  5. Flatten image:
    06-flatten
  6. Increase sharpness using «Unsharp mask» filter:
    07-unsharp-mask
  7. Save, print, enjoy…

In a real life case we may want to use some different algorithm, different values, but… we are talking about something completely different here :-)

Keep reading.

«Hard» way

image=${1:?"Set image name as a param"}
 
# let's say all images have three-letters "extension"
 
convert -monitor $image \
        \( +clone -blur 0x20 \) +swap \
        -compose divide -composite \
        -sharpen 0x1.3 ${image%%.*}_better.${image: -3:3}

Page before and page after (downsized for web).

Btw, if your camera gives horizontal image sometimes and you need to rotate some images — some, but in the same direction — you can use key «-rotate "90>"». This will rotate only horizontal images. Well, if you camera, luckily, provide your images with orientation tag, you can use -auto-orient, of course!

Btw, again, if you need to have black colour a bit more black, you can modify a script in, let’s say, this way:

image=${1:?"Set image name as a param"}
 
convert -monitor $image \
        -rotate "90>" \
        \( +clone -blur 0x20 \) +swap \
        -compose divide -composite \
        \( +clone -blur 20 \) +swap \
        -compose multiply -composite \
        -sharpen 0x1.3 ${image%%.*}_farbetter.${image: -3:3}

Page before, after the first script, after the second one (downsized for web). Again, this is not the only way, as if working with The GIMP or PhotoShop, of course :О)

For these particular images i’ve stopped on this:

image=${1:?"Set image name as a param"}
out="002"; mkdir -p ${out}
 
convert -monitor $image \
        -resize "3456x3456>" \
        -rotate "90>" \
        -median 1 \
        \( +clone -blur 0x20 \) +swap \
        -compose divide -composite \
        \( +clone -median 3 \) +swap \
        -compose multiply -composite \
        -level 10%,90%,1 \
        -sharpen 0x1.3 ${out}/${image%%.*}.${image: -3:3}

For the last picture this gives (downsized for web):
dscf3185_probably_final

Image is quite clean, occupies less disk space, can be pretty-printed :-)

Conclusion

:-)

I hope, you’ve agreed with my sarcasm.

And needless to say how easy that «hard» way — for a single picture, for all pictures in a directory, for all images around… Btw, long live „find” :-)

Of course, in real life it’s more convenient to have all processed images in a separate directory — it’s not a problem, too.

This command-line way works great under both Linux and (almost great,-) Windows. Just download and install ImageMagick. And read the manual :-)

Thanks, Matt!

Four (five) good blogs., by Lord Matt.

Hi everyone!

Yes… I write new posts rather very rarely :O)

So, i’m glad that this my «habit» may be let’s say interesting for somebody.

And… forgive me my english :-)

Pages

Recent Posts

Most Rated

Highest Rated

Tags

Archives