Tif image saving a black image

Viewed 375

I have input a uint8 tif image and tried to convert it as a uint16 tif image. Though the conversion works when I save the image using tiff.imsave the image is exported as a completely black image. I am not sure what I am doing wrong. Kindly guide.

from skimage.io import imread
from skimage.io import imshow
import numpy as np
import cv2
import PIL 
import glob, os
import tifffile as tiff


Image_input = tiff.imread("Input.tif");
imshow(Image_input);
Image_output = Image_input.astype(np.uint16)
imshow(Image_output);
im = tiff.imsave('Output.tif', Image_output)
1 Answers

In a uint8 image, all the pixels lie in the range 0..255. In a uint16 image, all the pixels lie in the range 0..65535.

So, the brightest pixel (255) in your input image will only be 255*100/65535 or 0.4% bright, also known as nearly black in your output image.

You will probably want to scale your image, multiplying by 255 or shifting left 8 bits to give it a comparable brightness.

Note there is no benefit of increased luminosity resolution as a result of your operation - so I hope there is some other unmentioned purpose to moving to 16-bit.

Related