The blog is about step by step procedure to install docker in Ubuntu 16.04 and use the docker by running Jupyter notebook with deep learning libraries.

Step 1: Update the system and install the docker dependencies.

Step 7 Verify that docker is installed by running docker hello world container

sudo docker run hello-world

If you get the hello-world Docker installation is completed.

Lets use the docker by pulling the Docker image. I am using all in one deep learning docker image of docker hub to show how to use docker. Image have tensorflow , keras , caffe , opencv and others deep leaning library. Below is the link of docker hub for all in one deep learning docker image you can check the details of image.

Above command – p is for port forwarding from docker to system and – v is share a folder from system to docker you need to edit path . I am sharing cv_basics folder to docker with name my_folder. You can give any name while sharing.

The post is about to install the latest Nvidia driver and Cuda 10.1 on Ubuntu 16.04 LTS. Recently due to some problem in Ubuntu or Nvidia after updating the Ubuntu I cant login to my system. This is happening due to installed nvidia driver so if you face the same problem follow the below steps first

In login Ubuntu screen press ctrl + alt +f1 to get the console access.

Remove nvidia driver by sudo apt purge nvidia * (if installed by deb package) or sudo nvidia-uninstall (for local run package).

Restart system by ( sudo shutdown -r now )

Now you can login to ubuntu system

Follow the below steps to install latest nvidia driver and cuda 10.1 driver.

Cuda driver have dependency of Nvidia driver so first we will install Nvidia driver.

Allow permission of downloaded nvidia driver file with chmod command

sudo chmod +x cuda_10.0.130_410.48_linux.run

Create a new folder name nvidia_drivers and extract the cuda run files in this folder.

mkdir nvidia_drivers

./path to cuda_10.0.130_410.48_linux.run –extract=path to nvidia_drivers folder we created above/

For cuda 10.1 run file you will get NVIDIA-Linux-x86_64-418.39.run with some other folder like cuda-toolkit , cuda sample for cuda10 run file you will get three files as shown below. For both cases we just want to install the nvidia linux file for nvidia driver.

Install the Nvidia Driver with below command

sudo ./NVIDIA-Linux-x86_64-410.48.run –no-x-check

Restart the system and check the nvidia driver installation

nvidia-smi

We installed the nvidia driver 410 in system now we will install cuda driver.

Install the cuda 10.1 with below command press d, accept the EULA licensce. After successful installation restart system.

sudo ./cuda-linux.10.0.130-24817639.run

Might be you will get the message that cuda installed with error it is Ok . Just restart your system and add the cuda path to your .bashrc file. Below are the steps

Add the cuda bin and library path to .bashrc file. Open .bashrc file (sudo gedit ~/.bashrc) and add the following two lines at end make sure to use your own Cuda version i am using 10.1 and in screen shot I used cuda 10.

Tutorial to discuss steps on how to install Anaconda 5.3 and configure OpenCv3.2 in Anaconda 5.3 for python 3.6.

After completing these steps I am sure you can use anaconda/Python3 and OpenCv 3.2.

Introduction

In office I was assigned a simple work in image processing which required extra modules of OpenCv in Python. It was simple task but I struggled a lot to configure python with opencv modules 😦 . After wasting my weekends I completed the task on time and came to know how easy it was 🙂 .

For Ubuntu 16.04 LTS (almost similar steps for Window 7).

1]. Download the Anaconda according to your system configuration from below link.

If we calculate the eigen value and eigen vector of data; eigen vector represent which basis direction data is spread and eigen value informs which basis direction (eigen vector ) have more information about data.

Basics of Eigen values and Eigen vectors :

Suppose A is matrix with size N x N.

V is vector with size N.

V is called the eigen vector of A.

A V = λ V ……. (i)

if multiplication of A scale the vector V .

In equation (i) λ is called the eigen value of matrix.

Function eig is used in MATLAB to get the eigen vector and eigen value.

suppose

[ V, D] = eig (A)

where D is diagonal matrix contain the eigen values and V is columns corresponding eigen vector then

AV = VD …..(2)

form equation 1

λ I – A = 0 called the root of polynomial

where λ is diagonal eigenvalues, I is identity matrix and A is given input matrix.

Determinant of matrix A (|A|) will be product of all eigen values.

Set of eigen vector is called the spectrum of matrix.

Symmetric matrix :

If transpose of matrix does not change the matrix its called symmetric matrix.

