Two video clips side by side using imagemagick and ffmpeg

Just copy the following code into a script file and run it at your bash. Please remmeber to “d2u your_file_name” otherwise you would have the error “syntax error near unexpected token $’\r’ “.

—————————————————————————————————-

n=900 #image number

for(( i=0; i<n; i++))
do
montage -label ‘%f’ “xrCor$(printf “%04d” $i).png”  “xrSag$(printf “%04d” $i).png” -tile x1 -geometry +4+4 “montage$(printf “%04d” $i).bmp”
done

ffmpeg -b 7000k -r 10 -i montage%04d.bmp -b 7000k -r 10 -vcodec mpeg4 -vtag DIVX montage.avi

draw line segments in matlab

After spending some effort searching online, I found one solution:

r = 5;
x1 = linspace(pos.cx – r, pos.cx + r);
y1 = linspace(pos.cy, pos.cy);

x2 = linspace(pos.cx, pos.cx);
y2 = linspace(pos.cy – r, pos.cy + r);

index1 = sub2ind(size(im), round(y1), round(x1));
index2 = sub2ind(size(im), round(y2), round(x2));
im(index1) = 127; % set the valudes to 127 for display
im(index2) = 127; % set the valudes to 127 for display

The above code snippet is used to draw a cross on an image or matrix. Because of over sampling, the line drawn is without aliasing artifacts. For drawing lines on figures, there exists an easier solution, just use function ‘line’. For example:

line(rect(1,:), rect(2,:),’Color’,’r’,’LineWidth’,2);

Reduce PDF size generated by Latex

One of the problems we often meet when submitting papers is that the size of our pdf paper is beyond the space limit. For graphics and vision conferences, it is very common for us to generate a ~50 MB pdf while the size limit for the paper and supplemental materials together is about 20MB. That is necessary for the conference to guarantee its submission site is still functionable at the last seconds before the deadline.

To reduce the pdf size, you could reduce your eps/png figures manually before you include them into your tex file. There is also a very easy way if you have Adobe acrobat. You could use  “Advanced->PDF Optimizer”.  In the opened dialog, you can set the compression of figures, fonts, and other staff to reduce your pdf size. I just managed to reduce the size of my paper from 20MB to about 400KB.

An alternative way is to use PrimoPDF. It has several predefined settings for generating PDF best for screen, ebook, print, and prepress. It also supports customized settings.

If you already have an eps file, and still want to reduce its size. You could run the following code: (http://electron.mit.edu/~gsteele/pdf/)

> gs -r300 -dEPSCrop -dTextAlphaBits=4 -sDEVICE=png16m -sOutputFile=fig.png -dBATCH -dNOPAUSE fig.eps
> convert -quality 80 fig.png fig.jpg
> convert fig.png eps3:fig.eps

Instead of using LaTex, you could also use PDFLaTex. In this case, you can use the following code to convert your figures to PDF files.

> for i in *eps; do ps2pdf -DEPSCrop $i; done
> sed -i ‘s/\.eps}/}/g’ *tex

Forming a 2D window from a 1D Function

I came to this question because of the Kaiser window used for my BM3D implementation. I used Matlab to generate the Kaiser window I want for my C code so I don’t bother to write that function in my project. However, Matlab only has 1D version of the window functions. The following demonstrates two ways to generate the 2D window from its 1D function.

——————————————————————-

There are basically two ways of forming a 2D window from a 1D function. The
first is the outer product formulation; the second is the rotational
formulation. To create a outer product window (which your kaiser examples
look like they are trying to do), you can use

w1D = hamming(16); % Some 1D window
w2D = w1D(:) * w1D(:).’; % Outer product

To use a rotational formulation (which generally gives more circular
contours), you can use

L = 16;
w1D = hamming(L); % Some 1D window
M = (L-1)/2;
xx = linspace(-M,M,L);
[x,y] = meshgrid(xx);
r = sqrt( x.^2 + y.^2 );
w2D = zeros(L);
w2D(r<=M) = interp1(xx,w1D,r(r<=M));

