Brownian motion

The quick brown fox jumps over the lazy dog

 

Posts Tagged ‘Linux’

“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 :-)

Finally: my django-based configurator for HTB shaper works

Well.. I’ve done my django based configurator for my HTB shaper (bridge/linux).

I will try to translate this post in english; if you can read Ukrainian, try here.

Use Windows “alt codes” in Linux but better

The one thing that most of us Linux users miss when leaving Windows behind is that «alt codes» are not supported. Well here is an under documented feature that should allow you to type alt codes and access all of the special characters with Ubuntu, Red Hat or whatever flavour of Linux you play or work with.

Windows «Alt Codes» for Linux works like this.

Ctrl+Shift+u

Hold down Control and then Shift and press the «u» key. You should get an odd looking character that is waiting for input. Type the numeric code and press space. You can use more than just ASCII but can use hex values too!

Now you can type and unicode value and get the character in you Linux text field. Feel free to say how fantastic I am.

So now you can type your «æ» or «Þ» or whatever. Spend only ¼ of the time typing characters and more time being cool.

Need a better look up for characters? http://unicode.org/charts/ is a full collection of PDF charts of all the information you should ever need.

ps. This took word-by-word from here: Use Windows «alt codes» in Linux but better, by Lord Matt.

HTB/8021q: That was my fault

Regarding the problem with shaping vlan-tagged traffic on linux bridge — it was my fault :-)

I asked community@lists.altlinux.org, and Sergey Vlasov answered me with some info and hint — thanks a lot!-)

As Sergey told, «a packet is being passed to bridge module before 8021q can process it». That’s why the classifier decides that a packet does not match a filter rule — because filter contains «protocol ip» condition, however a packet contains «protocol 802.1q» actually. It look like it’s enough to use «protocol 802.1q» in filter condition — after that ip addresses (offsets from IP packet’s start) will be counted correctly.

This offers a possibility to build «aggregating shapers» on linux bridges, which will be able to shaper clients” traffic regardless of «traffic direction» (regardless of a particular vlan membership). And it will be very easy to migrate from an «usual» shaper on linux bridge — we will have to replace «protocol ip» with «protocol 802.1q» in a filter template (or we can add one more filter — if it is really necessary).

Problem with shaping vlan-tagged traffic on linux bridge

Update: there are no any problem with vlans in classifiers, that was my fault.

Have been playing with shapers and run into such a problem: u32 classifier does not work (?) for tagged traffic on «non-tagged» linux bridge.

In more details:

Test bed:

Let’s take three linux boxes. One will be two-ports switch (SW), on two another (BoxA and BoxB) we will configure IP addresses 172.17.2.10/24 and 172.17.2.11/24, for example.

So.. For the beginning BoxA should ping BoxB on crossover cable.

Building bridge:

brctl addbr br0
brctl addif br0 eth0
brctl addif br0 eth1
ip link set up dev br0

Now BoxA should successfully ping BoxB through this switch.

Configuring shaper:

DEV=eth0
#
# QDisc:
tc qdisc add dev $DEV root handle 1: htb default 200
#
# root class:
tc class add dev $DEV classid 1:10 parent 1:0 htb rate 100Mbit
#
# default class:
tc class add dev $DEV classid 1:200 parent 1:10 htb rate 1Mbit
#
# class for test traffic:
tc class add dev $DEV classid 1:100 parent 1:10 htb rate 10Mbit
#
# filter for test traffic:
tc filter add dev $DEV protocol ip parent 1:0 prio 100 u32 match ip dst 172.17.2.10 flowid 1:100

Check — BoxA should ping BoxB, and this traffic should be in class 1:100, this can be verified by tc -s class show dev $DEV.

Configuring vlan subinterfaces:

Now on boxes A and B we remove addresses from interfaces and put them on sub-interfaces:

ip addr del 172.17.2.10/24 brd 172.17.2.255 dev eth0
#
vconfig add eth0.100
ip link set up dev eth.100
#
# on the other box there should be .11/24:
ip addr add 172.17.2.10/24 brd 172.17.2.255 dev eth0.100

Switch’s configuration remains unchanged.

Now BoxA still can ping BoxB, but this traffic is in the default class, 1:10, instead of 1:100.

The value of REORDER_HDR does not matter.

This is the problem.

What is wrong?

Some considerations:

  1. u32 classifier takes «offset» counting from the beginning of IP packet.
  2. vlan tag should not mess IP related code…

Is any of these wrong?

I’ve mentioned, i’m not a programmer :-)

Pages

Recent Posts

Most Rated

Highest Rated

Tags

Archives