Archive for February, 2012

Keeping Up With Science : InTech Publishes 49 New Books For You To Get Hold Of Right Now

February 29, 2012 Leave a comment

InTechWeb Blog

There is no slowing down here at InTech as we are never go idle when it comes to satisfying our demanding readership. Our team has just uploaded 49 new, highly-engaging books covering the most dynamic areas of research today. Each book includes chapters addressing current trends, developments, and the latest innovations in a wide array of STM research fields, giving the reader a comprehensive, yet detailed overview of its areas of interest as well as an introduction into new research paths to be undertaken.

What you knew up until now might just be water over the dam so be the first one to read, share, and download our latest books.

View original post

Categories: Open Source

ImageMagick – resize image

February 29, 2012 Leave a comment

ImageMagick  is really a convenient tool for batch image process.

Install from here:

For my installation I simply choose what they recommended: x86 dynamic version.

Now, able to batch resize use command like( this will resize all the jpg image under the current folder (overwrite the original one) with a rescale ratio %25 :

mogify -resize %25 *.jpg

Here’s a link with more information:


Use help to get all the command line functions provided.

$ mogrify -help

Usage: mogrify [options …] file [ [options …] file …]


Python CGI Display Image

February 27, 2012 Leave a comment

I was trying to write a simple html using python-cgi. It’s really a powerful tool ~ However, I had some problems of displaying the image with text. Here’s what I found:

1. You should only define one type of your html file. It should be either , or .  You can’t combine them! Basically, you would like to choose text type, but use the <img> tag to include your image.

2. Using <img> tag, the src field should be the link to the image.  Your images in web page is actually a second request to the server, so it should be a reference to the image — in other words, it should be “the url to your image”.

3. So, a question is, for example for my case, my web page is actually “self-usage” ( though sounds stupid) which I want to use it to display images in my local folder as well (not only images from another web url) — how can I do this? Here’s two different ways I found.

(a) put your image (you can also try other media files) into /cgi-bin/. For me I create a subfolder /cgi-bin/images. It seems that the server can found items under cgi-bin — I mean, each item under your cgi-bin actually has a url.  such as http://localhost:8000/cgi-bin/image/001.jpg . This will provide you a valid url for your image that you want to include.

(b) Since we have define our web as ‘text’. So to display an image read from local folder, you need to format the image somehow. Here’s what may work for you:

data_uri = open(r'D:/TEMP/yourimg.jpg', 'rb').read().encode('base64').replace('\n', '')
img_tag = '<img src="data:image/jpeg;base64,{0}" alt="" />'.format(data_uri)


You can get more information from here:

A tutorial of some basic examples of using python-cgi:

Categories: Programming, Python Tags: ,

Python OpenCV Crop Image

February 16, 2012 Leave a comment

cvIm = cv.LoadImage(imfile)
cropped = cv.CreateImage((roi_width, roi_height), cvIm.depth, cvIm.nChannels)
src_region = cv.GetSubRect(cvIm, (roi_x, roi_y, roi_width, roi_height))
cv.Copy(src_region, cropped)

By the way, here’s a link for using openCV in matlab.

Install Opencv Python API

February 16, 2012 1 comment

1. Download and install Python 2.7
2. Download and install NumPy and SciPy. You can find most of the compieled packages for windows here:
3. Download OpenCV 2.3.1 for windows use the superpack one:
4. Double click on the OpenCV installer. It will extract OpenCV to your selected folder. I put it to C:\OpenCV2.3.
5. Configure your opencv: add path to your system enviroment.
At least you should add C:\OpenCV2.3\build\x86\vc10\bin to PATH
I forget what I did when I first install opencv, well this is my current system path:
C:\OpenCV2.3\build\lib\Debug;C:\OpenCV2.3\build\x64\vc10\bin;C:\Program Files\Intel\tbb\4.0\bin\intel64\vc10;C:\OpenCV2.3\bin

6. OpenCV 2.3.1 folder structure is different from OpenCV 2.2. The pre-build library and Python package are located at C:\OpenCV2.3\build.
7. Open Python IDLE
8. Add the following path to your python path:

import sys

8. Now, you are ready to import OpenCV with
import cv


Use Python cgi localy on Windows7

February 16, 2012 2 comments

How to setup python cgi on window 7.

Here’s my first try-out for uing python cgi on my windows7.

1- Create a fake server somewhere on your disk, like D:\myserver

2- Go to your python installation folder and find Lib (for me it’s C:\Python27\Lib). Then copy the file:  to the server dir you just created (e.g. D:\myserver).

3- Create a subfolder under myserver: e.g. D:\myserver\cgi-bin.  This will be the folder where you put your codes in.

Copy the python code down the bottom, and save it as Then put it  into D:\myserver\cgi-binIt  will display “hello world” in your browser.

4-Run the file D:\myserver\ 🙂 Great,You now have the server running!

5- To run your code: D:\myserver\cgi-bin\ You need to put the server and port into your browser address line, like this:


print "Content-Type: text/html"
print """<html>
<head><title>First Python HTTP Programming </title></head>
<h2>Hello World!</h2>

By the way, a very nice tutorial:


Categories: Uncategorized

Install Matplotlib, Scipy on Mac

February 12, 2012 Leave a comment

Struggling for a while to install matplotlib on my mac, finally find this one works:

First install brew: <>

And following the instruction posted here.

$ brew install python
 $ brew install gfortran
 $ brew install pkg-config
 $ easy_install pip
 $ pip install numpy
 $ cd $HOME
 $ git clone
 $ cd matplotlib
 $ python build
 $ python install

Well, then continue for my scipy 🙂

Here’s a ‘investigation‘ that i found, very useful. The official scipy/numpy site only say that CC, XCC, etc needs to be changed, but not for the fortran part. For my case, I did’t export the CC, etc — it not works for me, but I deed have fcompile specified.

mkdir ~/tmp
cd ~/tmp
git clone
cd scipy
python build --fcompiler=gfortran
sudo python install

Install nose:

sudo pip install nose
Categories: Uncategorized Tags: ,