Friday, 5 February 2016

Digital Image processing

Digital image processing deals with manipulation of digital images through a digital computer. It is a subfield of signals and systems but focus particularly on images. DIP focuses on developing a computer system that is able to perform processing on an image. The input of that system is a digital image and the system process that image using efficient algorithms, and gives an image as an output. The most common example is Adobe Photoshop. It is one of the widely used application for processing digital images.

How it works.

Introduction Image
In the above figure, an image has been captured by a camera and has been sent to a digital system to remove all the other details, and just focus on the water drop by zooming it in such a way that the quality of the image remains the same.

Audience

This tutorial gives you the knowledge of widely used methods and procedures for interpreting digital images for image enhancement and restoration and performing operations on images such as (blurring , zooming , sharpening , edge detection , e.t.c). It also focuses on the understanding of how the human vision works. How do human eye visualize so many things , and how do brain interpret those images? The tutorial also covers some of the important concepts of signals and systems such as (Sampling , Quantization , Convolution , Frequency domain analysis e.t.c).

Prerequisites

Signals and systems

Since DIP is a subfield of signals and systems , so it would be good if you already have some knowledge about signals and systems , but it is not necessary. But you must have some basic concepts of digital electronics.

Calculus and probability

Basic understanding of calculus , probability and differential equations is also required for better understanding.

Basic programming skills

Other than this, it requires some of the basic programming skills on any of the popular languages such as C++ , Java , or MATLAB.

image quality inspection

radiologist reading scans on computer monitor

Confidence through Collaboration and Quality Data

Receiving quality images from sites is key to running successful clinical trials. From image acquisition to image analysis, the quality of the data impacts the quality of decisions made.
Our experienced in-house technologists inspect 100% of incoming images and ensure that image acquisition adheres to study protocols. VirtualScopics has the expertise to properly handle the imaging modalities required for all of our key therapeutic areas.
Our inspection team can receive images in multiple ways including courier, sFTP or third-party electronic image transfer systems. Each image is loaded onto our 21 CFR Part 11-compliant platform which provides a full audit trail of analyses performed.
Our Image Inspection department provides cross training to the entire inspection team. Cross training ensures that images are processed efficiently and within contracted timelines. Each technologist is trained to the department standard operating procedures as well as the individual project protocol and image acquisition requirements. The department manager performs monthly audits of the technologists’ work to ensure that the team is following appropriate processes and procedures.
Because our sponsors expect the best, the VirtualScopics team:
  • Adheres to industry standards, ensuring consistency throughout each study.
  • Utilizes proven metrics that recognize global challenges.
  • Delivers confidence and expertise from each imaging technologist who handles your data.

visual inspection

Visual testing (VT)

Visual Testing
Visual inspection is one of the most common and most powerful means of non-destructive testing. Visual testing requires adequate illumination of the test surface and proper eye-sight of the tester. To be most effective visual inspection does however, merit special attention because it requires training (knowledge of product and process, anticipated service conditions, acceptance criteria, record keeping, for example) and it has its own range of equipment and instrumentation. It is also a fact that all defects found by other NDT methods ultimately must be substantiated by visual inspection. VT can be classified as Direct visual testing, Remote visual testing and Translucent visual testing. The most common NDT methods MT and PT are indeed simply scientific ways of enhancing the indication to make it more visible. Often the equipment needed is simple for internal inspection, light lens systems such as bore scopes allow remote surfaces to be examined. More sophisticated devices of this nature using fibre optics permit the introduction of the device into very small access holes and channels. Most of these systems provide for the attachment of a camera to permit permanent recording.
Trinity NDT material testing facility contains light meters, welding gauges, magnifiers, lenses, other measuring instruments and equipments for precise control of surface quality. Our NDT inspectors, engineers and technicians are qualified to NDT Level I, II as per written practice prepared according to ASNT recommended practice SNT-TC-1A and in-house ASNT NDT Level IIIs for providing inspection and consulting services.

Histogram equalization












Histogram Equalization of Grayscale or Color Image

Histogram

Histogram is the intensity distribution of an image.

E.G -
Consider the following image. Say, depth of the image is 2 bits. Therefore the value range for each and every pixel is from 0 to 3.
Sample Image (Depth = 2 bits)
Sample Image (Depth = 2 bits)

Histogram of the a image shows how the pixel values are distributed. As you can see in the above image there are 5 pixels with value 0, 7 pixels with value 1, 9 pixels with value 2 and 4 pixels with value 3. These information is tabulated as follows.
Intensity Distribution of above image
Intensity Distribution of above image

