Discussion:
Conversion 16-bit to 8-bit (without scaling)
john.frink02-gM/Ye1E23mwN+
2012-05-11 10:19:06 UTC
Permalink
Hi all,

I have a 16-bit image where - when I analyze the histogram - only bins in
the range say 45 to 300 are taken, i.e. it's a "shifted" 8-bit image in the
16-bit range. Now, I would like to convert this image to 8-bit without
rescaling but only setting the right range.

I've been trying this by writing the following macro (in fact, it's a batch
of such images):
for (i=100; i <= 200; i++) {
open("./Img" + i + ".tif");
run("Conversions...", " ");
run("8-bit");
saveAs("Tiff", "./Img" + i + ".8bit.tif");
close();
}

This, however only sets the range from 0-255, without taking the bins
256-300 into account.
Do you have any advice for me? I've been trying this now for a while...

In addition, I would like to go over my batch of 3d tiffs and find out the
minimal bin taken in the histogram before applying this macro.

Thanks in advance!
John
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Kota
2012-05-12 09:51:44 UTC
Permalink
Post by john.frink02-gM/Ye1E23mwN+
Hi all,
I have a 16-bit image where - when I analyze the histogram - only bins in
the range say 45 to 300 are taken, i.e. it's a "shifted" 8-bit image in the
16-bit range. Now, I would like to convert this image to 8-bit without
rescaling but only setting the right range.
I've been trying this by writing the following macro (in fact, it's a batch
for (i=100; i <= 200; i++) {
    open("./Img" + i + ".tif");
    run("Conversions...", " ");
    run("8-bit");
    saveAs("Tiff", "./Img" + i + ".8bit.tif");
    close();
}
This, however only sets the range from 0-255, without taking the bins
256-300 into account.
Do you have any advice for me? I've been trying this now for a while...
In addition, I would like to go over my batch of 3d tiffs and find out the
minimal bin taken in the histogram before applying this macro.
Thanks in advance!
John
Hi John,

if your images are all with the minimum of 45 and max 300, you could
simply do

run("Subtract...", "value=45");

to shift all the pixel values towards 0.

To set conversion on/off,

ON
eval("script", "ImageConverter.setDoScaling(true)");

OFF
eval("script", "ImageConverter.setDoScaling(false)");

To know the minimum pixel value of a stack, use

Stack.getStatistics(voxelCount, mean, min);

cheers,
Kota
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Sam Lord
2012-05-24 17:46:11 UTC
Permalink
I'm not sure I fully understand the problem. You cannot have pixels
outside the 0-255 range in 8bit. You can't have an 8bit image with the
range 45-300. You can, however, display a 16bit image with that range.

ImageJ will convert 16bit to 8bit in two ways: either rebin the
*displayed* range of the image (e.g. 500-8530 becomes 0-255) or rebin
the *entire* bit depth (i.e. 0-65535 will become 0-255). The former is
the default, but you can turn if off by going to Edit->Options-
Conversions and unchecking "scale when converting" (or run the
eval("script", "ImageConverter.setDoScaling(false)"); language that
Kota mentions). For your case, you wan "scale when converting"
*checked*, then just set the display range to what you want before
converting. In other words, if you go to Image->Adjust-
Brightness&Contrast, then set the display range to 45-300, then
convert to 8bit, that original range will now be rebinned to 0-255.
The old 45 value will now be 0 and 300 will be 255. If you use only
256 values in the display range of the 16bit image, no rebinning
occurs; however, if you have a larger or smaller number of values
displayed in the 16bit image, after converting those values will be
compressed or spread over the 256 bins. Does that make sense?

I don't think subtracting 45 before converting will change anything,
as long as you also shift the display range accordingly.

-Sam
Hi all,
I have a 16-bit image where - when I analyze the histogram - only bins in
the range say 45 to 300 are taken, i.e. it's a "shifted" 8-bit image in the
16-bit range. Now, I would like to convert this image to 8-bit without
rescaling but only setting the right range.
I've been trying this by writing the following macro (in fact, it's a batch
for (i=100; i <= 200; i++) {
    open("./Img" + i + ".tif");
    run("Conversions...", " ");
    run("8-bit");
    saveAs("Tiff", "./Img" + i + ".8bit.tif");
    close();
}
This, however only sets the range from 0-255, without taking the bins
256-300 into account.
Do you have any advice for me? I've been trying this now for a while...
In addition, I would like to go over my batch of 3d tiffs and find out the
minimal bin taken in the histogram before applying this macro.
Thanks in advance!
John
--
Please avoid top-posting, and please make sure to reply-to-all!

Mailing list web interface: http://groups.google.com/group/fiji-users
Loading...