Chapter 5. Introduction to Image Processing

In today's modern science and technology areas, images and videos have gained broader scope due to the ever-growing importance of scientific visualization and digitization. In this chapter, you will get introduced to the basics of image processing. Once you have understood the basics of image processing, the image processing library, which needs to be installed on Raspberry Pi, will get introduced. Later in this chapter, we will perform basic image processing operation on Raspberry Pi followed by interesting projects creating a time-lapse video and Twitter-controlled Raspberry Pi camera. The following topics are covered in this chapter:

  • What is image processing?
  • The Raspberry Pi camera module
  • A image processing library
  • A quick start to image processing
  • Creating a time-lapse video with a Raspberry Pi camera
  • Developing a Twitter-controlled Raspberry Pi camera

What is image processing?

Of the five human senses—vision, hearing, smell, taste, and touch—vision is undoubtedly the major source of input/information to the human brain. Human eyes provide information in a range of megabits per glance. However, much of this information is redundant and several layers of visual cortex compress this information so that higher centers of the brain have to interpret only a small fraction of the input data. The ultimate goal of areas such as computer vision is to use a computer to emulate human vision, including learning and being able to take actions based on visual inputs. A computer vision can be defined as the process of deciphering the physical contents of an image/video by computer/machine. This chapter will focus on a high-level image processing, which is often referred to as computer vision.

Note

Some authors refer to computer vision as machine vision.

A computer vision is a rapidly growing field, partly as a result of both cheaper and more capable cameras, partly because of an affordable processing power, and partly because vision algorithms are starting to mature.

Today, for most of the software professionals and students, image processing has become anonymous to digital image processing in which the input is an image and the output is a processed image, which may be either modified image as per the user's requirements or parameters related to the image. So, in simple terms, image processing is a process of getting useful information from the supplied input image by analyzing/modifying the image.

Tip

A detailed study of image processing is out of the scope of this book.

Images and types of images

A digital image can be considered as a discrete representation of data possessing both spatial (layout) and intensity (color) information. When trying to recreate the physical world in a digital format via a camera, for example, the computer just sees the image in the form of a code that just contains the numbers 1 and 0. A digital image is nothing but a collection of pixels (picture elements), which are then stored in matrices or any other suitable format that will be understood by image processing library for further manipulation. In the matrices, each element contains information about a particular pixel in the image. The pixel value decides how bright or what color that pixel should be. Based on this, images can be classified images:

  • Grayscale
  • Color/RGB

Note

Pixels are the smallest constituent elements in a digital image and contain a numerical value, which is the basic unit of information within the image.

The grayscale image

In the grayscale image, the pixel value can range from 0 to 255 where 0 being black and 255 being white. As pixels in the grayscale image can vary from 0 to 255, several shades of gray color are visible in the following image:

The grayscale image

Tip

You might be wondering why 0 to 255 and why not other numbers. This is because as a starting point I have taken the example of 8-bit images. 8-bit means 2^8=256. So, here the value will vary from 0 to 255.

A special case of a grayscale image is the binary image or the black and white image where each pixel of an image can have a value of either 0 or 255. Here is a black and white image:

The grayscale image

Color/RGB

As you know, red, blue, and green are the fundamental/primary colors. Different colors can be made by different proportion of red, green, and blue. For each channel, the pixel value can be in the range of 0 to 255. Here's the color image:

Color/RGB

Image formats

From a mathematical viewpoint, any meaningful 2-D array of numbers can be considered as an image. In the real world, we need to effectively display images, store them (preferably compactly), transmit them over networks, and recognize bodies of numerical data as corresponding to images. This has led to the development of standard digital image formats. In simple terms, the image formats comprise a file header (containing information on how exactly the image data is stored) and the actual numeric pixel values themselves. There are many image formats available today. However, the most widely used image formats are shown in the following table:

Acronym

Name

Properties

GIF

Graphics Interchange Format

This is limited to only 256 colors (8-bit), lossless compression

JPEG

Joint Photographic Expert Group

This is most widely used today; lossy compression

BMP

Bit Map Picture

This is a basic image format; lossless compression

PNG

Portable Network Graphics

This is a new lossless compression format

TIF/TIFF

Tagged Image Format (File)

This is a highly flexible, detailed and adaptable format

As suggested in the Properties column of the preceding table, different image formats are suitable for different applications. Basically, different image formats came into existence because raw images (as mentioned in the previous section of Grayscale and RGB image) require more space on your machine.

Applications of image processing

The history of image processing is intimately tied to the development of the digital computer. The first computers powerful enough to carry out meaningful image processing tasks appeared in the early 1960s. The work on using computer techniques to improve images from a space probe began at the Jet Propulsion Laboratory (Pasadena, California) in 1964 when pictures of the moon transmitted by Ranger 7 were processed by a computer to correct various types of image distortion in the on-board television camera. In parallel with space applications, digital image processing techniques began in the late 1960s and early 1970s to be used in medical imaging, remote Earth resources observations, and astronomy. Today, there is almost no area of technical endeavor that is not impacted in some way by digital image processing.

As mentioned earlier, the focus of this chapter is on computer vision/machine vision. Here are the typical problems in the machine vision that utilize image processing: automatic character recognition, industrial machine vision for product assembly and inspection, military recognizance, automatic processing of fingerprints, screening of X-rays and blood samples, and machine processing of aerial and satellite imagery for weather prediction and environmental assessment. In this chapter and the next chapter, you will learn about some of the image processing techniques used in the preceding applications. However, to give you a feel of how important the image processing field has become today, here are some image processing applications categorized according to the image source:

Note

Here the image sources are categorized based on the electromagnetic spectrum: gamma rays, X-rays, ultraviolet, visible, infrared, microwaves, and radio waves.

Image source

Applications

Gamma rays

Nuclear medicine

Astronomical observation

X-rays

Medical diagnostics (angiography and computerized axial tomography (CAT) scan)

Astronomy

Ultraviolet

Lithography

Industrial inspection

Microscopy

Lasers

Biological imaging

Astronomical observations

Visible and infrared

Visual imaging

Microscopy

Astronomy

Remote sensing

Law enforcement

Microwave

Radar

Radio wave

Medicine, magnetic resonance imaging (MRI)

Astronomy

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.116.50