为什么16位到8位的转换会产生条纹图像?

2024-09-30 22:24:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在几张VHSR卫星图像上测试分割算法,这些图像最初是16位格式的,但当我将它们转换为8位图像时,生成的图像显示出条纹状的外观。 我尝试过不同的python库(skimage、cv2、scipy)得到了相似的结果。在

1)原来的16位图像是一个4波段图像(NIR,B,G,R),所以需要选择合适的波段来创建一个真彩色图像,RGB图像(4,3,2波段)。提前谢谢。可从以下链接下载: 16bit image

2)我使用此代码将每个像素值从现在适合8位范围内的16位整数转换为:

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

这是我上面代码的结果:


Tags: 代码图像算法格式波段scipycv2ss
2条回答

我认为这是一种方法:

#!/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')

enter image description here

你可能需要调整一下对比度,然后检查我选择了正确的波段。在

bytescale适合我。我认为asarray这一步把事情搞砸了。在

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)

enter image description here

相关问题 更多 >