Swordrock's Blog

Just another WordPress.com site

Image processing 3


Hi !

Today i will talk about ;

Intensity transformations and spatial filtering

Spatial domain processing :

1)     intensity (gray level) transformations

2)     spatial filtering

g (x,y) = T [f (x,y)]  : general form of spatial filtering

f is the input image and g is the output image , T is an operator on f , defined over a specified neighbourhood about point (x,y) .

when we work with color images , intensity is used to denote a color image component certain color spaces .

Function imadjust

A basic image processing toolbox tool for intensity transformations of gray scale .

G = imadjust (f,[low_in high_in],[low_out high_out], gamma)

This function maps the intensity values in image f to new values in g , such that values between  low_in and high_in values between low_out and high_out values .

Values less than low_in and above high_in clipped  . It means that values above high_in map to high_out and values less than low_in clipped to low_out .

The input and output image is the same class; unit8 unit 16 etc .

>> f = imread (‘40977.jpg’);

>> g = imadjust(f,[0 1],[1 0]);

>> imshow (g)

This is the digital equivalent of obtaining a photographic negative , useful for enhancing white or gray detail embedded in a large , predominantly dark region .

Negative of an image can also be called with imcomplement function.

>>  g = imcomplement(f);

>> imshow (g);

Ex :

>> g2 = imadjust (f,[0.5 0.75],[0 1]);

>> imshow (g2)

This example expands the gray scale region 0.5 and 0.75 to the full 0 1 range . It is great for highlighting an intensity band of ineterest .

Ex :

>> g3  = imadjust (f,[],[],2);

>> imshow (g3)

More gray tones …

Logarithmic and Contrast-Stretching Tranformations

Basic tools for dynamic range manipulation .

G = c*log(1+double(f))

C is a constant . Shape is similar to the gamma curve .

It is also used to compress dynamic range . For example , it is not unsual to have a Fourier spectrum with values in the range [0 10^6] or higher . When we display it on the monitor  , it is scaled linearly to 8 bits , high values dominate the display , resulting in lost visual detail for lower intensity values in the spectrum .

By computing the log , a dynamic range on the order of , for example 10^6 , is reduced to approximately 14 , which is much more manageable .

While working logarithmic transformation , it is often desirable to bring the resulting compressed values back to the full range display .

For 8 bits , it is easily done like that :

G4= im2unit8 (mat2gray(g));  % using mat2gray brings the values to the range [0 1] and im2unit8 brings them to the range [0 255]

Later this transformations will be easier .

Contrast-Stretching Function

Compresses the input levels lower than m into a narrow range of dark levels in the output image ; it compress the values above m into a narrow band of light levels in the output . Result is an image of higher contrast .

This limiting function called thresholding function , a simple tool used for image segmentation .

S = T(r) = 1/ (m/r)^E

E controls the slope of the function .

We  can implement this  in Matlab like that ;

G = 1./(1+double(f)+eps)).^E

(suppose E is 20)

Use of eps prevents any overflow if f has any 0 values

 

See you !

Ocak 11, 2011 Posted by | Image Processing | , , , | Yorum bırakın

Image processing 2


Last lesson i introduce some basic matlab commands for image processing and tell what is image processing .

Today i will go on useful functions for image processing  .

İmage types

images

#ind

#Intensity images

#binary exed images

#RGB images

We mostly work on intensity and binary images , indexed and rgb images are after Works all .

for more info , you can look at :

http://en.wikipedia.org/wiki/Image_file_formats

Intensity images

A data matrix whose values represents intensities . Image pixels have values between [0 255] (for unit 8)  and between [0 65535] (unit 16)

Binary images

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

A numeric array is converted to binary using function logical . Thus if A is a numeric array consisting 0s and 1s , we create a logical rray B using that :

B = logical (A) ;

If A contains elements other than 0 and 1 , logical function converts all nonzero values to 1 , and all entries with value 0 to logical 0s .

To test if an array is logical we use islogical function :

islogical (C)

Converting between Data Classes and Image types

Converting between images and data types are an important task for Matlab to use in software

unit8 (C) % if an array of class double has any values outside the range [0 255] and it is converted to class unit8in the manner just described , Matlab converts to 0 all values less than 0 , and converts all the values 255 bigger than 255 .

Converting between Image classes and data types

f =

-0.5000    0.5000

0.7500    1.5000

>> g = im2unit8 (f)

0             128

191    255

mat2gray (f) :

g= mat2gray (f,[fmin , fmax])

sets the values of fmin and fmax to the actual minimum and maximum values in f . input andoutput is also double .

im2double (f) :

converts an input to class double .

im2bw (f,T) :

conversion between binary and intensity image types .

T = 0.5

g= im2bw (f,T)

produces a binary image g from intensity image f by thresolding .

g values less than threshold takes 0 and other takes 1 .

the value specified for T has to be in the range [0,1] . When we dont use imbw without T , it is set to 0.5 as a default value , and you can change it .

You can change T values and you will get different outputs .

Array indexing

#Vector indexing

>>  v = [5 89 6 2 789]

v =

5    89     6     2   789

>> w = v.’

w =

5

89

6

2

789

>>

As you see , you can set a column vector and convert it by using .’

We can get matrix values by indexing like that :

>> a = [1 2 3;4 85 98 ; 69 87 45]

a =

1     2     3

4    85    98

69    87    45

>> a(2,2)  % as you can see we set matrix a 3×3 and take the value at (2,2)

ans =

85

>>

You can use colon operator to get full column or row :

>> a(:,3)

ans =

3

98

45

sum (a(:))

If we want to find the sum of all the elements of the matrix :

>> sum ((a(:)))

ans =

394

Some Important Arrays

zeros (M,N) generates an M x N matrix of 0s of class double .

ones (M,N) generates an M x N matrix of 1s of class double .

true (M,N) generates an M x N logical matrix of 1s.

false (M,N) generates an M x N logical matrix of 0s.

Rand (M,N) generates an M x N matrix whose entries are uniformly distributed

>> rand (5,5)

ans =

0.8147    0.0975    0.1576    0.1419    0.6557

0.9058    0.2785    0.9706    0.4218    0.0357

0.1270    0.5469    0.9572    0.9157    0.8491

0.9134    0.9575    0.4854    0.7922    0.9340

0.6324    0.9649    0.8003    0.9595    0.6787

Some arithmetic image functions

1

İmadd : adds two images

2

İmsubstract : substracts two images , or substract a constant from an image

3

İmmultiply : multiplies two images

4

İmdivide : divides two images

5

İmabsdiff : computes the absolute difference between two images .

6

İmcomplement : complements an image

7

İmlincomb : computes a linear combination of two or more images .

See you !

Ekim 17, 2010 Posted by | Image Processing | Yorum bırakın