Archive for the 'C Programming' Category

May 31 2007

Effecient Sorting Algorithm For Applying Median Filter to a Image

Published by admin under Algorithms, C Programming

Normally median filters are applied to remove speckle noises in an Image. There are many variations of Median Filters but all these variations are for choosing the kernel dimensions and shape. What i mean by kernel is that it could be a 3X3 kernel or 5X4 kernel or a radius 3 kernel.

A 3×3 kernal will have 9 elements to sort

A 5X5 kernal will have 25 elements to sort

A radius 3 kernel will have 29 elements to be sorted before you can pick the median.

Bottom line is you choose any variations of kernals, it boils down to effeciency of sorting. I have come up a one such algorithm that i think is very effecient for Median Filtering

Assumptions:

  1. RGB Planar data. The bit depth Per pixel is 8 bits.
  2. Median Filter Kernel size is Odd Number. Like 5, 9, 25 etc
  3. The following code is PseuodCode and good for one dimensional data.

A pseudo Code implementation of the Algorithm is shown below:

Continue Reading »

Comments Off

May 24 2007

How to Avoid Integer overflow in C?

Published by admin under C Programming

Here is the General Way to avoid integer overflow.Example 1

value = value + 100;

if ULONG_MAX - 100 >= value
then No Overflow
else
overflowed

Example 2

x = x * 10 + r;

To Check whether x would overflow, do the following before you execute the above sentense

if ULONG_MAX - r/10 >= x
No Overflow
else
overflow

NOTE:ULONG_MAX is normally defined in limits.h. And it is dependent on the Processor.

Comments Off