Posted by
Robert Smith on
URL: http://imagej.273.s1.nabble.com/linear-transform-tp5023513p5023515.html
Robert, excellent and best approach- with one recommendation, instead of simply subtracting 20000 from everything use the Math>Macro>(v=v*20000) which would subtract that value from all pixels and would be much faster than a array while not changing the range of any of them. Just a suggestion.
Bob
________________________________
From: Robert Lockwood <
[hidden email]>
Sent: Friday, June 12, 2020 7:49 PM
To:
[hidden email] <
[hidden email]>
Subject: Re: linear transform
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:
--
ImageJ mailing list:
https://eur05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=02%7C01%7C%7Ce9ac4880ab2b428012c508d80f2bc62d%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637276027973135535&sdata=P8JR93MtOyspCWEIZUpuo0%2BX5tIhhVCMldq4jLiG8kM%3D&reserved=0--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html