无法在OpenCV / Scikit-Image / Tifffile中加载tif图像/分割的tif图像

时间:2019-10-26 10:03:06

标签: python opencv scikit-image

我目前正在尝试在python中加载.TIF文件,然后将其另存为RGB和NIR图像。

这是我使用/尝试过的代码:

%matplotlib notebook

import tifffile as tiff
import cv2
from matplotlib import pyplot as plt
import skimage.io
import numpy as np
import os
def load_images_from_folder(folder):
    images = []
    for filename in os.listdir(folder):
        img = None
        print(filename)
        if filename.endswith('.TIF'):
            img = cv2.imread(os.path.join(folder,filename), -1)
            #img = tiff.imread(os.path.join(folder,filename))
            #img = skimage.io.imread(os.path.join(folder,filename), plugin='tifffile')
        if img is not None:
            images.append(img)
            b,g,r,nir = cv2.split(img)
            image_rgb = np.stack([b,g,r], axis=2)

            nir_normalized = cv2.normalize(nir,None,0,255,cv2.NORM_MINMAX)
            image_rgb_normalized = cv2.normalize(image_rgb,None,0,255,cv2.NORM_MINMAX)

            skimage.io.imsave("satellite_imagery_split/" + filename[:-4] + "_nir_normalized.png", np.array(nir_normalized, dtype = np.uint8 )) 
            skimage.io.imsave("satellite_imagery_split/" + filename[:-4] + "_rgb_normalized.png", np.array(image_rgb_normalized, dtype = np.uint8 ))
            cv2.imwrite("satellite_imagery_split/" + filename[:-4] + "_nir_normalized.png", np.array(nir_normalized, dtype = np.uint8 )) 
            cv2.imwrite("satellite_imagery_split/" + filename[:-4] + "_rgb_normalized.png", np.array(image_rgb_normalized, dtype = np.uint8 ))

    return images

images = load_images_from_folder('satellite_imagery/')

,但没有任何变体可以正常工作。 使用OpenCV,我在整个图像上都有奇怪的条形:

OpenCV RGB image

对于tiff图像和scikit图像,如果具有这种怪异的色彩效果:

Tiff and scikit RGB image

我尝试使用上面的代码进行不同的组合,但是没有任何结果给我合适的结果。 但是非常奇怪的是,对于某些图像(20张中的2张),结果是预期的,因此RGB和NIR图像看起来正确,但是对于其他所有图像,我都遇到了这种奇怪的现象。

有人可以告诉我我做错了什么,因为我也使用Adobe Lightroom打开了所有图像,并且所有原始的四通道图像看起来都正确。

0 个答案:

没有答案
相关问题