S = S T

where ST is transpose of S matrix.

One of the example of symmetric matrix is co-variance matrix.

The property of symmetric matrix is that if we calculate eigen values and eigen vectors, all eigen values will be real.

Eigen Value Decomposition:

if V1 and V2 correspond to eigen values λ 1 and λ2 , if λ1 is not equal to λ2 then vector V1 and V2 will be orthogonal.

Lets take eigen vectors V = ( V1 , V2 , V3 ….) (orthogonal matrix)

if V*VT is zero we can say columns are orthogonal

and if Λ = ( λ 1, λ 2, λ 3….) diagonal eigen values.

we can write

S = V Λ VT ……. (3)

where VT is transpose of V

equation 3 is called the eigen value decomposition.

Lets write the code of eigen value decomposition in MATLAB.

To make sense of Eigen value decomposition input matrix should be symmetry matrix so eigen value will be real. Will calculate co variance matrix which is symmetry matrix.

%%%%%%%%%%%%%%%%%%%%%%%%% Code end %%%%%%%%%%%%%%%%%%%

Results:

Input image

Symmetric or Covariance input image generated by Lena image:

Covariance image reconstruction by top 5 eigen values and corresponding vectors:

Loss of information because we used only top 5 eigen vector = 27.84 percentage

Top 5 eigen vectors contain 72.16 percentage information of input image

Covariance image reconstruction by 1 eigen vector:

Loss of information = 72.40 percentage

Top 1 eigen vector contain 27.8 percentage information of input image

Applications:

Eigen value docomposition is the basic of Sigular value decomposition and Principal Component Analaysis with the help of PCA we can able to reconstruct our original lena image which we will discuss in futher post.

GLCM (gray level co-occurrence matrix) is mainly useful to perform the texture analysis and find the features from image.

As name suggested its work on gray image and try to create sort of 2 d histogram from image.

Main application of GLCM are texture analysis, feature extraction and segmentation.

Steps to Calculate GLCM matrix :

Lets assume image I which is gray image.

Initialize GLCM matrix size 256 x 256 (256 is level of GLCM).

Suppose we use zero angle of GLCM means direction of GLCM is horizontal.

Suppose distance of GLCM is 1, means we just look horizontally next pixel to current pixel.

In image I(i,j) get the gray value (suppose value of pixel is a = 127 at I(i,j)), and get gray value I(i,j+1) in case of distance 1 and zero degree of GLCM (suppose value of pixel is b = 58 at I(i,j+1)).

Go to GLCM matrix co-ordinate (a = 127, b=58) and increment the value by 1.

Iterate the full image that will give us GLCM matrix of zero degree for distance 1.

According to texture type, GLCM distance can be decided.

For road because texture changes so rapidly we consider the small distance to calculate GLCM but for bricks, distance of the GLCM matrix should be large.

Angle of GLCM should be selected according to direction of image texture changes, so in brick image we want to consider 2 direction 0 degree and 90 degree.

Calculate features from GLCM matrix, there are many features are available to perform the texture analysis like contrast, correlation, energy , and homogeneity etc.

We will get the contrast feature from GLCM matrix which are sufficient to say weather texture is rough or smooth.

Lets write basic GLCM code which calculate the zero degree GLCM for 256 level and get contrast feature.

%%%%%%%%%%%%%%%%%%%%%%%%%Code Start here %%%%%%%%%%%%%%%

%%%%% GLCM function start here %%%%%%%%%%%%%

function GLCM_0 = getGLCM0(img_gray, distance) %% function calculate the GLCM matrix at zero degree angle and given distance %% GLCM_0 is GLCM matrix for 0 degree angle. %% img_gray is input gray image %% distance is distance of GLCM calculated

Lest take two input image first is road texture and second is brick image apply the GLCM and get the contrast feature.

Result:

Contrast feature of figure. 2 road texture is 3.9489e+03

Contrast feature of figure.3 Brick texture is 91.0206

As from result we can say that road texture have so much texture because of that its contrast value is so much high if less texture will be present in image contrast value will be low.

So for smooth area in image contrast will be low, for rough area contrast will be high.

* Note: GLCM value depend on the size of image we are performing the GLCM so size of image should be fix or normalize.

For more information about GLCM feature analysis please go through the paper harlick texture features .

%%%%%%%%%%%% Code End %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Following are the main 2 D project transform :

Euclidean Transform

