zoukankan      html  css  js  c++  java
  • 伪彩映射

    python版的

    摘自:https://blog.csdn.net/guduruyu/article/details/60868501

     

    # -*- coding: utf-8 -*-
    """
    Created on Wed Apr 25 10:25:15 2018

    @author: Administrator
    """

    from matplotlib import cm  
    import numpy as np   
    from PIL import Image


        def get_jet():    #获取整型和浮点型的jet map
          
            colormap_int = np.zeros((256, 3), np.uint8)  
            colormap_float = np.zeros((256, 3), np.float)  
          
            for i in range(0, 256, 1):  
               colormap_float[i, 0] = cm.jet(i)[0]  
               colormap_float[i, 1] = cm.jet(i)[1]  
               colormap_float[i, 2] = cm.jet(i)[2]  
          
               colormap_int[i, 0] = np.int_(np.round(cm.jet(i)[0] * 255.0))  
               colormap_int[i, 1] = np.int_(np.round(cm.jet(i)[1] * 255.0))  
               colormap_int[i, 2] = np.int_(np.round(cm.jet(i)[2] * 255.0))  
          
            np.savetxt("jet_float.txt", colormap_float, fmt = "%f", delimiter = ' ', newline = ' ')  
            np.savetxt("jet_int.txt", colormap_int, fmt = "%d", delimiter = ' ', newline = ' ')  
          
            print colormap_int  
          
            return  
        
        
        def get_spectral():  #获取其他种类的  如:spectral map
     
        colormap_int = np.zeros((256, 3), np.uint8)  
        colormap_float = np.zeros((256, 3), np.float)  
     
        for i in range(0, 256, 1):  
           colormap_float[i, 0] = cm.spectral(i)[0]  
           colormap_float[i, 1] = cm.spectral(i)[1]  
           colormap_float[i, 2] = cm.spectral(i)[2]  
     
           colormap_int[i, 0] = np.int_(np.round(cm.spectral(i)[0] * 255.0))  
           colormap_int[i, 1] = np.int_(np.round(cm.spectral(i)[1] * 255.0))  
           colormap_int[i, 2] = np.int_(np.round(cm.spectral(i)[2] * 255.0))  
     
        np.savetxt("spectral_float.txt", colormap_float, fmt = "%f", delimiter = ' ', newline = ' ')  
        np.savetxt("spectral_int.txt", colormap_int, fmt = "%d", delimiter = ' ', newline = ' ')  
     
        print colormap_int  
     
        return


        def gray2color(gray_array, color_map):  #伪彩映射代码
              
            rows, cols = gray_array.shape  
            color_array = np.zeros((rows, cols, 3), np.uint8)  
          
            for i in range(0, rows):  
                for j in range(0, cols):  
                    color_array[i, j] = color_map[gray_array[i, j]]  
              
            #color_image = Image.fromarray(color_array)  
          
            return color_array  


        def test_gray2color():  #一个调用子程序
            gray_image = Image.open('Image.png').convert("L")    #
          
            gray_array = np.array(gray_image)  
              
            figure()  
            subplot(211)  
            plt.imshow(gray_array, cmap = 'gray')  
          
            jet_map = np.loadtxt('E:\Development\Thermal\ColorMaps\jet_int.txt', dtype = np.int)  
            color_jet = gray2color(gray_array, jet_map)  #调用了一个函数,,把一个数组进行彩色映射,
            subplot(212)                                 #做另一个画布
            plt.imshow(color_jet)                        #进行画图
            show()                                       #把图片显示出来
            return  



  • 相关阅读:
    Centos 7 开放查看端口 防火墙关闭打开
    idea将项目导出为war包
    webstorm 注册服务器
    centos 6.4系统双网卡绑定配置详解
    centos所有版本镜像下载地址
    浅谈Nginx负载均衡与F5的区别
    勒索病毒应急响应计划
    Python网络编程常用代码
    Flask debug 模式 PIN 码生成机制安全性研究笔记
    Pythonic定义
  • 原文地址:https://www.cnblogs.com/chulin/p/8944194.html
Copyright © 2011-2022 走看看