Re: linear transform

Posted by foxtango on
URL: http://imagej.273.s1.nabble.com/linear-transform-tp5023513p5023518.html

Thanks to both Roberts,

I confess that I use imagej in a very simple way. Unless I find a code on
the internet I embed the result of the macro recorder in a shell script
which replaces the variable parameters. Since the present task lends itself
to batch programming I have two questions.

1) I know how to extract the list of histogram values and from that I can
extract the lowest bin which is different in every image. But there must be
a possibility to get the MIN that is shown on the histogram window
directly, without the detour via the whole histogram.

2) Could you point out how the core of the math operations looks like. I do
know the input and output periphery.

Thanks again, Thomas


Am Sa., 13. Juni 2020 um 02:43 Uhr schrieb Robert Smith <[hidden email]
>:

> 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://eur05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7C%7Ce9ac4880ab2b428012c508d80f2bc62d%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637276027973125539&amp;sdata=XrP9B1AVEwWhJEeX2GJk9V07blnxdxdD92fv4FSbG2Y%3D&amp;reserved=0
> >
>
> --
> ImageJ mailing list:
> https://eur05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=02%7C01%7C%7Ce9ac4880ab2b428012c508d80f2bc62d%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637276027973135535&amp;sdata=P8JR93MtOyspCWEIZUpuo0%2BX5tIhhVCMldq4jLiG8kM%3D&amp;reserved=0
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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