python 组合RGB和亮度图像以制作LRGB

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 组合RGB和亮度图像以制作LRGB相关的知识,希望对你有一定的参考价值。

# Created 2015, Zack Gainsforth
import matplotlib
matplotlib.use('Qt4Agg')
import matplotlib.pyplot as plt
import numpy as np
from skimage import filters
import sys
import warnings
with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    import tifffile as tif
    # Yeah, that's stupid huh?  tifffile always returns warnings so ignore them.

# This function combines the RGB and the luminance images to make the LRGB.
def CombineImages(lum, rgb, smooth=0):
    # Make an output image.
    q = np.copy(rgb)
    
    # If there is smoothing, then apply it.
    if smooth > 0:
        q[:,:,0] = filters.gaussian_filter(q[:,:,0], sigma=smooth)
        q[:,:,1] = filters.gaussian_filter(q[:,:,1], sigma=smooth)
        q[:,:,2] = filters.gaussian_filter(q[:,:,2], sigma=smooth)
        
    # Combine with the luminance image.
    q[:,:,0] *= lum
    q[:,:,1] *= lum
    q[:,:,2] *= lum
    
    #Normalize for 8-bit RGB (currently we are using floats).
    q[:,:,0] -= np.min(np.min(q[:,:,0]))
    q[:,:,1] -= np.min(np.min(q[:,:,1]))
    q[:,:,2] -= np.min(np.min(q[:,:,2]))
    q[:,:,0] /= np.max(np.max(q[:,:,0]))/255
    q[:,:,1] /= np.max(np.max(q[:,:,1]))/255
    q[:,:,2] /= np.max(np.max(q[:,:,2]))/255
    
    # Convert to 8-bit RGB and return both the raw float data and the 8-bit data.
    return q, q.astype('uint8')
    
if __name__ == '__main__':
    
    # Make sure the user typed the command line correctly.  Help him out if not.
    if len(sys.argv) != 4:
        print('Syntax:\npython MakeLRGB.py Luminance.tif RGB.tif n\n\nn is a number >= 0.0 and gives the 1-sigma length in pixels for a gaussian smoothing function applied to the RGB image before combining it with the luminance image.  0 means no smoothing.\n\nThe output is saved to LRGB.tif.')
        sys.exit()
        
    # Read in the input images.
    lum = tif.imread(sys.argv[1]).astype('float')
    rgb = tif.imread(sys.argv[2]).astype('float')
    
    # Make the LRGB.
    qf, qi = CombineImages(lum, rgb, smooth=float(sys.argv[3]))
    
    # Save the LRGB to disk.
    tif.imsave('LRGB.tif', qi)
    
    # Show it to the user.
    plt.imshow(qi)
    plt.show()
    

以上是关于python 组合RGB和亮度图像以制作LRGB的主要内容,如果未能解决你的问题,请参考以下文章

QHYCCD型号Q9进行LRGB拍摄操作记录

如何计算RGB数字图像处理 亮度的亮度值

视频编码原理

视频编码原理

视频编码原理

图像处理------调整亮度与对比度