You are on page 1of 38

Digital image processing

Contents
Digital image representation Reading images Displaying images Writing images Data classes Image types Converting between data classes and image type

Digital image representation

An image may be defined as a two-dimensional function, f(x, y), where x and y are spatial coordinates, and f is the intensity of the image at (x, y) point

Digital image representation

in books

matlab toolbox

Digital image representation


A digital image can be represented as a MATLAB matrix:

Reading Images
Imread(filename)
Some examples: f=imread(chestxray.jpg); f=imread(D:\myimages\chestxray.jpg); f=imread(.\myimages\chestxray.jpg);

Reading Images
MATLAB can import/export several image formats
BMP (Microsoft Windows Bitmap) GIF (Graphics Interchange Files) HDF (Hierarchical Data Format) JPEG (Joint Photographic Experts Group) PCX (Paintbrush) PNG (Portable Network Graphics) TIFF (Tagged Image File Format) XWD (X Window Dump) MATLAB can also load raw-data or other types of image data

Hint: GIF is supported by imread but not with imwrite

Reading Images
>> size(f) ans =
494 600 >> [M,N]=size(f); >> whos f Name Size f 494x600

Bytes 296400

Class uint8 array

Displaying images
imshow(f,G)
Where G is the number of intensity levels used to display it

imshow(f) :

G=256 as default

imshow(f, [low high]) displays as black all values less than or equal to low, and as white all values greater than or equal to high. try pixval function??????????

Displaying images
imshow(f, [ ]): sets variable low to the minimum value of array f and high to its maximum value. Useful for displaying images that have a low dynamic range

imshow(f)

imshow(f, [ ])

Writing images
imwrite(f, filename) imwrite(f, patient10_run1, tif) Hint: >> imfinfo (filename)

Writing images
ans =

Filename: bubbles25.jpg FileModDate: 02-Feb-2005 09:34:50 FileSize: 13354 Format: jpg FormatVersion: Width: 720 Height: 688 BitDepth: 8 ColorType: grayscale FormatSignature: NumberOfSamples: 1 CodingMethod: Huffman CodingProcess: Sequential Comment: {}

Data classes

Image types
The tool box support four types of images: Intensity images Binary images Indexed images RGB images

Image types
Intensity image (gray scale image)
An intensity image is a data matrix whose values have been scaled to represent intensities. When the elements of an intensity image are of class uint8, or class uint16, they have integer values in the range [0,255] and [0,65535], respectively. If the image is of class double, the values are floating-point numbers

Image types

This figure depicts a grayscale image of class double

Image types
Binary image A binary image is a logical array of 0s and 1s.

Image types
RGB image (true colour image) A truecolor image is an image in which each pixel is specified by three values one each for the red, blue, and green components of the pixels color. MATLAB store truecolor images as an m-by-n-by-3 data array that defines red, green, and blue color components for each individual pixel. m-by-n-by-3 array of class uint8, uint16, single, or double whose pixel values specify intensity values.

Image types

Image types
RGB=imread(mti.jpg);

Image types
Indexed image An indexed image consists of an array and a colormap matrix. The pixel values in the array are direct indices into a colormap.

The colormap matrix is an m-by-3 array of class double containing floating-point values in the range [0,1]. Each row of map specifies the red, green, and blue components of a single color. An indexed image uses direct mapping of pixel values to colormap values.

Image types

Converting between data classes and image types


Image types

[X,map] = gray2ind(I,n)
-n specifies the size of the colormap ( default=64)

Example: Convert a grayscale image into an indexed image and then view the result.
I = imread('cameraman.tif'); [X, map] = gray2ind(I, 16); imshow(X, map);

Converting between data classes and image types

Converting between data classes and image types


Image classes

Losing Information in Conversions When you convert to a class that uses fewer bits to represent numbers, you generally lose some of the information in your image. For example a uint16 grayscale image is capable of storing up to 65,536 distinct shades of gray, but a uint8 grayscale image can store only 256 distinct shades of gray.

Example
F=imread(rose.tif);

fp= f (end:-1:1,:) Imshow(fp)

- Repeat from left to right

fs=f(1:8:end,1:8:end) Imshow(fs)

fc=f(257:768, 257:768) Imshow(fc)

Image Arithmetic Operation

Hint MAX , Min function

OTHER USEFUL FUNCTIONS

Examples
>> A=[1 2 3;4 5 6]; >> B=[0 -1 1;0 0 1]; >> xor(A,B) ans = 1 0 0 110 >> all(A) ans = 1 1 1 >> any(A) ans = 1 1 1 >> any(B) ans = 0 1 1

>> A=[1 2 0;0 4 5]; >> B=[1 -2 3;0 1 1]; >> A&B ans = 1 1 0 011 >> A|B ans = 1 1 1 011 >> ~B ans = 0 0 0 100

disp(argument) >> A=[1 2;3 4]; >> disp(A) 12 34 >> sc=Digital Image Processing.; >> disp(sc) Digital Image Processing. >> disp(This is another way to display text.) This is another way to display text.

>> t=input(message) >> t=input(messages,s)


Example: >> t=input(Enter your data: ,s) Enter your data:[ 1, 2, 4] in work space ............t = 1, 2, 4

You might also like