GiH
GiH

Reputation: 415

What Linear Mapping Function

What linear mapping function is required to map a gray image from [30-200] to [0, 255]?

I have already done some work and this is what I have come up with, but I would like to know if it's the correct way to do it:

min : 30, want to map to 0
mid : 85, want to map to 128
max : 200, want to map to 255

if (i <= mid), M(i) = 127*(i - min)/(mid - min) 
if (i  > mid), M(i) = 128 + (255 - 128)*(i - mid - 1)/(max - mid - 1); 

This appears to be correct to me because:

if i = 30, it should map to 0. Plugging the information in: 
M(30) = 127*(30-30)/(85 - 30) = 0
If i = 85, it should map to 127:
M(85) = 127*(85 - 30) / (85 - 30) = 127
If i = 200, it should map to 200:
M(200) = 128 + (255 - 128)*(200 - 85 - 1)/(200 - 85 - 1) = 255

Thank you.

Upvotes: 1

Views: 240

Answers (1)

Olivier A
Olivier A

Reputation: 842

If you apply a linear mapping, the middle of the first interval will be automatically mapped to the middle of the second interval (you can see it as Thales principle). So you need to apply only one equation: y=a.x+b

To solve this equation you have two information: a.30+b=0, and a.200+b=255.

Then you solve this and you obtain: a=1.5, and b=-45.

And be careful, the middle of [30, 200] is not 85 but 115 (=30+85).

Finally you can check, if you apply 1.5*x-45=y, you successfully obtain: 30->0, 200->255, and 115->127.5

Upvotes: 1

Related Questions