Posted by
Herbie on
URL: http://imagej.273.s1.nabble.com/linear-transform-tp5023513p5023519.html
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