Re: linear transform

Posted by Robert Lockwood on
URL: http://imagej.273.s1.nabble.com/linear-transform-tp5023513p5023514.html

Thomas, this is a math problem in four steps,
1. Translate the values from the current minimum of 20000 to a minimum of
zero by subtracting 20000 from the pixel value.
2. Calculate a new value between 0 and 1 by dividing it by the existing
range (65535 - 20000)
3. Multiply that value by the desired range (65535 - 30000)
4. Finally translate the value by adding the new minimum (and rounding it)
newValue =      round( ((oldValue - oldMin)/oldRange)*newRange + newMin)

I tested this for these values and results
20,000, 30,000, 40,000, and 65,535
30,000, 37,787, 45,574, and 65,535

To increase the speed, newRange/oldRange can be moved outside the loop as
it is a constant.
If you have a few times more pixels than 65,535 - 20,000 (45,535 + 1) and
many files I suggest pre-calculating each value into an array as a lookup
table. if speed matters.

HTH
Nate


On Fri, Jun 12, 2020 at 2:32 PM Thomas Fischer <[hidden email]> wrote:

> Hi everybody,
>
> I have a number of 16bit images. The highest gray value is 65535 in all of
> them. The lowest gray value varies between 20000 and 40000. How can I
> transform all images in a linear fashion leaving the highest gray value at
> 65535 and set the lowest to 30000?
>
> With Enhance Contrast I can stretch the distribution in such a manner that
> the lowest gray value is zero. But I want to stretch the distribution in
> some images and condens it in others.
>
> Thank you, Thomas
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html