# Log transformation of an image in matlab

Log curve maps a narrow range of grey-level values in the input image into a wider range of output levels

### Mathematical Form:

Log transformation in general in shown by this equation

s=clog(1+r)

### Uses:

1. Used to expand the values of dark pixels in an image while compressing the higher values

2. It compresses the dynamic range of images with large variations in pixel values

### Properties:

It can have intensity range from 0 to 10^6 or higher

We can not see the significant degree of detail as it will be lost in the display

### Example:

Example of image with dynamic range: Fourier spectrum Image

### Explanation:

As discussed above applying log transformation to an image will expand its low valued pixels to a higher level and has little effect on higher valued pixels so in other words it enhances image in such a way that it highlights minor details of an image as shown in figure below. Image (a) has minor details which are not much prominent but after applying log transformation we are able to see those little details

### Graph:

The log transformation has a graph as shown below in this you can easily see that how it is shifting low intensity grey-level values to high values while having a little or no effect on higher intensity pixels.

Now we want to implement this in matlab the code for this implementation is given below. We used same equation for transformation as shown on top i.e

s=clog(1+r)

clear all;

a=imread(‘C:\MATLAB7\Figure-3.tif’);

a=im2double(a);

x=a;

[r,c]=size(a);

C=4;

for i=1:r

for j=1:c

x(i,j)=C*log(1+a(i,j));

end

endsubplot(1,2,1)

imshow(a);

title(‘Before Transformation’)subplot(1,2,2)

imshow(x);

title(‘After Transformation’)

If you have further questions feel free to ask by commenting below….Thanks!

Whether this code also used for bi log transformation?

It can be made to use for bi log transformation

for k=0:255

for l=0:255

count=0;

for x=2:r-1

for y=2:c-1

temp = I(x,y);

if temp==k

temp1=I(x,y-1);

temp2=I(x,y+1);

temp3=I(x-1,y);

temp4=I(x+1,y);

Temp=[temp1 temp2 temp3 temp4];

inc=numel(find(Temp==l));

count=count+inc;

end

end

end

Qbar(k+1,l+1)=count;

T=temp;

A{k+1,l+1}=Temp;

end

end

how can reduce the for loop and how to reduce the time delay?

Matlab is not very fast for image processing use OpenCV by grabbing the concept from here and implementing it on OpenCV i will suggest that for faster performance…

i need Matlab program for this.

Any one can help me…. i need weighted histogram matlab code.