Source code for pyfusion.HIS

import cv2
import numpy as np
from copy import deepcopy
from .utils import histMatch, Image

from osgeo import gdal, gdalconst
from osgeo import osr


[docs]def HIS(src:Image, pan:Image): """Using HIS method to fusion the image The `source` image should not be upsampled :param src: `source` image, it should be `pyfusion.utils.Image` type :param pan: Panchromatic image, the image should be grayscale :return: fusion image :rtype: `pyfusion.utils.Image` """ assert src.image.RasterCount == 3, "src image should be 3 bands" assert pan.image.RasterCount == 1, "pan image should be 1 band" # use VRT to create result image driver = gdal.GetDriverByName("VRT") dstDs = driver.Create("", pan.image.RasterXSize, pan.image.RasterYSize, 3, options=["INTERLEAVE=PIXEL"]) dstImage = Image(dstDs) dstImage.data = _HIS(src.data, pan.data) return dstImage
def _HIS(src, pan): """Using HIS method to fusion the image The `source` image should not be upsampled :param src: `source` image, the image should be BGR color space :param pan: Panchromatic image, the image should be grayscale :return: fusion image :rtype: `numpy.ndarray` """ # upsamply the image img_rgb = cv2.resize(src, tuple(reversed(pan.shape))) # convert the color space img_HLS = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2HLS) # histogram match dst_pan = histMatch(pan, img_HLS[:,:,1]) # merge the new image img_fusion_HLS = cv2.merge((img_HLS[:,:,0], dst_pan, img_HLS[:,:,2])) del img_HLS del dst_pan # convert color space img_fusion_BGR = cv2.cvtColor(img_fusion_HLS, cv2.COLOR_HLS2BGR) return img_fusion_BGR