Uploaded by Khaled Gawad

LAB Tut1

advertisement
LAB Tut1
Digital Image Processing in Matlab
An image is a single picture that represents something. It may be a picture of a
person, or animal, or an outdoor scene, or microphotograph (‫ (صورة ضوئية‬of an electronic
component, or the result of medical imaging. An image can be defined as a twodimensional function, f(x,y) where x and y are spatial (plane) coordinates , and the
amplitude of f at any pair of coordinates (x,y) is called the intensity or gray level of the
image at that point. A digital image differs from a photo in that the x,y, and f(x,y) values
are all discrete, often integers.
Often image processing involves changing the nature of an image in order to
either:
1- improves its pictorial (‫ ) تصويريه‬information for human interpretation, or
2- render it more suitable for autonomous (‫ ) ذاتى‬machine perception.
The field of digital image processing refers to processing digital images by means of
a digital computer.
Applications:
1- Medicine (x-ray, CAT (Computerized Axial Tomography))
2- Agriculture (Satellite views of land)
3- Industry (automatic inspection of items on production line)
4- Law enforcement (fingerprint analysis)
Aspects of image processing:
1- Image Enhancement (Sharpening, improving contrast, removing noise)
2- Image restoration (removing of blur)
3- Image segmentation (finding particular shapes in an image)
Fundamental Steps in Digital Image Processing:
1- Image acquisition: can be done using camera or a scanner.
2- Image enhancement: to highlight certain features of interest in an image.
3- Image restoration: improving the appearance of an image unlike enhancement
4- Wavelets: the foundation for representing images in various degrees of resolution.
5- Compression: reducing the storage required to save an image or the bandwidth to
transmit it.
6- Segmentation: partitioning an image into its constituent parts or objects and is one
of the difficult tasks in digital image processing.
7- Representation and description: almost always follow the output of a segmentation
stage and it is converting the data to a form suitable for computer processing,
description is also called feature selection, deals with extracting attributes that
result in some quantitative information of interest or are basic for differentiating
one class of objects from another.
8- Recognition: is the process that assigns a label to an object based on its
descriptors.
Types of digital images:
1- Binary: each pixel is just black or white so we need only one bit per pixel and may
be suitable for text, fingerprints, and architectural plans.
2- Gray scale: each pixel is a shade of gray, normally from 0 (black) to 255 (white).
This range means that each pixel can be represented by 8 bits.
3- True color or RGB: each pixel has an amount of red, green, and blue colors. Each
color is represented by 8 bits so the total number of bits is 24 for each pixel. Each
image may has 2553=16,777,216 different possible color.
4- Indexed: most color images have only a small subset of the more than 16 million
possible colors. For convenience of storage and file handling the image has an
associated color map, or color palette, which is a list of all colors used in that
image. Each pixel has a value that does not give its color but an index to the color
in the map.
Consider a 512 x 512 binary image so its size will be
512 x 512 x 1= 262,144 bits
=
kb
a gray scale image of the same size will be
512 x 512 x 1 = 262,144 bytes
=
kb
a color image of the same size will be
512 x 512 x 3 = 262,144 bytes
=
kb
Image display
>> c=imread ('cameraman.tif');
>> imshow (c)
To show the size of an image matrix
>> size (c)
>> [M N]= size ( c) ;
>>M=size (c , 1);
>>N=size(c,2);
In RGB images
>> size (a) where a is a matrix image
returns three values: the number of rows, columns, and "pages" of image a, which is a
three-dimensional matrix.
To display more than one image we use
>> imshow(g), figure, inshow(c)
Figure used here to open a second figure for the second image while the first one is
showed in figure 1.
>> Bw=imread (‘flowers.tif’);
>> whos Bw
Name
Bw
Size
362x500x3
Bytes Class
543000 uint8 array
Grand total is 543000 elements using 543000 bytes
To show images of low dynamic range or that have positive and negative values
>> imshow(g, [ ] );
Writing an image into disk (saving it into the working directory of matlab)
>>imwrite (g, ‘filename.ext’)
Or
>> imwrite (g, ‘filename’ , ‘ ext’)
>>imwrite (g, ‘flowers.png’)
To write the image into specified path
>>imwrite(g, ‘d:\flowers.tif’)
Another form for imwrite used with JPEG images
>>imwrite (g, ‘filename.ext’ , ‘quality’, q) where q is a number between 0 and 100
indicates the compression level.
>> imwrite(g, ‘flowers’, ‘quality’, 25)
To know the effect of this on the image you can show the image and also use
Imfinfo command to see what happened to the image characteristics.
Using of high compression level (means small q) leads to false contouring problem which
causes image appearance distortion.
To find maximum pixel value in an image
>>m = max(b)
treats the columns of image b as vectors and returns a row vector of largest elements.
m is a row vector containing the maximum value of each column.
>>m
= max(b,[],dim) returns the largest elements along dimension dim.
>>m=max(b,[],2)
m is a column vector containing the maximum value of each row.
Finding the minimum pixel value is the same using min command
>>n=min(b)
>>n=min(b,[],2)
So to find the maximum and minimum pixel value in an image matrix
>>m = max(max(c));
>>n=min(min(c));
>> imfinfo (‘cameraman.tif’)
The information returned by imfinfo depends on the file format, but it always includes at least
the following:

Name of the file

File format

Version number of the file format

File modification date

File size in bytes

Image width in pixels

Image height in pixels

Number of bits per pixel

Image type: truecolor (RGB), grayscale (intensity), or indexed
Exercises:
1- Consider the image cameraman.tif :
a. Determine its type (binary , graysacle, true color, indexed)
b. Determine its size in pixels
c. Determine its data class type.
2-Write the image in Q.1 into file of types JPEG, PNG, and BMP. What is the size
of those files?
3-Find the max and min pixel values in the image cameraman.tif exists in
the built-in demo images of Matlab toolbox.
Download