Nothing To Lose

If you don’t have it, how can you lose it!
Subscribe

Archive for January, 2009

Regular Expression “Word Boundary”

January 28, 2009 By: Dexter Category: Regular Expressions, Tutorial

Word Boundary:

(The explanation below for grep under Linux using BASH)

Before you can proceed using regular expressions effectively one needs to clearly understand what part of a give string will be treated as a word.

Here are a few points:

  • The set [a-zA-Z0-9_] is considered to be a word.
  • Any other character between the combination of the above set will be a word separator.
  • Any combination of [a-zA-Z0-9_] till the end of the string or line.
  • Any combination of [a-zA-Z0-9_] from the beginning of the string till any other character is encountered.

Take the following sentences/strings:


This line contains mice.
mice in the beginning.
is there one in the end! mice
Some mice are free.
Some are trapped like this !mice. !mice!  (mice) .
Some are mixedmice, catmicecat and micecat.


Notice I have put ‘micein many places in the strings. Open you favourite text editor and copy the above strings in the file and save it as say ‘mice.txt‘.

before we proceed using grep, lets make sure grep is set to display the match in different color.
run the following command:

$ alias grep=’grep –color=always’

Running grep command directly on the file mice.txt for ‘mice’ you will notice that all the lines that contains mice are selected. I have highlighted it below:

$ grep ‘mice’ mice.txt
This line contains mice.
mice in the beginning.
is there one in the end! mice
Some mice are free.
Some are trapped like this !mice. !mice!  (mice) .
Some are mixedmice, catmicecat and micecat.

Notice that wherever the literals ‘mice’ are coming in the sequence they are selected.

To understand how words are differentiated run the following command to search the word ‘mice’:

$ grep ‘\<mice\>’ mice.txt
OR
$ grep -w ‘mice’ mice.txt

This line contains mice.
mice in the beginning.

is there one in the end! mice
Some mice are free.
Some are trapped like this !mice. !mice!  (mice) .

Lets understand the output one line at a time:

Output line 0)
mice in the beginning.
The Zeroth line that is in the output contains the ‘mice’ in the beginning and follows a character that is not in the set [a-zA-Z0-9_].
So anything that starts in a string which is a combination of  [a-zA-Z0-9_] and then follows any other character which is not the part of the set is a word.

Output line 1) is there one in the end! mice
The first line that is in the output contains the ‘mice’ in the end and just before ‘m’ there is a space which is not in the set [a-zA-Z0-9_]. This makes it a word.

Output line 2) Some mice are free.
The second line contains the ‘mice’ containing and space before and after it, since space is not a part of the word character set it is considered a word. This is also a standard understanding for separating word generally.

Output line 3) Some are trapped like this !mice. !mice!  (mice) .
The third line is interesting since it displays three entities selected these are  !mice. notice that the character before and after mice is not in the set [a-zA-Z0-9_]. This makes it a word. Similarly for the other two !mice! and (mice) the characters surrounding it are not in the set [a-zA-Z0-9_]. This makes them a word.

So something like the following strings having mice in between will be treated as word.
#@$$$mice##
abcde!mice.ran
can.you.see.the.mice.here

In the following mice will not be treated as a word:
Three blindmice
micemice
redmice
mincemice

Hope this helped you understand what is considered a word from the point of view of a regex.

Sphere using GIMP

January 25, 2009 By: Dexter Category: GIMP, Tutorial