http://www.mathworks.com/matlabcentral/newsreader/view_thread/23588

Using opencv from python on windows

http://stackoverflow.com/questions/4709301/installing-opencv-on-windows-7-for-python-2-7

The official OpenCV2.2 installer does not install the Python bindings into your Python directory. There should be a Python2.7 directory inside your OpenCV 2.2.0 installation directory. Copy the whole Lib folder from OpenCV\Python2.7\ to C:\Python27\. Then set the windows environmental variable PATH to include your OpenCV\bin directory together with C:\Python.

Alternatively use the opencv-python installers at http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv.

Warning: Remote Host Identification Has Changed

I met this problem today morning after I started the sshd service. I think it is because I just updated my Fedora recently, and the ssh known_hosts file in your home directory should be updated too. There are 3 solutions to solve this,
http://www.cyberciti.biz/faq/warning-remote-host-identification-has-changed-error-and-solution/

The simple solutions to this problem are:
$ cd
$ rm .ssh/known_hosts
$ ssh ras.mydomain.com
or just:
ssh-keygen -R server.example.com

Fedora 14

Fedora 14 was released before I remembered that I should update my Fedora 12 to 13. So I was lucky to install Fedora 14 directly instead of 13. I tried the live CD and the installation was fast and pleasant, less than 5 mins. Later on, I found out it was very painful to use live CD as the installation media. Lots lots of packages are not there. So I spend hours in the afternoon to install the packages I need. Today when I planned to do some programming, and found out that GCC is not installed?? What the hell? Linux without GCC? Fortunately, you can use yum to install all these packages very easy, like:

yum groupinstall “Development Tools” “Development Libraries”

yum groupinstall “GNOME Software Development” “X Software Development” “Java Development” “Legacy Software Development” “KDE Software Development” “Fedora Packager” “XFCE Software Development” “Web Development”

RAW vs TIFF

Need to read raw images for my project. I found lots of open source packages on line, but it still needs many efforts to read and incorporate the code. Then I remember that TIFF has 16 bit version, maybe I could convert raw to 16bit tiff, which could still give me enough information about the scene, since normally raw images have 12 or 14 bits for each pixel. This sounds convenient and effortless. However, after a few experiments, I found that 16 bit tiff still loses lots of information about the scene. Mainly because when you convert raw to tiff, you have to do demosaicing, white balancing, sharpening and gamma correction for viewing (maybe). This process will inevitably truncate some head room gained by using raw format when comparing with jpeg. That is why people says “stay in Lightroom for as long as you can” (or the equivalent “do as much in ACR as you can)”), as all edits in Lightroom are nondestructive and non-cumulative.

For a detailed investigation, please check out these posts,
http://forums.adobe.com/message/2742439
http://www.bobatkins.com/photography/digital/raw.html
http://www.cambridgeincolour.com/tutorials/RAW-file-format.htm
http://osp.wikidot.com/raw

content management system

Long time ago, I tried to set up a blog website on my desktop, since I have static IP at school. Now this could be done very easily by some content management systems. The three most popular CMS are wordpress, drupal, and joomla. Drupal is developer friendly, and hard to setup. WordPress is perfect for me. Easy to setup, and the functionality is enough for my use. It only took me several hours to set up it, although I still haven’t figured it out how to upload images. Anyway, it works fine to me. One good article about the difference between these CMS could be found at: http://www.goodwebpractices.com/other/wordpress-vs-joomla-vs-drupal.html. Actually you could also use pmwiki, the one used by our department.

SVN Tutorial for Unix

A very good detailed svn tutorial for linux.
http://artis.imag.fr/~Xavier.Decoret/resources/svn/index.html

I found it is very easy to setup svn repository in Linux if only one person is going to use it. Under windows, I have to configure apache+subversion server on my desktop, and use TortoiseSVN to commit/update from my laptop. While in Linux, you just need to type a couple of commands. From laptop, you can access the code repository by using svn+ssh://url.of.desktop/home/user/svn project“. It is super convenient, no surprising as usual.