Showing posts with label algorithms. Show all posts
Showing posts with label algorithms. Show all posts
Tuesday, 20 September 2016
Tuesday, 2 August 2016
Particles explained using Gifs!!
Particles, just like most existing algorithms in computer science, are inspired by nature. Have you ever seen a beam of sunlight coming through a window and illuminate a bunch of floating particles (impossible in London though I have seen it before)? When you see these tiny particles, you notice that they are suspended in air and that it's very difficult to predict their motion unless you disturb the surrounding air. This simple concept is vital for many computer algorithms that model motion/dynamics of an object.
Particles, along with their randomness, can be simulated inside a computer program. The simplest of such algorithm is called Random Walk, where a particle is modelled with its current position/state alone and a random displacement/jump determines its next position in time. Here I have shown one Random Walk particle:
![]() |
A Single Random Walk Particle |
Monday, 6 June 2016
Expectation Maximization for Gaussian Mixture Model in OpenCV
I recently wrote code for Gaussian Mixture Model (GMM) based clustering in C++. As always, I found it much convenient to use OpenCV for manipulating matrices. Although there already exist an implementation of Expectation Maximization-based GMM, I tried to understand it by writing my own implementation.
The basic idea of GMM is to first randomly assign each sample to a cluster. This provides initial mixture model for clustering. This is then optimized using Expectation - or the probability/score of assigning each sample to each component in GMM - and Maximization - or updating the characteristics of each mixture component with the given probability/score . An attractive attribute of GMM is its ability to cluster data that does not have clear boundaries for clusters. This is achieved by having a probability/score for each sample from each cluster component.
The basic idea of GMM is to first randomly assign each sample to a cluster. This provides initial mixture model for clustering. This is then optimized using Expectation - or the probability/score of assigning each sample to each component in GMM - and Maximization - or updating the characteristics of each mixture component with the given probability/score . An attractive attribute of GMM is its ability to cluster data that does not have clear boundaries for clusters. This is achieved by having a probability/score for each sample from each cluster component.
Thursday, 14 April 2016
Particle Filtering - Survival of the fittest
I recently studied dynamic system models such as Kalman and Particle Filters.
For Kalman Filter I followed a Matlab demo that can be found here.
In this demo, the simple problem of tracking a ball is addressed using a Kalman Filter. The input sequence is of a ball, which is travelling at varying velocity and which is occluded in some frames by a box. I think this is a great example to demonstrate the power of dynamic system models, especially the occluded frames can be used to test how good a dynamic model is. Here is the actual sequence:
As you can see the ball goes underneath the box and comes out of the other end. If our dynamic model is accurate it will be able to predict the state of the ball even when it is not visible, and should match the position when the ball comes out.
For Kalman Filter I followed a Matlab demo that can be found here.
In this demo, the simple problem of tracking a ball is addressed using a Kalman Filter. The input sequence is of a ball, which is travelling at varying velocity and which is occluded in some frames by a box. I think this is a great example to demonstrate the power of dynamic system models, especially the occluded frames can be used to test how good a dynamic model is. Here is the actual sequence:
As you can see the ball goes underneath the box and comes out of the other end. If our dynamic model is accurate it will be able to predict the state of the ball even when it is not visible, and should match the position when the ball comes out.
Monday, 28 March 2016
Designing an algorithm - from ideas to code
I had always been interested in solving sudoku puzzles, partly because there are too many combinations that make each Sudoku unique. Since my work involves writing and using programming in different scenarios, I thought why not try using my skills on Sudoku. So there I was on a London Underground train to Barbican - looking at a Sudoku puzzle at the back of a morning newspaper, wondering how I can write an algorithm to solve it. I figured out a few simple tricks that I have always used in algorithm design. Here I explain what thoughts I had while designing my very own Sudoku solver and how I transformed those ideas into a working prototype.
First of all lets have a look at a typical Sudoku puzzle and some basic rules:
![]() |
Sudoku Puzzle |
Yes - it has got everything to do with numbers!! lots of numbers!
A Sudoku puzzle typically has 81 boxes where each box can have a number between 1 to 9. However, all these boxes follow some rules that make it all interesting. You may have noticed 3x3 squares grouping the number boxes. A correct solution of Sudoku ensures no repetition of numbers from 1 to 9 inside each of the 3x3 squares, in each horizontal line and each vertical line. When solving a Sudoku puzzle, this is exactly where I look for a solution, and exactly where my thought process starts for my Sudoku solver algorithm.
Labels:
algorithms,
application,
code,
demo,
matlab,
puzzle,
skill,
Tutorial
Sunday, 20 December 2015
Long Exposure Shots with a GoPro and Matlab
I recently got a GoPro. You know to get cool selfies, videos and all :D I am very much impressed by all the cool things you can do with it but was specifically impressed by the fact that one can create a time lapse video.
After giving a couple of tries to time lapse videos, I wanted to go beyond. I had always seen photographers make a long exposure shots by using specific DSLR cameras. I wanted to create just that using the only camera I had, a GoPro. However I had something much more than the camera, I knew how to write a code that deals with a number of images (I am a Computer Vision Engineer).
After giving a couple of tries to time lapse videos, I wanted to go beyond. I had always seen photographers make a long exposure shots by using specific DSLR cameras. I wanted to create just that using the only camera I had, a GoPro. However I had something much more than the camera, I knew how to write a code that deals with a number of images (I am a Computer Vision Engineer).
Labels:
algorithms,
code,
Computer Vision,
matlab,
Open Source,
random,
skill
Sunday, 24 May 2015
What if I told you, you can use OpenCV code with Matlab mex!!
Matlab is probably one of the best tools for quickly prototyping and testing your research ideas. As quick and flexible it is, sometimes Matlab code can consume a lot of execution time. This is specifically a big hurdle when multiple experiments need to be run. A real-time execution alternative is to implement Matlab compatible C++ code and compile it with mex-compiler. While this works most of the time, it is well known that quickly implementing ideas in C++ is not possible.
Labels:
algorithms,
application,
c++,
code,
compile,
Computer Vision,
matlab,
Open Source,
OpenCV,
Setup,
Windows
Sunday, 15 March 2015
Estimating Pi with OpenCV
Yesterday was Pi day where the date and time specifically corresponded to the value of Pi, i.e. 3/14/15 9:26 <===> 3.1415926 . What made this day extraordinary was how different ideas and videos came out, some explaining its significance while others showing fun ways to estimate its value.
One such video caught my eye in which @thephysicsgirl and @veritasium calculated the value of Pi using Monte Carlo sampling method but with a fun twist. Instead of using random particles they decided to use random darts and a modified dart board. They explain the idea in a very simple and intuitive way in the video.
Tuesday, 18 February 2014
Creating "Mood lights" animation with OpenCV
The other day I went on a typical London walk near Thames, and as always loved the lights, reflections and the view. It was amazing! One thing I really liked was the RGB mood lights on the bridge that transformed from every possible color in a way that it made the whole experience amazing!! Here is a glimpse from my instagram.
Since there was a sequence of colors involved, I thought I would at least try to replicate these mood lights using OpenCV. Turns out its not very difficult to make this animation at all. I wrote an algorithm for doing this using some clever tricks that did make it simple and interesting. Here is a gif showing how cool the animation looks when you execute the code.
Labels:
algorithms,
application,
Computer Vision,
demo,
Graphics,
random,
Windows
Saturday, 15 February 2014
Interview experience with Google
This may sound unbelievable but it all started a few months back in late 2013, when I saw a really cool movie called "The internship". Of course I had been thinking about applying for a software eng. intern position at Google for a long time, but it was this movie which made me get up from my couch of epic laziness and start preparing for the experience that was to follow! Unlike the movie, my story doesn't end with me getting a position at all, but it certainly is about the interesting path for a learning experience. So after watching the movie, I started preparing my application and submitted it within a few days. Pretty standard details were required for submission at this point.
Labels:
algorithms,
google,
internship,
interview,
random
Wednesday, 5 February 2014
Algorithm to check Sudoku puzzle!
I have got a couple of interviews this week, which I love preparing for as it a good way to refresh my C++ and at the same time, I get to implement some pretty interesting algorithms.
As most of us would do, I have been searching for the past few days about frequently asked interview questions and have been trying to solve most of the algorithm design questions myself. This post is about an interview question asked by google interviewers for an internship position. The question is about checking if a Sudoku Solution is correct or not.
Subscribe to:
Posts (Atom)