Here is a small tutorial which will tell you how to create a sphere using GIMP. Ok so here we go.

  1. Start with a small blank gimp canvas. Around 300×300 px
  2. Using the Elliptical Select Tool , select a circular region. To select a circular region, in the options of the Elliptical select tool, Fixed — Aspect Ratio, this will allow you to do a circular select. See IMAGE 1..
  3. Now select a color for your sphere. I have chosen a dark green.
  4. Next select the Blend Tool ( IMAGE 2) for gradient fill. In this select the Shape as Radial. See IMAGE 2.
  5. Change the direction of the gradient by clicking the check box next to the gradient. See IMAGE 2
  6. In the selected circular area, select a point in it using the gradient tool and drag it diagonally. See IMAGE 3.
    Try out different starting points for the gradient fill. You will get different effect for the sphere.
  7. You sphere should be ready now. See IMAGE 4.
  8. To make it look a more real, drop a perspective shadow to it using the shadow filter. Filters — Light and Shadow — Perspective. You will probably need to change the angle according to your requirements so that the shadow falls opposite to the light, i.e the bright area on the sphere. See Image 5.

Circular selection

IMAGE 01: Circular selection

Blend Tool and its options

IMAGE 02: Blend Tool and its options

Blend Fill from inside out

IMAGE 03: Blend Fill from inside out

IMAGE 04: After the blend fill the image looks like a sphere.

IMAGE 04: After the blend fill the image looks like a sphere.

IMAGE 05: Final sphere with shadow.

IMAGE 05: Final sphere with shadow.

Tags: ,

Fingerprint using GIMP

January 20, 2009 By: Dexter Category: GIMP, Tutorial

Nothing much has happened in last few days. Was playing around with GIMP when I decided to try out making a finger print like effect. Follow the steps and probably you will get a fingerprint ready for yourself.

  • Start with a small blank gimp canvas.
  • Using the Elliptical Select Tool, select a oval region and fill it with some dark color. This color represents the ink which is used to the finger print mark. You should get something similar to IMAGE 1
  • Run the Noise - Pick (Filters — Noise — Pick) filter on the select oval area. This removes some pixels from here and there, converting your oval to a distorted one. See IMAGE 2
  • Next run the filter Erase Every Other Row (Filters — Distort — Erase every other row) on your image. Make sure you have selected the rows/cols option to rows. You should get something similar to IMAGE 3.
  • Now select the oval area again using the elliptical select tool.
  • Use filter Iwarp on this. (Filters — Distort — Iwarp).
  • Play around will different values and options of Iwarp, I used small Deform Radius and small amount of Deform Amount. and opted for Deform mode as Swirl CCW and Swirl CW. You just have to move the mouse across the image shown in the upper left corner of the dialogue box. And best part is the changes are not immediate, it has a reset button which restores the image back to its basic state.
  • Iwarp dialogue box
  • IMAGE 05 - I warp dialogue box

  • Play around with the image, once you are happy with your finger print, click on ok to finally apply on the original image.

IMAGE 01 - Finger Print basic

IMAGE 01 - Finger Print basic

IMAGE 02 - After using pick filter Filter

IMAGE 03 - After applying Erase every other row

IMAGE 03 - After applying Erase every other row

IMAGE 06 -  final finger print after applying the Iwarp filter.

IMAGE 06 - final finger print after applying the Iwarp filter.

And remember whatever you do, whenever you try this out again … you will not get the same finger print again. As it is know no two finger prints are identical. ;)

Tags: ,

3 step conversion of photo to canvas painting using GIMP

January 12, 2009 By: Dexter Category: GIMP, Tutorial

Ok after posting the images had to do something.. had been feeling itchy and had to do something about it.. So here we go with another simple tutorial.. of A 3 step conversion of a photo to a canvas painting and of course using my favorite GIMP .

Step One

Take your basic image. I have taken a moon shot which I had taken recently.

I will be using IMAGE 1 as my base.

IMAGE 1

IMAGE 1

Step Two

On the image use the canvas filter: Filters => Artistc => Apply Canvas.

You should now have your image having a similar effect as in IMAGE 2.

IMAGE 2

IMAGE 2

Step 3

And finally apply cubism filter.: Filters => Artistc => Cubism.

In the cubism dialogue box: select  smaller tile size and smaller value of tile saturation

I have use tile size 0.8 and tile saturation 1.8

IMAGE 3

IMAGE 3

And you oil painting is ready… and looks a bit old too… ;)

Tags: ,