Welcome to My Personal Web Site

Knows How to Provide Solution

Home
About Me
Photo Album
Info Center
Tech Tip Center
Tools
Shared Folders
My World
Contact Me
Site Map
News Letter

Image Processing in Command Line (March 26, 2008)

There are many application for image processing, croping, resizing bluring, morphing, resampling, and  many more action that can be done on a image. These applications are usually well designed and you can easily access different functionalities by just choosing the right menu.

 

So, why should we bother to type in the command to , let say, crop an image? Moreover, we may need to repeat the command for several times to achieve the suitable parameters' values.

 

If you want to perform an action on just one image then you are right. But suppose that you have tens if not hundreds of images that need the same action. Then, you admit that opening all these images and choosing the right menu takes you ages, if not impossible.

 

Many software comes with an scripting language inside it for automation. If you are using such a software, then good luck. But usually most of these softwares are not free.

 

CONVERT is a text environment tool provided by ImageMagick. It is free and available for the Linux, Mac OSX, and for Windows users.

 

Here is just a short list of what convert ImageMagick does:

 

  • Format conversion: convert an image from one format to another (e.g. PNG to JPEG)
  • Transform: resize, rotate, crop, flip or trim an image
  • Transparency: render portions of an image invisible
  • Draw: add shapes or text to an image
  • Decorate: add a border or frame to an image
  • Special effects: blur, sharpen, threshold, or tint an image
  • Animation: create a GIF animation sequence from a group of images
  • Text & comments: insert descriptive or artistic text in an image
  • Image identification: describe the format and properties of an image
  • Composite: overlap one image over another
  • Montage: juxtapose image thumbnails on an image canvas
  • Motion picture support: read and write the common image formats used in digital film work
  • Image calculator: apply a mathematical expression to an image or image channels
  • High dynamic-range images: accurately represent the wide range of intensity levels found in real scenes ranging from the brightest direct sunlight to the deepest darkest shadows
  • Large image support: read, process, or write mega- and giga-pixel image sizes
  • Encipher or decipher an image: convert ordinary images into unintelligible gibberish and back again
  • Threads of execution support: ImageMagick is thread safe and many internal algorithms are already threaded to take advantage of speed-ups offered by the dual and quad-core processor technologies  
  • (This is a copy pasted list from their website)

 

for more information and how to use this commad refer to ImageMagick website.

 

Well, The life is getting even easier.

 

More on Text Processing (March 14, 2008)

On March 12, 2008, I introduced some techniques that can be used to process big text files. Now, some more commands, which are also very useful, is introduced.

 

The command that I like to introduce here is 'cut' command. This command can be used to filter fields in each line. It contains many switches and options; but I will just introduce the most two basic ones, i.e. '-d' and '-f'. Although, these are the most basic switches of the 'cut' command; but you can do lots of wonderful things with it.

 

By using '-d' switch you can define what character has been used in the text file as the delimiter between separate fields. As an example comma is used in CSV file; hence, you have to issue '-d,'. If ':' is used as the delimiter then you have to issue '-d:'.

 

The '-f' switch is used to define which fields is needed to be shown. As an example, if each line in your text file contains, let say, 10 fields and you just need, let say, field 1 and 5, you have to issue '-f1,5'. Then just these two fields would be shown on your screen.

 

Example:

cat BigCSVFile.csv | grep 2000 | cut -d, -f1,5 > SmallCSVFile.csv

The above command pipes the contents of the 'BigCSVFile.csv' to 'grep' command. The 'grep' command filters those lines just containing the text string 2000 and the output is piped in 'cut' command. Now, the 'cut' command assumes that comma is the delimiter character and just field 1 and 5 are stored in SmallCSVFile.csv.

 

Don't forget that the SFU or cygwin must be installed on your Windows system prior to using 'cut' command.

 

Well, Your life just got easier.

 

 

Text Processing (March 12, 2008):

It happens a lot that you need to process a big text file. Many scientific information are still presented in a simple CSV (Comma Separated Version), meteorological information is just one example. But it is also common that you just need one portion of the whole text file, but the file is either just too big to be opened or the records that you want to extract are scattered through out the whole file. So, what to do then?

Many people try to import the CSV file into a database application, such as Microsoft ACCESS, and then by writing simple queries they retrieve their interested records. Sounds good and smart, but sometimes this procedure is too lengthy or the file is just so big that can not be handled by regular PCs and desktop database programs. Here, another method is introduced.

Using Microsoft Windows XP:

If you are using Microsoft Windows XP (well more than 90% of people are using it around the globe) you need to know just some simple commands. With out any doubt you have to issue these command in command prompt, i.e. CMD.

1- “TYPE”: This command pours the content of a text file on the screen. ( Ok, I know you already know this one)


2- “FIND”: This command searches for a text string in a file.

Example:
FIND “2000” filename.txt
Will return those lines in ‘filename.txt’ which contains the string ‘2000’.


FIND /V “2000” filename.txt
Will show those lines which does not contain the string ‘2000’ (because of ‘/V’ switch, for more switches type ‘FIND /?’)

3- “>” and “>>”: these are re-directive operators. The “>” operator means to redirect the outcome to a new file. If the file already exists it would be recreated. The “>>” operator means to redirect the outcome to the mentioned file and append it to the end of the file; hence, former information in the file will not be erased but if the file doesn’t exist it will be created.

 

Examples:
FIND “2000” filename.txt > newfilename.txt

All lines in ‘filename.txt’ containing ‘2000’ sting will be stored in .newfilename.txt’.

FIND “2000” filename.txt >>newfilename.txt
FIND “2001” filename.txt >>newfilename.txt
All lines in ‘filename.txt’ containing ‘2000’ and ‘2001’ are stored in ‘newfilename.txt’.

Mixing all command together:
TYPE bigCSVfile.csv | FIND “2000” > smallerCSVfile.csv


The above command is equivalent to

FIND “2000” bigCSVfile.csv >smallerCSVfile.csv

So, you already know what it does. “|” is also a redirector operator. It will redirect the output of the first command as an input to the second command.

Using LINUX and MAC:

LINUX and MAC are much faster in this kind of text processing. So, really consider to move on one of these platforms. If you are a LINUX or MAC user, you already know the appropriate commands. The only reason that I discuss it here is those Windows users, who have installed SFU or CYGWIN, are also able to use LINUX commands.

I don’t like to use the word “EQUIVALENT” because LINUX commands are much stronger and you have many more options while using LINUX commands. But as a lazy person I really don’t like to repeat the entire above text again. So, have this in mind that when I say “EQUIVALENT” it means that the command in LINUX does whatever the command in Windows does plus thousands of more options and task that the LINUX command does but the Windows one doesn’t.

1- Use “cat” for “type”.
2- Use “grep” for “find and “grep –v” for “find /v”
3- “>” and “>>” are the same.

Example:
cat bigCSVfile.csv | grep 2000 > smallerCSVfile.csv

And remember that LINUX is the case sensitive environment so “grep –v” is different than “GREP –v” or “Grep –v” or even “grep –V”. Well, the last one doesn’t have anything to do with casesensitiveness of the LINUX environment.

Well, now enjoy your life. The impossible has become possible.

 

(Yes, I know. I didn't use the word equivalent. Because it is not at all)