Similarity Transform

Affine Transform

Projective Transform

Euclidean Transform :

Let define transformation matrix for Euclidean transform

T = [ R11 R12 Tx ; R21 R22 Ty ; 0 0 1]

Where R11 , R12, R21 and R22 are rotation matrix and Tx and Ty are translation. So it have have 3 degree of freedom 1 in rotation and 2 in translation.

lets take 30 degree rotation angle and -100 pixel translation in both direction

Result of Euclidean Transform

Euclidean Transform dont have property to scale the images.

Similarity Transform:

Let define transformation matrix for Similarity transform

T = [ s*R11 s*R12 Tx ; s* R21 s*R22 Ty ; 0 0 1]

It have 4 degree of freedom.

if in Euclidean transform we added the feature of scale (s) its become similarity tranform

lets take 40 degree rotation angle and -100 pixel translation in both direction and 1.5 scaling factor

Affine Transform :

Let define transformation matrix for Affine transform

T = [ a11 a12 Tx ; a21 a22 Ty ; 0 0 1]

In Similarity transform if we can able to take different angle as well as different scale it will become affine transform.

lets take 40 degree rotation angle in x direction and 30 degree rotation angle in y direction , -100 pixel translation in both direction, 0.7 scaling factor in x direction and 1.5 scaling factor in y direction.

Projective Transform :

Define the transformation full matrix which include the homogeneous factor as well.

T = [h11 h12 h13 ; h21 h22 h23 ; h31 h32 h33]

Projective transform have 8 degree of freedom because we added 2 coefficient h31 h32 in affine transform matrix which take care of image homogeneous co-ordinate geometry. (might be in furure calibration post i will discuss it about in detail)

In this post, I will discuss the Haar wavelet analysis (wavelet transform) in image processing.

Applications of Haar wavelet transform in image processing are Feature extraction, Texture analysis, Image compression etc.

Wavelet is time frequency resolutions analysis.

As shown in above figure.1 its have the information of different time frequencies of signal.

Its like applying a comb of filters bands in signal they are called levels. First we apply full frequency band and have no knowledge of time.

Apply filter which have half bandwidth of signal lose some frequency information but have some knowledge of time resolution called first level decomposition.

Further reduce the filter bandwidth will be second level decomposition.

Haar wavelet is made of two filters one is low pass filter and second high pass filter.

Coefficients of Low pass filter = [0.707, 0.707]

Coefficients of High pass filter = [-0.707, 0.707]

Figure .3 shows the block diagram of first level decomposition.

I is image of size m , n. We take the image column vectors (1d) and apply the low pass filter and high pass filter.

Down sample the output and reshape the image I1 of size m, n/2 (size is n/2 because we down sampled the columns by 2).

Apply low and high pass filter in row wise in image I1 again down sample the output and reshape the image (m/2,n/2).

Figure. 5 shows the result of haar wavelet decomposition results at first level.

LL filter output will proceeds for next level decomposition. As its contains most information of input image and looks almost same at down sampled resolution.

HH, LH and HL will have texture information in vertical, horizontal and ramp directions. HH, LH and HL are called haar features.

We can further decompose the LL image into LL1, LH1, HL1 and HH1 images.

MATLAB provide Wavelet Toolbox GUI to perform the wavelet analysis.

%% function haar_wave calculate the haar wave decomposition of given imput image %% Image in :- input gray level image %% LL :- Low Low band output image %% LH :- Low High band output image %% HL :- High Low band output image %% HH :- High High band output image

%% apply low pass filter in one d image column wise image
image_low_pass_1D = filter(filter_L,1,image_vector);
image_high_pass_1D = filter(filter_H,1,image_vector);

% Down sample the image low and high pass image.
temp = 1;
Dimage_low_pass_1D = 0;
Dimage_high_pass_1D = 0;

for i = 1:2:length(image_low_pass_1D)
Dimage_low_pass_1D(temp) = image_low_pass_1D(i);
Dimage_high_pass_1D(temp) = image_high_pass_1D(i);
temp = temp+1;
end

%% reshape the image in 2 D, size will be row/2 , col
Dimage_low_pass = reshape(Dimage_low_pass_1D,round(row/2), col)’;
Dimage_high_pass = reshape(Dimage_high_pass_1D, round(row/2),col)’;

%% conver the image in 1 D but in column vector, I transpose Dimage_low_paas image above.