8 bit to 16 bit ImageSave

I'm trying to save an 8 bit wave to a 16 bit image and maintain the scale of the image, using ImageSave. Attached is graphic. Is it possible to save an 8 bit wave to a 16 bit image and maintain the "scale" of the image? By scale, I mean the ratio of a given pixel intensity to the max intensity for a given bit depth (255 for 8bit or 65535 for 16bit)? I'm using IP7.

Clayton
16bit conversion.jpg (253.72 KB)
Same problem. The ImageSave function appears to scale the created image based upon the min and max value of the image. So if I scale the 8 bit image values to 16 bit values before I save it, the same problem occurs. The solution I'm currently using is to save it twice. I first save the 8 bit wave to a 16 bit image, then reload the image back into Igor, scale it (based upon the 8 bit image), and then save it again as 16 bit. The 16 bit to 16 bit save, does not change the scale.
How about using ImageSave/U for not normalizing? According to the IP7 documentation this is what you want.

PS: It is much easier to help if you post a minimal working example.
ctmckee wrote:
Is it possible to save an 8 bit wave to a 16 bit image and maintain the "scale" of the image? By scale, I mean the ratio of a given pixel intensity to the max intensity for a given bit depth (255 for 8bit or 65535 for 16bit)? I'm using IP7.
Clayton


Note that the documentation tells you that the normalization option (/U) applies to TIFF files. If you are saving jpg images (as may be implied by the image you posted) there is no sense to trying the 16 bit option.

FWIW, it would really be far more useful to see the syntax of the commands you used than to see a jpg image.

In the image I attached I tried to show that both
 ImageSave/I/DS=16/T="tiff" Image_8bit
and
 ImageSave/I/DS=16/U/T="tiff" Image_8bit
give the same result.

To describe my second comment in a bit more detail. I have an 8bit wave, I save this wave to an image using:
 ImageSave/I/DS=16/T="tiff" Image_8Bit as "Image_16bit.tif"
then I load the 16 bit image back into Igor, modify it via the scale of the 8bit image and then save again:
matrixop/o Image_16bit=(Image_8bit/255)*65535
ImageSave/I/DS=16/T="tiff" Image_16bit as "SameScaleImage"


The 16 bit to 16 bit save appears to maintains the scale. The 8 bit to 16 bit always modifies it.

Ok, writing that out made me realize how to correct. I now do the following so I don't have to save, import and re-save.

duplicate/o image_8bit image_16bit
redimension/w image_16bit
matrixop/o image_16bit=(image_8bit/255)*65535
ImageSave/I/DS=16/T="tiff" Image_16bit
ctmckee wrote:
Ok, writing that out made me realize how to correct. I now do the following so I don't have to save, import and re-save.

duplicate/o image_8bit image_16bit
redimension/w image_16bit
matrixop/o image_16bit=(image_8bit/255)*65535
ImageSave/I/DS=16/T="tiff" Image_16bit


I don't think this code is executing in the manner that you expect. The two lines:
duplicate/o image_8bit image_16bit
redimension/w image_16bit
are meaningless and misleading. You do not need to pre-allocate the output of MatrixOP. Since your following line is:
matrixop/o image_16bit=(image_8bit/255)*65535
then it does not matter if image_16bit exists and it does not matter what number type it has (as long as it is not a text wave).

Furthermore, the result of the expression (image_8bit/255)*65535 is NOT 16 bit wave; check it out and you will find it is SP!

To get a 16bit wave you can execute:
matrixop/o image_16bit=Uint16(image_8bit*255)


I hope this helps,

A.G.