Re: linear transform

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

You are absolutely correct young man, I didn't catch the error untill after I hit the send key.  Finger dyslexia in an old man. My apologies, and however no you would only subtract the 20000, thereby lowering
the overall level of the image while maintaining the orginial range of intensity.
Again, I apologize.
Bob 😊

________________________________
From: ImageJ Interest Group <[hidden email]> on behalf of CARL Philippe (LBP) <[hidden email]>
Sent: Saturday, June 13, 2020 9:36 AM
To: [hidden email] <[hidden email]>
Subject: Re: linear transform

Dear Bob,
I'm really not an expert of these pixels operations but like Nelson Mandela said: "I never lose. I either win or learn".
Thus if what I will be writing below is wrong, I will then be able to learn from my errors!
But in order to subtract 20000 from everything shouldn't you rather use the Math>Macro>(v=v-20000) [instead of the Math>Macro>(v=v*20000) your wrote ?]
Also wouldn't it even be simpler to just use the Process>Math>Substract...>20000 ?
My best regards,
Philippe

Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 42 89

----- Mail original -----
De: "Robert Smith" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Samedi 13 Juin 2020 02:42:06
Objet: Re: linear transform

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:

> 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: https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7C%7Ce8a57509af6943a4d14808d80f9ee006%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637276522322408782&amp;sdata=r%2FwhGAIrnLekJKjNmRex4q6u4MbiSzxNF3cBwGJ3d54%3D&amp;reserved=0
>

--
ImageJ mailing list: https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7C%7Ce8a57509af6943a4d14808d80f9ee006%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637276522322418776&amp;sdata=3TWpGU7jGzY2UCW2Rjz0Ut29kCwlI4Q6N%2Few2ZVXhmM%3D&amp;reserved=0

--
ImageJ mailing list: https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7C%7Ce8a57509af6943a4d14808d80f9ee006%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637276522322418776&amp;sdata=3TWpGU7jGzY2UCW2Rjz0Ut29kCwlI4Q6N%2Few2ZVXhmM%3D&amp;reserved=0

--
ImageJ mailing list: https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7C%7Ce8a57509af6943a4d14808d80f9ee006%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637276522322418776&amp;sdata=3TWpGU7jGzY2UCW2Rjz0Ut29kCwlI4Q6N%2Few2ZVXhmM%3D&amp;reserved=0

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