Tuesday, March 16, 2010

Color Image Segmentation using Meanshift Algorithm


The meanshift method can be used to segment color image. In this method image pixels is treated as points in color space.In each iteration the meanshift vector is calculated for points which are inside the kernel radius.After that the the old kernel location is changed to meanshift vector's position. Color is also updated. This process continues untill both converge.

Original Image


Meanshift Filterd Image


As the iteration count increases , the same color segment which has same type of colors will get merged together. You can see the effect of meanshift filter on sachin's photo.Its like water painting (not exactly,there are other filters for that. )





Thursday, March 11, 2010

How to check a Point inside a Triangle


When i started to learn vector mathematics , i had found many methods to determine whether a point is inside a triangle or not.Easy method is not the fastest. This type of calculations are very important for making a fast graphics library.
Following are the methods which i remember now.
1. Using Cross Products
Take cross product between each triangle edge and the point to check. If the direction of cross product result is for the three edges that point is inside the triangle , otherwise not

2. Using the angle between the vectors made by point and triangle coordinates.If the sum of angle is 360 the point is inside , otherwise not.



3. Using Point and Plane test.See the figure. You need to know plane equation to understand it.




4. Using Bary centric Coordinates
This is the fastest of above. It involves checking the point in Bary centric coordinates system.