Friday, November 30, 2012

Gabor Filters, some useful links for overview

I had to go through the functionality of gabor filter for a group discussion. It was really interesting and engaging discussion where everyone really got involved, and I learned more than I taught :)..

Well, I am putting down the links I referred for my study,

I also found a beautiful presentation about Gabor filters and texture segmentation (The most important application of Gabor filters). Here it is...

There is a matlab implementation also available :

Tuesday, November 27, 2012

compressing in Linux : the 'tar' command

I find  the 'tar' command very useful for my work especially when I work with lots of files and maintain lot of versions of code. The man page of tar is huge and I am sure there are many more flavours to it. However, I always find it confusing...there are certain customizations of 'tar' that come handy to me often and here they are...

$tar -cvzf filesDir.tgz  filesDir/
Compress all files in directory filesDir to filesDir.tgz

Suppose, you edit only a few files of a huge directory with lots of sub-folders, then you would want to save only those few files.

In such case you should maintain a fileList which contains all filenames with relative path to the parent folder.

$cat fileList.txt

$tar -cvzf filesDir.tgz -T fileList.txt
This will compress  the files mentioned in fileList.txt. Note that subdir4/ is an entire folder. In this case, we are compressing all files contained in subdir4/

Now, comes the uncomressing part.

Go to the required path.
$ mkdir filesDir
$cd filesDir
filesDir]$ tar -xvzf filesDir.tgz

In case when you want to merge this data into another version of the same library/code, you can go into that directory and simply untar as above. The corresponding files in respective paths will get replaced by the files in filesDir.tgz, and new files and folders will be added.

Before untarring, we may want to check the difference to make sure that we are doing the right thing.

Here are the commands:
$diff -r dir1/ dir2/
This will display all the differences in two directories and their contents recursively (-r).

If you want to just see the files which correspond to changes, not the contents, then
$diff --brief -r dir1/ dir2/

Saturday, November 24, 2012

beautiful Matlab tutorials for advance usage

Found  an excellelent tutorial on Matlab for advance usage such as speed-up, debugging, using OOP.  Its been really useful to me, hope anyone who finds it will be equally delighted having found it :)

YAGTOM: Yet Another Guide TO Matlab


Monday, November 19, 2012

UGM Library for Undirected Graphical Models

I was in search for  suitable library for CRF implementation for my segmentation work and found the UGM library useful, since it has some demos and nice explanations for different functionalities. It also seems to be up-to-date with different inference techniques.

Here is the link for the directory:

They have clearly explained the download and setup process. However, I found that bit scattered across different pages, so here are the steps that I went through:

1. Download the tgz from the homepage .
The 2011 version is available in

2. There are also some updates in 2012. Download them as well.

3.Download the mex-wrapper for maxflow from the link and place it under the directory UGM/

4.Download from and place it inside UGM/maxflow/  under the name maxflow-v.3.0 (since the different files refer to it in the same name.)  Note: there is a  Readme.txt in UGM/maxflow/ to guide us too.

5.In matlab command window,
 >> cd UGM/
 >> addpath(genpath(pwd))
>> mex -setup
>> mexAll

In case you find errors like the following while running mexAll, sort it out using help from the other blogpost :  matlab-error-of-type-usrbinld

: /usr/bin/ld: matlab/sys/os/glnx86/ version `GLIBCXX_3.4.10' not found (required by /usr/bin/ld) 


 5. >> cd maxflow/
      >> make
     >> test1 
     >> test2   % to test the functionality
      >> cd ..

In case you are in a 64-bit system, you will face an error like this:

>> make     
>> test1

??? Error using ==> maxflowmex
Function "mxGetIr_700" is obsolete in file "compat32.cpp", line 282.
(64-bit mex files using sparse matrices must be rebuilt with the "-largeArrayDims" option.  See the R2006b release notes for
more details.)

Error in ==> maxflow at 35
[flow,labels] = maxflowmex(A,T);

Error in ==> test1 at 32
[flow,labels] = maxflow(A,T)

The solution is, 

edit the file maxflow/make.m as follows:

mex -O -largeArrayDims maxflowmex.cpp maxflow-v3.0/graph.cpp maxflow-v3.0/maxflow.cpp

>> make
>> test1 
>> test2   % to test the functionality
>> cd ..

6.  Run any demo present in UGM/examples/. For example,
  >> example_UGM_AlphaBeta 

Friday, November 9, 2012

Handling Sparse matrices in Matlab

Matlab has its own memory limits due to which we have to define very large matrices
as sparse and use them. But we can not use them exactly the same way as normal matrice
due to difference in the way of storage. In my case, I have to define neighborhodd of 
pixels in an image which is usually of large size(307200 for a 640x480 image!!!). So,
the nbrhood matrix (lets call it adj) is now of size 307200x307200, which is huge.
I posted this in stackoverflow and had a beautiful discussion over the forum.
>>nNodes = 50400;
>>adj = sparse(nNodes,nNodes); %adj is a large sparse matrix with all values as zero.
I want to insert a 1 to adj(i,j) if pixel i and j are adjacent.
>>adj(sub2ind([nNodes nNodes], ind, ind + 1)) = 1; %ind is a vector of indices
??? Maximum variable size allowed by the program is exceeded.
Therefore, it is better to define adj in the following way, where definition
and updation take place in one shot. 
>>adj = sparse(ind, ind + 1, ones(size(ind)), nNodes, nNodes, length(ind));
Now, how do we access sparse matrix elements?
In a general matrix, we can access and modify the elements, 
either by using 2-dimensional indexing  or linear indexing.
for example,
>> a = [ 1 2 3; 4 5 6]
a =
     1     2     3
     4     5     6

>> a(1,2)
ans =

>> a(3)
ans =

>> i = find(a == 2)
i =
>> [i,j] = find(a == 2)
i =
j =

But we do not have the luxury to access using linear index 
for sparse matrices.
If I want to access non-zero elements of sparse matrix, I have to 
access the following way:
>> [i,j] = find(adj); 

The elements with higher indices must be accessed with 
2-dimensional indexing:

>> adj(nNodes, nNodes)
ans =

>> adj(nNodes * nNodes)
??? Maximum variable size allowed by the program is exceeded.
That's it with sparse matrices for the time being. :)

Monday, November 5, 2012

Video Lectures of BMVC 2012

The video lectures of tutorials, keynote speeches and oral presentations BMVC 2012 are available in  the following link:

They seem to be interesting, so I decided to listen to them :)

I am going to list down the ones interesting to me as I listen to the lectures one by one ...

1. Pushmeet Kohli's talk on MRFs:

Sunday, November 4, 2012

Matlab error of the type : /usr/bin/ld: matlab/sys/os/glnx86/ version `GLIBCXX_3.4.10' not found (required by /usr/bin/ld)

