判断一幅图像是否是红外的python程序

    技术2023-11-11  73

          判断一幅图像是否是红外还是可见光,直接在rgb颜色空间不好弄,需要转化到hsv空间进行判别,具体就是统计s通道的值是否为0或接近0,这样一来可以直接加和s通道的值,然后取个均值,最后给个阈值,当这个均值小于给定阈值时,就可以认为这幅图像就是红外的,具体python程序如下:

    import os,sys import numpy as np def judgeimingmode(impath): infraredthresh=10 im = cv2.imread(impath) if im is None: print(impath) return None imshape = im.shape hsvim = cv2.cvtColor(im, cv2.COLOR_BGR2HSV) schannelmeanval = np.sum(hsvim[:, :, 1]) / (imshape[0] * imshape[1]) if schannelmeanval < infraredthresh: imagingmode = 'hongwai' else: imagingmode = 'kejianguang' # print('{} imagingmode={}'.format(impath, imagingmode)) return imagingmode

     

    Processed: 0.009, SQL: 10