Posted by
Herbie on
URL: http://imagej.273.s1.nabble.com/linear-transform-tp5023513p5023521.html
Good day Thomas,
the following code is about 10 times faster than the previous:
// imagej-macro "linTrans" (Herbie G., 14. June 2020)
requires("1.53b");
run("Revert");
setOption("ScaleConversions", false);
w = getWidth;
h = getHeight;
img = getImageID;
getRawStatistics( n, mn, currMin );
max = 65535;
min = 30000; // desired minimum
b = ( max - min );
b /= ( max - currMin );
a = max * ( 1 - b );
run("Plot Profile"); // ????
selectImage( img );
run( "32-bit" );
run("Multiply...", "value=&b");
run("Add...", "value=&a");
run( "16-bit");
run("Plot Profile"); // ????
exit();
// imagej-macro "linTrans" (Herbie G., 14. June 2020)
A plugin will be even faster...
Regards
Herbie
::::::::::::::::::::::::::::::::::::::::::::
Sorry Thomas,
there was a little typo in the code!
Please correct the value according to:
max = 65535;
Attached please find an additional test image.
Regards
Herbie
::::::::::::::::::::::::::::::::::::::::::::
Good day Thomas,
the following macro code applies the desired linear transformation to
all values of a 16bit image. (Test image appended.)
// imagej-macro "linTrans" (Herbie G., 13. June 2020)
requires("1.53b");
run("Revert");
w = getWidth;
h = getHeight;
img = getImageID;
getRawStatistics( n, mn, currMin );
max = 65635;
min = 30000; // desired minimum
b = ( max - min );
b /= ( max - currMin );
a = max * ( 1 - b );
run("Plot Profile"); // ????
selectImage( img );
for ( j=0; j<h; j++ ) {
for ( i=0; i<w; i++ ) {
setPixel( i, j, linTrans( a, b, getPixel( i, j ) ) );
}
}
run("Plot Profile"); // ????
exit();
function linTrans( x, y, z ) { return round( x + y * z ); }
// imagej-macro "linTrans" (Herbie G., 13. June 2020)
Paste the above macro code to an empty macro window (Plugins >> New >>
Macro), open the test image, then run the macro.
With the test image you get two profiles along the image diagonal, one
taken before the transformation, the other after the transformation.
If your image doesn't have a selection, you must comment or eliminate
the code lines denoted with "????".
Please note that transforming an image per macro code is slow.
You need a plugin to perform fast pixel-wise operations.
Regards
Herbie
::::::::::::::::::::::::::::::::::::::::::::
Am 12.06.20 um 22:58 schrieb Thomas Fischer:
> 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