Wednesday, January 30, 2013

Low pass filters (blurring) in Image Processing using C++


Low pass filtering also called "blurring" & "smoothing" is very basic filtering operations in image processing. The simplest low-pass filter just calculates the average of a pixel and all of its eight immediate neighbours. The result replaces the original value of the pixel. The process is repeated for every pixel in the image.The example of Kernel used for simple low pass filters is
In this kernel pixel values from the neighbourhood are summed without being weighted, and the sum is divided by the number of pixels in the neighbourhood. Here is the C++ code for low pass filtering operation using above Kernel (Averaging operation) . Here I implement the convolution operation.

Source Code : C++ 

Saturday, January 12, 2013

Histogram equalization using C++: Image Processing


The histogram equalization is an approach to enhance a given image. The approach is to design a transformation T such that the gray values in the output are uniformly distributed in [0, 1].


Compute a scaling factor, α= 255 / number of pixels
Calculate histogram of the image
Create a look-up table LUT with
    LUT[0] =  α * histogram[0]
for all remaining grey levels, i, do
    LUT[i] = LUT[i-1] + α * histogram[i]
end for
for all pixel coordinates, x and  y, do
    g(x, y) = LUT[f(x, y)]
end for

Source Code : C++

Thursday, January 10, 2013

Intensity Histogram using C++ and OpenCV: Image Processing

The histogram of a digital image with gray levels in the range [0, L-1] is a discrete function h(rk) = nk, where rk is the kth gray level and nk is the number of pixels in the image having gray level rk.
For an 8-bit grayscale image there are 256 different possible intensities, and so the histogram will graphically display 256 numbers showing the distribution of pixels among those grayscale values.


1. Assign zero values to all elements of the array hf;
2. For all pixel (x, y) of the image f, increment hf [f(x, y)] by 1.

Tuesday, January 8, 2013

Contrast Stretching using C++ and OpenCV: Image Processing


Contrast Stretching is one of the piecewise linear function. Contrast Stretching increases the dynamic range of the grey level in the image being processed.
Points (r1, s1) and (r2, s2) control the shape of the transformation. The selection of control points depends upon the types of image and varies from one image to another image. If r1 = s1 and r2 = s2 then the transformation is linear and this doesn't affect the image. In other case we can calculate the intensity of output pixel, provided intensity of input pixel is x, as follows

Wednesday, January 2, 2013

Producing negative of a grayscale image: C++ and OpenCV

The concept behind negative of grayscale image is very simple. Just subtract each intensity level of an image from 255. The negative transformation is given by the function
                         s = L - 1 - r
Where s is the pixel after transformation, r is the pixel before transformation and L is the maximum intensity level (in our case it is 256).

The program is written in C++ using OpenCV library in QT IDE. If you are using QT IDE then add the following line of code in .pro file.

Tuesday, January 1, 2013

[Solved] Error: Cannot find -IGL / Cannot find existing library

While I was running a OpenCV project on QT, I came up with a wired error. It was like "cannot find -IGl".  I was working on Fedora 16 x86_64 system.
Later I knew that the error was due to  Shared Object (SO) Name, also called soname,  and its versoining.

When linking, the link editor (ld) can take a library as parameter via a link-library parameter (-lGL). When it goes to look the library, it simply search the file by replacing l with lib and appending .so at the end of the link-library parameter. Now the parameter becomes However, it may not find exactly and may find different versions like, etc. This is the actual reason of my problem.  Linker is looking for but I  only have