Archive for the 'C Programming' Category

Nov 10 2013

C++ Operator Functions Declaration

Published by under C Programming

A summary on how the different operator functions, in C++,  have to be declared

(replace @ by the operator in each case):

Expression Operator Member function Global function
@a        + – * & ! ~ ++ — A::operator@() operator@(A)
a@        ++ — A::operator@(int) operator@(A,int)
a@b        + – * / % ^ & | < > == !=

<= >= << >> && || ,

A::operator@ (B) operator@(A,B)
a@b        = += -= *= /= %= ^= &=

|= <<= >>= []

A::operator@ (B)          –
a(b, c…)        () A::operator() (B, C…)          –
a->x        -> A::operator->()          –

PS: This is for my reference that I copied from cplusplus.com.

Comments Off on C++ Operator Functions Declaration

May 31 2007

Effecient Sorting Algorithm For Applying Median Filter to a Image

Published by 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 on Effecient Sorting Algorithm For Applying Median Filter to a Image

May 24 2007

How to Avoid Integer overflow in C?

Published by 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 on How to Avoid Integer overflow in C?