Continue to Site

# Difficulty in matlab coding

Status
Not open for further replies.

#### Anney

##### Newbie level 3
Hi

I am tring to perform a coding of the below equations which basically is an enhancement operation of an image called Single Scale Retinex.

The Single Scale retinex is given by

Ri (x,y)=log Ii (x,y) – log [F(x,y) * Ii (x,y) ]

Where

F(x,y) = K exp(-r2 / c2 )--- Surround Function
c- Scalar value and selection of K is that
r- √ x2 + y2
∫∫ F(x,y) dx dy =1

The problem I have is , I am not able to find the value of F(x,y) (surround function) with the integration condition....

Could somebody help me with this
Thank you

Hi Anney,

Welcome to Edaboard!
If there is no a typo and I'm not wrong, you equation reduces (assuming natural log) to

Ri (x,y) = -log(K) + r2/c2

Regards

Z

Anney

### Anney

Points: 2
I did not understand what your problem exactly is. Is it integration in 2D in MATLAB? If you want to integrate two-variable functions over rectangular areas, you can make use of "meshgrid" function. Below lines may give you an idea.
[x,y]=meshgrid(-5:0.1:5,-10:0.1:10); % x,y grid for two independent variable is created.
r=sqrt(x.^2+y.^2) % norms of points are stored

Anney

### Anney

Points: 2
@Zorro and Ferdem

Actually I need to solve for Ri(x,y) with those conditions and my difficulty is in 2D integration.

Using meshgrid I agree ,I can find r...which on substituting in F(x,y) = k exp(-r.^2/c.^2)....[[c is any scalar value]]

now to find the value of k i use the integration condition ∫∫ F(x,y) dx dy =1

ie k=1/∫∫ (exp(-r.^2/c.^2))

My problem is I dont know how to satisfy this condition and subsitute in
Ri (x,y)=log Ii (x,y) – log [F(x,y) * Ii (x,y) ]

I get errors while coding this part....Can anyone send me the matlab code for this .

Regards
Anney

---------- Post added at 13:33 ---------- Previous post was at 13:13 ----------

Ii(x,y) is the original image

* is the convolution operation

F(x,y) is the surround function calculated from F(x,y) = k exp(-r.^2/c.^2)

Thank You
Anney

Because I m not familiar with your subject, I can only help you about how you code math expressions in Matlab. For example you can calculatethis integral, ∫∫ (exp(-r.^2/c.^2)). You should define integration region first. Lets say: x is in between 0-5 and y 0-10.

deltax=0.1;
deltay=0.2;
c=5;
[x,y]=mesgrid(0:deltax:5,0:deltay:5);
r=sqrt(x.^2+y.^2);
integrand=(exp(-r.^2/c.^2)); %calculates values of integrand at sample points
deltas=deltax*deltay; %represents differential area in discrete domain
integral_result=sum(sum(integrand*deltas)); % sum all values (differential area times value at that point for each point!)

I did not try this code in Matlab, therefore I did not wrap it by code tags. There may be errors but I hope it helps you.