MATLAB Answers

## Problem in Gray Level Manipulation

Asked by Vennila

### Vennila (view profile)

on 6 Jan 2013
Accepted Answer by Image Analyst

### Image Analyst (view profile)

Hi all,

I tried to enhance a gray scale image by using the formula

`   E(i,j) = round( I(i,j)^3/ f * M^2)`

where

```      M = max gray level of the image
f = 0.8```

The output should be a gray scale image, but I get a binary Image.

Thanks for your help in advance.

Code :

```[x,y] = size(I);
I1 = repmat(uint8(0),x,y)
M = max(I(:));
for i = 1:x
for j = 1:y
if I(i,j) ~= 0
v = double(I(i,j));
I1(i,j) = round( v^3 / f * M^2 );
% disp(I1(i,j)); ' all manipulated pixels has value 255
end
end
end
```

## 2 Answers

### Image Analyst (view profile)

Answer by Image Analyst

### Image Analyst (view profile)

on 6 Jan 2013
Accepted answer

What are some values of z? Also, have you looked at I1 in the variable editor to verify that they're all 255 or 1? Have you tried to display I1 with [], like this:

```imshow(I1, []);
```

which you need to do for floating point images? M^2 is in the numerator - is that what you want? The units seem all weird - you'll have an output that is proportional to gray level to the fifth power! Are you missing some parentheses? Like you want M^2 in the denominator? Where did you ever get this formula anyway? Do you have a citation for it?

Image Analyst

### Image Analyst (view profile)

on 7 Jan 2013

Is f and array? It should be. But you're not using ./, you're using /, so that leads me to think that f is not an array like it needs to be.

Vennila

### Vennila (view profile)

on 7 Jan 2013

f is not an array.

Image Analyst

### Image Analyst (view profile)

on 7 Jan 2013

Then you're not following the algorithm given in the paper.

### Walter Roberson (view profile)

Answer by Walter Roberson

### Walter Roberson (view profile)

on 6 Jan 2013

Change

```M = max(I(:));
```

to

```M = double( max(I(:)) );
```

Vennila

### Vennila (view profile)

on 6 Jan 2013

I tried it but no change.

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

### MATLAB Academy

New to MATLAB?

Learn MATLAB today!