find an inverse log transformation of an image in matlab

19.2k Views Asked by At

I have been searching for this almost all day. The general form of the log transformation is

s = clog(1+r) 

where

c = 0.1 

The opposite is inverse log transformation(book). What will be the inverse log transformation? Is it

s = exp(r)?

Could not get right output.

5

There are 5 best solutions below

3
On

Exp() will only be an inverse of Log() if Log() is the natural logarithm. If your Log() is using a different base (base 2, base 10, any other arbitrary base), then you will need to use the different base in place of e in Exp().

Update

Try 10^(x/0.1)-1. x/0.1 undoes the 0.1 * operation, 10^ undoes the log(), and -1 undoes the +1.

0
On

I think you defined c to normalize the resulting image to a valid (visible) range. Then a rational value for c could be:

c = (L - 1)/log(L) 

where L is the number of gray levels. So s would be:

s = log(r+1) .* ((L – 1)/log(L)) 

or

s = log(r+1) .* c

Then the inverted transformation would be:

s2 = (exp(r) .^ (log(L) / (L-1))) – 1

or

s2 = (exp(r) .^ (1/c)) – 1

This is the transformation output for L=256:

enter image description here

To apply this transformation to an image we need to do some typecasting:

figure;
L = 256;
I = imread('cameraman.tif');
log_I = uint8(log(double(I)+1) .* ((L - 1)/log(L)));
exp_I = uint8((exp(double(I)) .^ (log(L) / (L-1))) - 1);
subplot(2, 2, [1 2]); imshow(I); title('Input');
subplot(2, 2, 3); imshow(log_I); title('\itlog(I)');
subplot(2, 2, 4); imshow(exp_I); title('\itexp(I)');

enter image description here

0
On

This works for inverse log transformation

clc;
clear all;
close all;
a=imread('imagename.jpg');
ad=im2double(a);
x=ad;
[r,c]=size(ad);
factor=1;
for i=1:r
    for j = 1:c
  x(i,j)= exp(ad(i,j)^factor)-1;
    end
end
subplot(1,2,1);imshow(ad);title('before');
subplot(1,2,2);imshow(x);title('after');
1
On

You can use power law transform to do this as in power law transform you can shift the curve so as to perform log transform or to perform inverse log transform which effects high level pixels but not low level pixels..You may use this

a=imread('Figure-3.tif');
a=im2double(a);
[r,c]=size(a);
gamma=0.6;
C=1;
for i=1:r
for j=1:c
   s(i,j)=C*(a(i,j)^gamma);
end
end
imshow(s);
0
On
import cv2
import numpy as np
# Open the image.
img = cv2.imread('InverseLogTransform.jpg')
cv2.imshow('Input',img)
# Apply log transform.
c = 255 / (np.log(1 + np.max(img)))
ilog_transformed = np.(exp(img/c))-1
# Specify the data type.
ilog_transformed = np.array(ilog_transformed, dtype=np.uint8) 
cv2.imshow('ILog',ilog_transformed)
cv2.waitKey(0)cv2.destroyAllWindows()