zoukankan      html  css  js  c++  java
  • 合并几张图

    def awesome_plot(rgb_and_grey):
        """
        注意!输入是一个tuple!!函数的输入输出装进tuple里面比较安全。
        画图函数:输入几张图片(可以彩色或者灰色, 也可以是不同size), 拼成一张图片, HWC
    
        :param rgb_and_grey: tuple[0]:img, tuple[1]:gd, tuple[2]:pred ...
        :return: stacked ndarray
        """
        if not isinstance(rgb_and_grey, tuple) or len(rgb_and_grey) <=1 :
            raise  ValueError("input must be a tuple with len > 2")
        pics_list = []
        for pic in rgb_and_grey:
            if len(pic.shape) == 2:
                pic = pic.repeat(3).reshape(pic.shape[0], pic.shape[1], 3)
                pic = cv2.resize(pic, (320, 256))
                pics_list.append(pic)
            elif len(pic.shape) == 3:
                if pic.shape[2] == 3:
                    pic = cv2.resize(pic, (320, 256))
                    pics_list.append(pic)
                else:
                    raise ValueError("input format must be HxWxC and C must be 3!")
            else:
                raise ValueError("wrong input: must be pics")
    
        # print("stacking ", len(pics_list), " pics~")
    
        if len(pics_list) == 2:
            res = np.hstack((pics_list[0], pics_list[1]))
            return res
        elif len(pics_list) == 3:
            res = np.hstack((pics_list[0], pics_list[1], pics_list[2]))
            return res
        elif len(pics_list) == 4:
            row1 = np.hstack((pics_list[0], pics_list[1]))
            row2 = np.hstack((pics_list[2], pics_list[3]))
            res = np.vstack((row1, row2))
            return res
        elif len(pics_list) == 6:
            row1 = np.hstack((pics_list[0], pics_list[1], pics_list[2]))
            row2 = np.hstack((pics_list[3], pics_list[4], pics_list[5]))
            # row3 = np.hstack((pics_list[4], pics_list[5]))
            res = np.vstack((row1, row2))
            return res
        else:
            raise ValueError("too man pics( more than 6)")
    
  • 相关阅读:
    python数据分析与展示
    人生苦短,我学python。
    数学
    解决git for windows 和 vim for windows 的 vim 显示中文乱码的问题
    解决win7连接IPsec报错789和809错误
    python安装pandas库
    vim配置文件
    0x03-数据和C
    Ubutun安装问题记录
    Django-rest-framework --- 三大认证
  • 原文地址:https://www.cnblogs.com/theodoric008/p/9121238.html
Copyright © 2011-2022 走看看