Histogram of a image usually presented as a graph. The following graph represents the histogram of the above image.

Image Histogram
Image Histogram


Histogram Equalization

Histogram Equalization is defined as equalizing the intensity distribution of an image or flattening the intensity distribution curve. Histogram equalization is used to improve the contrast of an image. The equalized histogram of the above image should be ideally like the following graph.
Equalized Histogram
Equalized Histogram

But practically, you cannot achieve this kind of perfect histogram equalization. But there are various techniques to achieve histogram equalization close to the perfect one. In OpenCV, there is an in-built OpenCV function to equalize histogram.



Histogram Equalization of Grayscale image

Here is the sample program demonstrating how to equalize the histogram of a grayscale image (black and white image) using a OpenCV in-built function.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


#include "opencv2/highgui/highgui.hpp"

#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>




using namespace cv;

using namespace std;




int main( int argc, const char** argv )

{

Mat img = imread("MyPic.JPG", CV_LOAD_IMAGE_COLOR); //open and read the image




if (img.empty())

{

cout << "Image cannot be loaded..!!" << endl;

return -1;

}



cvtColor(img, img, CV_BGR2GRAY); //change the color image to grayscale image




Mat img_hist_equalized;

equalizeHist(img, img_hist_equalized); //equalize the histogram




//create windows

namedWindow("Original Image", CV_WINDOW_AUTOSIZE);

namedWindow("Histogram Equalized", CV_WINDOW_AUTOSIZE);




//show the image

imshow("Original Image", img);

imshow("Histogram Equalized", img_hist_equalized);




waitKey(0); //wait for key press




destroyAllWindows(); //destroy all open windows




return 0;

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


You can download this OpenCV visual c++ project from here(The downloaded file is a compressed .rar folder. So, you have to extract it using Winrar or other suitable software)




Original Image
Original Image

Image with Equalized Histogram
Image with Equalized Histogram

New OpenCV functions

  • void cvtColor( InputArray src, OutputArray dst, int code, int dstCn=0 )
This function converts image from one color space to another color space. 
OpenCV usually loads an image in BGR color space. In the above example, I want to change the image to grayscale color space. So, I use the  CV_BGR2GRAY as the 3rd parameter. If you want to convert to HSV color space, you should use CV_BGR2HSV.

This is an explanation of each parameters of the above function.

  • InputArray src- Input image ( it should be 8 bit unsigned or 16 bit unsigned or 32 bit floating point image)
  • OutputArray dst - Output image ( It should have a same size and depth as the source image )
  • int code- Should specify the color space conversion. There are many codes available. Here are some of them.
    • CV_BGR2HSV
    • CV_HSV2BGR
    • CV_RGB2HLS
    • CV_HLS2RGB
    • CV_BGR2GRAY
    • CV_GRAY2BGR
  • int dstCn - Number of channels in the destination image. If it is 0, number of channels of the destination image  is automatically derived from source image and color space conversion code. For a beginner, it is recommended to use 0 for this parameter. 

  • void equalizeHist( InputArray src, OutputArray dst )
This function equalizes the histogram of a single channel image ( Grayscale image is a single channel image )
By equalizing the histogram, the brightness is normalized. As a result, the contrast is improved.

Here is the description of each parameters of the above OpenCV function.
  • InputArray src - 8 bit single channel image
  • OutputArray dst - Destination image of which histogram is equalized ( It should have the same size and depth as the source image. )

Histogram Equalization of Color image

In the above example, I have shown how to equalize the histogram of a grayscale image. Now I am going to show you how to equalize histogram of a color image using sample OpenCV program.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, const char** argv )
{
Mat img = imread("MyPic.JPG", CV_LOAD_IMAGE_COLOR); //open and read the image

if (img.empty()) //if unsuccessful, exit the program
{
cout << "Image cannot be loaded..!!" << endl;
return -1;
}

vector<Mat> channels; 
Mat img_hist_equalized;

cvtColor(img, img_hist_equalized, CV_BGR2YCrCb); //change the color image from BGR to YCrCb format

       split(img_hist_equalized,channels); //split the image into channels

       equalizeHist(channels[0], channels[0]); //equalize histogram on the 1st channel (Y)

   merge(channels,img_hist_equalized); //merge 3 channels including the modified 1st channel into one image

      cvtColor(img_hist_equalized, img_hist_equalized, CV_YCrCb2BGR); //change the color image from YCrCb to BGR format (to display image properly)

//create windows
namedWindow("Original Image", CV_WINDOW_AUTOSIZE);
namedWindow("Histogram Equalized", CV_WINDOW_AUTOSIZE);

//show the image
imshow("Original Image", img);
imshow("Histogram Equalized", img_hist_equalized);

waitKey(0); //wait for key press

destroyAllWindows(); //destroy all open windows

return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
You can download this OpenCV visual c++ project from here(The downloaded file is a compressed .rar folder. So, you have to extract it using Winrar or other suitable software)


Original Color Image
Original Color Image



Color Image with Equalized Histogram
Color Image with Equalized Histogram


New OpenCV functions



  • cvtColor(img, img_hist_equalized, CV_BGR2YCrCb)
This line converts the color space of BGR in 'img' to YCrCb color space and stores the resulting image in 'img_hist_equalized'.

In the above example, I am going to equalize the histogram of color images. In this scenario, I have to equalize the histogram of the intensity component only, not the color components. So, BGR format cannot be used because its all three planes represent color components blue, green and red. So, I have to convert the original BGR color space to YCrCb color space because its 1st plane represents the intensity of the image where as other planes represent the color components.  

  • void split(const Mat& m, vector<Mat>& mv )
This function splits each channel of the 'm' multi-channel array into separate channels and stores them in a vector, referenced by 'mv'.

Argument list
  • const Mat& m - Input multi-channel array
  •  vector<Mat>& mv - vector that stores the each channel of the input array

  • equalizeHist(channels[0], channels[0]);
Here we are only interested in the 1st channel (Y) because it  represents the intensity information whereas other two channels (Cr and Cb) represent color components. So, we equalize the histogram of the 1st channel using OpenCV in-built function, 'equalizeHist(..)' and other two channels remain unchanged.

  • void merge(const vector<Mat>& mv, OutputArray dst )
This function does the reverse operation of the split function. It takes the vector of channels and create a single multi-channel array.
Argument list
  • const vector<Mat>& mv - vector that holds several channels. All channels should have same size and same depths
  • OutputArray dst - stores the destination multi-channel array

  • cvtColor(img_hist_equalized, img_hist_equalized, CV_YCrCb2BGR)
This line converts the image from YCrCb color space to BGR color space. It is essential to convert to BGR color space because 'imshow(..)' OpenCV function can only show images with that color space. 

This is the end of the explanation of new OpenCV functions, found in the above sample code. If you are not familiar with other OpenCV functions, please refer to the previous lessons.

Next Lesson: Smooth / Blur Images



Image processing using open CV

What is OpenCV?


OpenCV is an open source C++ library for image processing and computer vision, originally developed by Intel and now supported by Willow Garage. 
It is free for both commercial and non-commercial use. Therefore it is not mandatory for your OpenCV applications to be open or free.
It is a library of many inbuilt functions mainly aimed at real time image processing. Now it has several hundreds of image processing and computer vision algorithms which make developing advanced computer vision applications easy and efficient.
If you are having any troubles with installing OpenCV or configure your Visual Studio IDE for OpenCV, please refer to Installing and Configuring with Visual Studio.

Key Features
  • Optimized for real time image processing & computer vision applications
  • Primary interface of OpenCV is in C++
  • There are also C, Python and JAVA full interfaces
  • OpenCV applications run on Windows, Android, Linux, Mac and iOS
  • Optimized for Intel processors

OpenCV Modules

OpenCV has a modular structure. The main modules of OpenCV are listed below. I have provided some links which are pointing to some example lessons under each module.
  •  core                  
This is the basic module of OpenCV. It includes basic data structures (e.g.- Mat data structure) and basic image processing functions. This module is also extensively used by other modules like highgui, etc.

  • highgui
This module provides simple user interface capabilities, several image and video codecs, image and video capturing capabilities, manipulating image windows, handling track bars and mouse events  and etc. If you want more advanced UI capabilities, you have to use UI frameworks like Qt, WinForms, etc.

  • imgproc
This module includes basic image processing algorithms including image filtering, image transformations, color space conversions and etc.

  •  video
This is a video analysis module which includes object tracking algorithms, background subtraction algorithms and etc.
  • objdetect
This includes object detection and recognition algorithms for standard objects. 


OpenCV is now extensively used for developing advanced image processing and computer vision applications. It has been a tool for students, engineers and researchers in every nook and corner of the world.