26 February 2017

Cloud from aeroplane window

Here is a photo i took from a recent trip from HKG->BLR; not that the matters because you cannot identify from the photo itself. The clouds look cool; i thought.

08 January 2017

Book list

Here is my book-list. I plan to keep this updated with suggestions. I can read Hindi, English, Bengali and Tamil. If you like to make suggestions, please drop a comment.

20 November 2016

Caffe using anaconda or miniconda

I have been spending some time in installing the machine learning software caffe on Slackware. I have a modest GPU card, the GE Force GT 730. Slackware version is 14.1. For installing caffe, there are a few requisites which can be easily installed from source. These are: gflags, glog, leveldb, lmbd, snappy and protobuf. Also, users of Python scientific computing packages would be aware of Anaconda or miniconda, which offers a bunch of scientific computing software(and maybe much more besides) in one package or an installer. This is a Very Useful Thing. However, I have had massive trouble compiling caffe using the Anaconda python. The only reason is that the final linking step throws up this kind of error . That is, libboost_python looks for a different version of python that provided by Anaconda(which we specified in the Makefile.config file prior to starting the build. One solution is to re-build the entire boost using the Anaconda python distribution, but it could mean making more changes systemwide. However, I do with that it would be easy to know which python version the built libboost_python.so links to. This information is not available from ldd. There is also an explanation to this in some thread, but practically I found that it is best to use the system python. With the availability of pip, it is no more tedious to install multiple packages.

25 September 2016

Adding existing header files in Eclipse project

I am facing a strange problem when I add existing header files to an existing Eclipse. I have added the files using Import->File System->Directories and then choosing the necessary files. This works for making the IDE aware of these files and for symbol resolution. Unfortunately, when the project is attempted to be built, there is a failure due to these included header files. I have taken a look at the forums but the only solution provided is to include these new directories in the c/c++ properties of eclipse. strangely, this problem does not happen in visual studio. I felt that Eclipse can also do this, i do not now why this is not done. This can be considered to be a "wishlist" by the respected Eclipse developers.

10 May 2015

Motion by curvature example in 2D

Here is a simple set of Octave/MATLAB files to help anyone understand or visualise motion by curvature for a 2D planar curve. I am yet to find out how to embed code in HTML; but in any case it is easier to pack and zip files in one place. The above plot shows a random curve green which has been evolved by its curvature for some iterations and the resultant curve is shown in red. 
One problem I faced was that if i increase the number of curve points to a very large number, say 150 or above, the evolution is not so stable any more and we get unexpected results. My guess is that this is a numerical stability issue rather than a bug in the code but do feel free to correct me by emailing or leaving a comment in this web-log entry or from where you downloaded the code or by emailing me.

09 May 2015

Our Lady of Alice Bhatti Quick review

I bought this book from Amazon.
Below is review:

I have read Mohammed Hanif's "A case of exploding mangos" for maybe 150 rupees. That was an amazing book; unbelievable. So I bought this book. This is also an amazing narrative of Christian suppression in Pakistan. Salute to the author. Also the protagonist is a woman; add that to her troubles as well. This is a much darker book than the Case of exploding mangoes. This is worth a read definitely. And the courage of Shri Mohammed Hanif is not to be trivialised.

Amuktamalayada translation by Srinivas Reddy

I bought the book from Amazon and posted the review below:
Amazed to read the history of this book. The original version is written by a Kannada king in Telugu language and is about a Tamil saint and describes Madurai with great zest. Amazing, that despite cut-throat warfare in the South the people still managed to praise something or the other from other regions. As a translation, obviously it looks kludgy but the author has made best effort and called this his labour of love. Praiseworthy. My prime reason for liking this book is it notes and annotations. Very nice.

02 May 2015

MICR code for SBI

Why is it so difficult to get MICR code for SBI from official SBI website? Getting teh IFS Code or IFSC is easy.

25 January 2015

ShopClue Less

This is a crib post. I frequently purchase articles online and most of the times there is promise of amazing deals from shady or semi-shady websites. i ignore and stick to the few well-known ones; even there I have received poor quality good and have had no problems returning those. Recently, I came across a websites called Shopclues dot com. There was an amazing "deal" or "offer" on CFL lamps. It seemed to be really good and I have heard about these sellers from some friends. I do not think they gave positive reviews nor necessarily negative ones either. Anyway, partly curious and partly out of, I admit the "greed" to grab a good deal, I placed the order for two CFL lamps. The photo in the shopclues website was blurry but I could decipher a brand. I was under the impression that the brand they ship might be good but they choose not to mention the name. Well, long story short; when the wretched things came; the CFLs were crushed. I do not know what went wrong and where but there was no packaging at all for the lamps. Just that they were dumped in a big cardboard box and dispatched. Also, the brand of the lamps was one which I saw for the first time ever. The courier was RedExpress; do not know if this is a shady courier service. The beauty comes now however. I went to the "returns" part of shopclues; and one has to enter the reason for return. Fine; but then the beauty is that YOU the customer has to take photos of the material and upload those. Then the jerkoffs of ShopClues would consider your case and issue a refund or whatever. I sent an email to the Shopclues wretches stating clearly the problem. I pointed out to them that they do not seem to have any quality control check in place, and tie up with the most dodgy of sellers; and doubt the integrity of the buyers who have upped their money. The regulation response came from some low IQ wretch manning the website. The buffoon merely reiterated their policy, expressed his deepest anguish, sorrow and other emotions at my troubles and then fowarded the same link as before which demands that I upload a photo. 
Anyway, I did not want to take a photo and demean myself( at least I think it is demeaning). So, the lesson is "Buyer Beware". Now that I have had first hand experience with ShopClues; the big message to you prospective customers is: be prepared to take the photo of your damaged product before you see back a rupee. Many of us do not check the returns policy before buying. I give you people a free early warning for this dodgy website.

01 November 2014

Elementary 2d rotation registration

Hopefully would prove useful for someone!
Representation of rotation is angle only; and optimisation is steepest decent. metric is the sum of squared difference metric. Shared purely for pedagogical purposes. Python code is horribly unoptimised.


import numpy, cv2
import scipy
from scipy import ndimage
import matplotlib
from matplotlib import pyplot
#def rotate_correct(fixed, moving, init_angle=0):
DATA_DIR = 'your_data_path_here';
FILE_NAME = 'fixed.png';
ROT_FILE_NAME = 'moving.png';
INIT_ANGLE = 0;
#
fixed = cv2.imread( DATA_DIR + FILE_NAME, cv2.IMREAD_GRAYSCALE);
moving = cv2.imread(DATA_DIR + ROT_FILE_NAME, cv2.IMREAD_GRAYSCALE);
#
fixed_im = numpy.float32(fixed);
moving_im = numpy.float32(moving);
registered_im = numpy.copy(moving_im);
#
NUM_ITER = 25;
STEP_SIZE = 0.00001;
BORDER = 70;
N = registered_im[BORDER:-BORDER, BORDER:-BORDER].shape[0]*registered_im[BORDER:-BORDER, BORDER:-BORDER].shape[1]
INIT_SSD_COST = registered_im[BORDER:-BORDER, BORDER:-BORDER] - fixed_im[BORDER:-BORDER, BORDER:-BORDER];

INIT_SSD_COST = numpy.sum(INIT_SSD_COST**2);
print('Initial_SSD: {0}'.format(INIT_SSD_COST))
estimated_angle = INIT_ANGLE;
D = numpy.gradient(registered_im);
D0 = D[0];
D1 = D[1];
term1 = numpy.zeros_like(fixed_im);
#
prevSSD = INIT_SSD_COST;
prev_angle = INIT_ANGLE;
for iter in range(NUM_ITER):
   
    term1[BORDER:-BORDER, BORDER:-BORDER] = registered_im[BORDER:-BORDER, BORDER:-BORDER] - fixed_im[BORDER:-BORDER, BORDER:-BORDER];
    update = 0.0;
    for x in range(BORDER,fixed_im.shape[1]-BORDER): #X direction
            for y in range(BORDER,fixed_im.shape[0]-BORDER): #Y Direction
#                 rotation_matrix = numpy.array( [ [numpy.cos(angle), -numpy.sin(angle)], [numpy.sin(angle), numpy.cos(angle)] ]);
                rotation_matrix_deriv = numpy.array( [ [-numpy.sin(estimated_angle), - numpy.cos(estimated_angle)], [numpy.cos(estimated_angle), -numpy.sin(estimated_angle)] ])
                x1 = x*rotation_matrix_deriv[0][0] + y*rotation_matrix_deriv[0][1];
                y1 = x*rotation_matrix_deriv[1][0] + y*rotation_matrix_deriv[1][1];
                term2 = D0[y,x]*x1 + D1[y,x]*y1;
                update = update + term1[y,x]*term2;
    update = STEP_SIZE*update/N;
    estimated_angle = estimated_angle - update;
    D0 = scipy.ndimage.rotate(D[0], estimated_angle*180.0/numpy.pi,reshape=False);
    D1 = scipy.ndimage.rotate(D[1], estimated_angle*180.0/numpy.pi,reshape=False);
    registered_im = scipy.ndimage.rotate(moving_im, estimated_angle*180.0/numpy.pi,reshape=False);
    SSD_COST = registered_im[BORDER:-BORDER, BORDER:-BORDER] - fixed_im[BORDER:-BORDER, BORDER:-BORDER];
    SSD_COST = numpy.sum(SSD_COST**2);
    currSSD = SSD_COST;
    if currSSD > prevSSD:
        estimated_angle = prev_angle;
        print('Minima reached. Exiting loop');
        break;
    else:
        prev_angle = estimated_angle;
        prevSSD = currSSD;
        print('Iter: {0}'.format(iter+1)),
        print('Step Update: {0} Estimated Angle: {1}'.format(update*180.0/numpy.pi, estimated_angle*180.0/numpy.pi)),

        print('SSD: {0}'.format(SSD_COST/INIT_SSD_COST))
    if iter == NUM_ITER - 1:
        print('Max iter reached. Exiting loop');
##
SSD_COST = registered_im[BORDER:-BORDER, BORDER:-BORDER] - fixed_im[BORDER:-BORDER, BORDER:-BORDER];
SSD_COST = numpy.sum(SSD_COST**2);
print('Final_SSD: {0}'.format(SSD_COST/INIT_SSD_COST))

print('Estimated_angle: {0}'.format(estimated_angle*180.0/numpy.pi))
##
DISPLAY = 0
BORDER  = 1;
if DISPLAY == True:
    #
    pyplot.subplot(131)
    pyplot.imshow(fixed_im[BORDER:-BORDER])
    pyplot.gray()
    pyplot.title('Before image difference')
    #
    pyplot.subplot(132)
    pyplot.imshow(moving_im[BORDER:-BORDER])
    pyplot.gray()
    pyplot.title('After difference ')
    #
    pyplot.subplot(133)
    pyplot.imshow(registered_im[BORDER:-BORDER])
    pyplot.title('Registered image')
    pyplot.gray()
    #
    pyplot.show()