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 !

Reklamlar

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

C++ matrix operations


Hi!

 

Today i will share some arithmetic operations with C++ like addition , multiplication , transpose and inverse

 

1)ADDITION

this program takes a 3×3 matrix as an input and gives the total value (2xN) .

 

—————————————————

 

#include <iostream>
using namespace std ;

int main ()
{
int i,j,b[3][3]={0},n[3][3]={0}; // definition of variables

cout<<“enter the values for 3×3 matrix : “<<endl;
// cout<<“entering to for …”<<endl;
for(i=0;i<3;i++){
for(j=0;j<3;j++) {

cout<<“(“<<i<<“,”<<j<<“)=”;
cin>>n[i][j];
cout<<endl;

b[i][j]=2*n[i][j];

}
}

////////////////////////////////////////////////////////////////////////////////////
//addition printing
cout<<“Sum : “<<endl;
for(i=0;i<3;i++){
cout<<endl;
for(j=0;j<3;j++) {
if (i==2 && j==2) cout<<‘\t’;

cout<<“(“<<i<<“,”<<j<<“)=”<<b[i][j]<<‘\t'<<‘\t’;

}
}

//end of addition printing

////////////////////////////////////////////////////////////////////////////////////
cout<<endl;

system (“pause”);
}

 

—————————————————

 

2)MULTIPLICATION

In this program i take values of a 3×3 matirx and take square of it

—————————————————

 

#include <iostream>
using namespace std ;

int main ()
{

int i,j,c[3][3]={0},a[3][3]={0},n[3][3]={0};   // defition of variables

cout<<“enter values for 3×3 matrix : “<<endl;
// cout<<“entering to for …”<<endl;
for(i=0;i<3;i++){
for(j=0;j<3;j++) {

cout<<“(“<<i<<“,”<<j<<“)=”;
cin>>n[i][j];
cout<<endl;

c[i][j]=n[i][j]*n[i][j];
}

}

////////////////////////////////////////////////////////////////////////////////////
//multiplication display

cout<<“carpim : “<<endl;
for(i=0;i<3;i++){
cout<<endl; cout<<‘\t’;
for(j=0;j<3;j++) {
if(i==2 && j==2) cout<<‘\t’;
cout<<“(“<<i<<“,”<<j<<“)=”<<c[i][j]<<‘\t’;

}
}

////////////////////////////////////////////////////////////////////////////////////

cout<<endl;
system (“pause”);
}

 

—————————————————

 

 

3)TRANSPOSE

In this program , i take values of a 3×3 matrix and display the transpose of it ,

(if you dont know about transpoze matrix :http://en.wikipedia.org/wiki/Transpose )

 

—————————————————

 

#include <iostream>
using namespace std ;

int main ()
{

int i,j,a[3][3]={0},n[3][3]={0};

cout<<“enter values for 3×3 matrix : “<<endl;
// cout<<“entering to for …”<<endl;
for(i=0;i<3;i++){
for(j=0;j<3;j++) {

cout<<“(“<<i<<“,”<<j<<“)=”;
cin>>n[i][j];
cout<<endl;
a[j][i]=n[i][j]; // calculating the transpose

}

}

 

////////////////////////////////////////////////////////////////////////////////////
//transpose printing
cout<<“tranpose : “<<endl;
for(i=0;i<3;i++){
cout<<endl;
for(j=0;j<3;j++) {

cout<<“(“<<i<<“,”<<j<<“)=”<<a[i][j]<<‘\t’;

}
}

////////////////////////////////////////////////////////////////////////////////////

system (“pause”);
}

 

—————————————————

 

4)INVERSE

 

In this program  , i calculate the inverse of a 3×3 matrix , i use determinant method , you can also find inverse programs done by gauss-jordan method

—————————————————

 

#include <iostream>
using namespace std ;

int main ()
{

cout<<“enter values for 3×3 atrix : “<<endl;
// cout<<“entering to for …”<<endl;

int z,j,i,n[3][3];
double a[3][3];

for(i=0;i<3;i++){
cout<<endl;
for(j=0;j<3;j++) {

cout<<“(“<<i<<“,”<<j<<“)=”;
cin>>n[i][j];
cout<<endl;

}

}

// adjoint matrix calculation

a[0][0]=n[1][1]*n[2][2]-n[1][2]*n[2][1];
a[0][1]=n[1][2]*n[2][0]-n[1][0]*n[2][2];
a[0][2]=n[1][0]*n[2][1]-n[1][1]*n[2][0];
a[1][0]=n[0][2]*n[2][1]-n[0][1]*n[2][2];
a[1][1]=n[0][0]*n[2][2]-n[0][2]*n[2][0];
a[1][2]=n[0][1]*n[2][0]-n[0][0]*n[2][1];
a[2][0]=n[0][1]*n[1][2]-n[0][2]*n[1][1];
a[2][1]=n[0][2]*n[1][0]-n[0][0]*n[1][2];
a[2][2]=n[0][0]*n[1][1]-n[0][1]*n[1][0];

z=n[0][0]*a[0][0] + n[0][1]*a[0][1] + n[0][2]*a[0][2];

////////////////////////////////////////////////////////////////////////////////////

// inverse  printing

cout<<“determinant : “<<z<<endl;
cout<<“inverse of matrix :  : “<<endl;
for(i=0;i<3;i++){
cout<<endl; cout<<‘\t’;
for(j=0;j<3;j++) {
if(i==2 && j==2) cout<<‘\t’;
cout<<“(“<<i<<“,”<<j<<“)=”<<a[j][i]/z<<‘\t’;

}
}

cout<<endl;
////////////////////////////////////////////////////////////////////////////////////

system (“pause”);

}

 

—————————————————

 

 

We did some arithmetic calculations with C++ today , see you !

 

 

Aralık 26, 2010 Posted by | C/C++ programming | , , , , , | Yorum bırakın