简体   繁体   中英

Why 16bit to 8bit conversion produces striped image?

I am testing a segmentation algorithm on several VHSR satellite images, which originally comes in 16bit format, but when I convert them to 8bit images, the produced images are showing striped appearance. I've been trying different python libraries (skimage, cv2, scipy) getting similar results.

1) The original 16-bit image it is a 4 band image (NIR,B,G,R), so you need to choose the right bands to create a true color image, RGB image (4,3,2 bands). thanks in advance. It can be downloaded from this link:16bit image

2) I use this code to convert each pixel value, from a 16-bit integer now fitting within 8-bit range:

  from scipy.misc import bytescale
  SS = io.imread('Imag16bit.tif')
  SS = bytescale(SS)
  SS = np.asarray(SS) 
  plt.imshow(SS)

This is my result of above code:

bytescale works for me. I think the asarray step messes up something.

import cv2
from skimage import io
from scipy.misc import bytescale

image = io.imread('SkySat_16bit.tif')
cv2.imshow('Original', image)
print(image.dtype)

image = bytescale(image)
print(image.dtype)

cv2.imshow('Converted', image)
cv2.waitKey(0)

在此处输入图片说明

I think this is a way to do it:

#!/usr/local/bin/python3

from PIL import Image
from tifffile import imsave, imread

# Load image
im = imread('SkySat_16bit.tif')

# Extract Red, Green and Blue bands into separate 8-bit arrays
R = (im[:,:,3]/256).astype(np.uint8)
G = (im[:,:,2]/256).astype(np.uint8)
B = (im[:,:,1]/256).astype(np.uint8)

# Combine bands into RGB array
RGB = np.dstack((R,G,B))

# Save to disk
Image.fromarray(RGB).save('result.png')

在此处输入图片说明

You may want to adjust the contrast a bit, and check I selected the correct bands.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM