Sunteți pe pagina 1din 10

3.

IMAGE PROCESSING TOOLBOX

Image Processing Toolbox is a set of functions and


algorithms for image processing operation, analysis and visualization.
Image Processing Toolbox supports a diverse set of image processing
operation such as: Image analysis and enhancement, linear filtering
and filter design, neighbourhood and block operation, spatial image
transformation etc. In this chapter, basic IPT functions are
introduced along with some examples and their results to have a
better understanding of the topic.

As earlier mentioned that a digital image f(x,y) in MATLAB can be


represented as a MxN matrix where x ranges from 0 to M-1 and y
ranges from 0 to N-1 as origin is taken as (0,0). But, here, the IPT
uses a slightly different coordinate convention to represent the
array. First, instead of using (x,y), the toolbox use (r,c) to represent
rows and columns. Secondly, the origin of coordinates system is at
(r,c) = (1,1). Thus r ranges from 1 to M and c ranges from 1 to N.

3.1 BASIC IPT FUNCTIONS:


3.1.1 READING IMAGES
Images are read into the
MATLAB environment using function imread, whose syntax is
> imread(filename)
here, filename is a string containing the complete name of the
image file including any applicable extension. To read an image
whose location is outside the current directory, we have to mention
the complete URL of that image.
For Example- If our image is located at the desktop(say) then,
we can write the following syntax to read that image file:

>> f= imread('C:\Users\Bhavya\Desktop\index.jpeg');

3.1.2 whos function


The whos function displays the additional information
about an array.

Example-

>> whos f

RESULT-

Name Size Bytes Class Attributes

f 194x259x3 150738 uint8

3.1.3 Displaying Images

Images are displayed at MATLAB desktop using the finction


imshow which has the basic syntax-
imshow(f)

RESULT-

3.1.4 Writing Images


Images are written to disk using the function imwrite which has the
following basic syntax

imwrite(filename)
with this syntax, the string contained in filename must include
recognized file format extension. Alternatively, we can assign
another file format extension explicitly according to our need.

EXAMPLE-

>> imwrite(f, 'C:\Users\Bhavya\Desktop\test2.jpg)

A more general syntax that can be used only for JPEG/JPG format
images-

Imwrite(f, 'C:\Users\Bhavya\Desktop\test2.jpg,quality,q)

Where q is an integer between 0 to 100 (the lower the number


higher will be the degradation to the image compression). The size of
the image file reduce depending on the value of q.

3.2 DATA CLASSES

Although we work with integer coordinates, the values of the pixels


themselves are not restricted to be integers in MATLAB. The various
data types that are supported by MATLAB are listed in the table 3.1
3.3 IMAGE TYPES

IMAGE TYPE INTERPRETATION


Binary Logical array containing only 0s
(Also known as a bilevel image) and 1s, interpreted as black and
white, respectively.
Indexed Array of class logical, uint8,
(Also known as a pseudocolor uint16, single, or double whose
image) pixel values are direct indices into
a colormap. The colormap is an
m-by-3 array of class double. For
single or double arrays, integer
values range from [1, p]. For
logical, uint8, or uint16 arrays,
values range from [0, p-1].

Grayscale Array of class uint8, uint16,


(Also known as an intensity, gray int16, single, or double whose
scale, or gray level image) pixel values specify intensity
values.

For single or double arrays,


values range from [0, 1]. For
uint8, values range from [0,255].
For uint16, values range from [0,
65535]. For int16, values range
from [-32768, 32767]
Truecolor m-by-n-by-3 array of class uint8,
(Also known as an RGB image ) uint16, single, or double whose
pixel values specify intensity
values.
For single or double arrays,
values range from [0, 1]. For
uint8, values range from [0, 255].
For uint16, values range from [0,
65535]

An image is characyerized by both its class and types. For


instance, a statement discussing an uint8 intensity image is
simply referring to an intensity image whose pixels are of data
class uint8.
The important point to be noted is that pixels in binary image
can only be of data class logical.

3.4 CONVERTING BETWEEN DATA CLASSES AND TYPES -


This operation are frequent in IPT application. When converting
between data classes, it is important to keep in mind the value
ranges for each data class. Coverting between data classes has
following general syntax:
B= data_class_name(A)

Where data_class_name is one of the names from the following-


double,uint8, uint16, int8 , int16, int32, single, char, logical.

As stated earlier that ranges of the data types have to be kept in


mind while performing the data type conversion because after
conversion pixel value changes according to the range of the data
type in which it is being converted. This can be understood by
studying the following case:

Suppose that A is an array of class double and some of its value lie
outside the range [0, 255]. Now , if we convert the data type into
uint8 class, then, MATLAB converts pixels value to 0 for all values
less than zero , and converts it to 255 for all values greater than 255.

FOR EXAMPLE

f=

-0.5 0.5
0.75 1.5

g = im2uint8(f)

After performing conversion, we get a matrix g

g=

0 128
191 255

The summarized table for conversion is given below-

3.4 IMPROVING IMAGE CONTRAST USING HISTOGRAM


EQUALIZATION
An image histogram is a graphical representation of the tonal
distribution of an image. It plots the number of pixels for each tonal
value. The horizontal axis of the graph represent the tonal variations,
while the vertical axis represent the number of pixel in that
particular tone. The left side of the horizontal axis represent the
black and dark areas, the middle represents medium grey and the
right hand side represents the light and pure white areas.

The histogram for the above can be plotted from the following
syntax:

Imhist(f)
Now, we can observe the from the histogram that the tonal
distribution is concentrated to the left hand side which represent the
dark and grey areas which is evident from the given photo.

The image contrast of the given image can be improve using


histogram equalization in which tonal distribution is spread over the
full range horizontal axis. This equalization is achieved using histeq
function.

I = histeq(f);
>> imhist(I)

S-ar putea să vă placă și