When I tried to compile mex files in Matlab (R2009a, 32-bit) on my Ubuntu 11.10 system, I got the following error:


/usr/bin/ld: /home/swagatika/softwares/matlab/sys/os/glnx86/ version `GLIBCXX_3.4.10' not found (required by /usr/bin/ld)
/usr/bin/ld: /home/swagatika/softwares/matlab/sys/os/glnx86/ version `GLIBCXX_3.4.11' not found (required by /usr/bin/ld)
/usr/bin/ld: /home/swagatika/softwares/matlab/sys/os/glnx86/ version `GLIBCXX_3.4.15' not found (required by /usr/bin/ld)
collect2: ld returned 1 exit status

    mex: link of ' "minFunc_2009/lbfgsC.mexglx"' failed.

Well, I found that I upgraded my system from v10.10 to 11.10. In the process, the libraries stored in Matlab were not updated with the system libraries.

So when such an error occurs,

1) Locate the library file in the system.
2)Remove or create a back up of the library in Matlab path.
3)Create a soft link in the matlab's appropriate folder for the one present in /usr/lib/

$ locate

$ln -s /usr/lib/i386-linux-gnu/

Now it compiles properly.

Thursday, November 1, 2012

IROS 2012 Videos

I found the following link from a friend, the videos are awesome to watch. Each of them is very interesting. So here is the link to motivate us :)

Monday, October 29, 2012

batch processing using Imagemagick

Imagemagick is a wonderful tool if you want to do batch image processing.

There are few operations which are very useful, but I tend to forget them all the time. :P

Image resizing:

$mogrify -resize HxW  *.jpg

where, HxW is image size (Height x Width). We can take any image format in place of jpg.

If we want to force the desired size,

$mogrify -resize HxW! *.jpg

I prefer using the second command to the first one.

Remember, this replaces the original image file. So you need to take a backup of the current image directory before applying this command.

Format Converstion:

For conversion of all images in current directory to another format,

$mogrify -format <newformat>  *.<currentformat>

for example,
$mogrify -format ppm *.bmp

This converts all bmp images to ppm format and saves a copy.

We can apply this command without worrying at all, since a new copy is created without losing original image format.

Autocrop Images: 

Usually when we save matlab figures, we get large undesirable white boundaries.  We may want to crop those images to fit to actual image dimensions.

$convert -trim image.jpg image.jpg

For processing images in a batch, you can use the following script:
$for i in `ls *.jpg`; do convert $i -trim `basename $i`; done

If you do not want to replace the current image, and rather make a new copy of it, do as follows:
$for i in `ls *.jpg`; do convert $i -trim cropped_`basename $i`; done

Refer this link to go through more complicated settings for the same purpose.

confusion in VL_SLIC

The input image for segmentation:

Way1: Read the img as im2double , so the intensity ranges from 0 to 1. Here, the output superpixels are more regular and spacious.

img = im2double(imread('Images/2_14_s.bmp'));
regionSize = 30 ;
regularizer = 0.1;

%get the SLIC superpixels
segments1 = vl_slic(single(img), regionSize, regularizer) ;

Way2: Read the img as uint8 , so the intensity ranges from 0 to 255.
Here, the output superpixels are more irregular but tightly fit to the edges.

img = imread('Images/2_14_s.bmp');
regionSize = 30 ;
regularizer = 0.1;

%get the SLIC superpixels
segments1 = vl_slic(single(img), regionSize, regularizer) ;
I want to know which is the right way? and why this change is affecting the performance?