基本上,我认为处理热像素的最快方法就是使用size=2中值滤波器。然后,噗,你的热像素消失了,你还杀死了其他各种高频传感器噪音从你的相机。

如果您真的只想删除热像素,那么替换时可以从原始图像中减去中值滤波器,就像我在问题中所做的那样,只将这些值替换为中值滤波图像中的值。这在边上不起作用,所以如果你可以忽略沿边的像素,那么这将使事情容易得多。

如果要处理边,可以使用下面的代码。但是,它不是最快的:import numpy as np

import matplotlib.pyplot as plt

import scipy.ndimage

plt.figure(figsize=(10,5))

ax1 = plt.subplot(121)

ax2 = plt.subplot(122)

#make some sample data

x = np.linspace(-5,5,200)

X,Y = np.meshgrid(x,x)

Z = 100*np.cos(np.sqrt(x**2 + Y**2))**2 + 50

np.random.seed(1)

for i in range(0,11):

#Add some hot pixels

Z[np.random.randint(low=0,high=199),np.random.randint(low=0,high=199)]= np.random.randint(low=200,high=255)

#and dead pixels

Z[np.random.randint(low=0,high=199),np.random.randint(low=0,high=199)]= np.random.randint(low=0,high=10)

#And some hot pixels in the corners and edges

Z[0,0] =255

Z[-1,-1] =255

Z[-1,0] =255

Z[0,-1] =255

Z[0,100] =255

Z[-1,100]=255

Z[100,0] =255

Z[100,-1]=255

#Then plot it

ax1.set_title('Raw data with hot pixels')

ax1.imshow(Z,interpolation='nearest',origin='lower')

def find_outlier_pixels(data,tolerance=3,worry_about_edges=True):

#This function finds the hot or dead pixels in a 2D dataset.

#tolerance is the number of standard deviations used to cutoff the hot pixels

#If you want to ignore the edges and greatly speed up the code, then set

#worry_about_edges to False.

#

#The function returns a list of hot pixels and also an image with with hot pixels removed

from scipy.ndimage import median_filter

blurred = median_filter(Z, size=2)

difference = data - blurred

threshold = 10*np.std(difference)

#find the hot pixels, but ignore the edges

hot_pixels = np.nonzero((np.abs(difference[1:-1,1:-1])>threshold) )

hot_pixels = np.array(hot_pixels) + 1 #because we ignored the first row and first column

fixed_image = np.copy(data) #This is the image with the hot pixels removed

for y,x in zip(hot_pixels[0],hot_pixels[1]):

fixed_image[y,x]=blurred[y,x]

if worry_about_edges == True:

height,width = np.shape(data)

###Now get the pixels on the edges (but not the corners)###

#left and right sides

for index in range(1,height-1):

#left side:

med = np.median(data[index-1:index+2,0:2])

diff = np.abs(data[index,0] - med)

if diff>threshold:

hot_pixels = np.hstack(( hot_pixels, [[index],[0]] ))

fixed_image[index,0] = med

#right side:

med = np.median(data[index-1:index+2,-2:])

diff = np.abs(data[index,-1] - med)

if diff>threshold:

hot_pixels = np.hstack(( hot_pixels, [[index],[width-1]] ))

fixed_image[index,-1] = med

#Then the top and bottom

for index in range(1,width-1):

#bottom:

med = np.median(data[0:2,index-1:index+2])

diff = np.abs(data[0,index] - med)

if diff>threshold:

hot_pixels = np.hstack(( hot_pixels, [[0],[index]] ))

fixed_image[0,index] = med

#top:

med = np.median(data[-2:,index-1:index+2])

diff = np.abs(data[-1,index] - med)

if diff>threshold:

hot_pixels = np.hstack(( hot_pixels, [[height-1],[index]] ))

fixed_image[-1,index] = med

###Then the corners###

#bottom left

med = np.median(data[0:2,0:2])

diff = np.abs(data[0,0] - med)

if diff>threshold:

hot_pixels = np.hstack(( hot_pixels, [[0],[0]] ))

fixed_image[0,0] = med

#bottom right

med = np.median(data[0:2,-2:])

diff = np.abs(data[0,-1] - med)

if diff>threshold:

hot_pixels = np.hstack(( hot_pixels, [[0],[width-1]] ))

fixed_image[0,-1] = med

#top left

med = np.median(data[-2:,0:2])

diff = np.abs(data[-1,0] - med)

if diff>threshold:

hot_pixels = np.hstack(( hot_pixels, [[height-1],[0]] ))

fixed_image[-1,0] = med

#top right

med = np.median(data[-2:,-2:])

diff = np.abs(data[-1,-1] - med)

if diff>threshold:

hot_pixels = np.hstack(( hot_pixels, [[height-1],[width-1]] ))

fixed_image[-1,-1] = med

return hot_pixels,fixed_image

hot_pixels,fixed_image = find_outlier_pixels(Z)

for y,x in zip(hot_pixels[0],hot_pixels[1]):

ax1.plot(x,y,'ro',mfc='none',mec='r',ms=10)

ax1.set_xlim(0,200)

ax1.set_ylim(0,200)

ax2.set_title('Image with hot pixels removed')

ax2.imshow(fixed_image,interpolation='nearest',origin='lower',clim=(0,255))

plt.show()

输出:

python热成像_在python中自动从图像中移除热/死像素相关推荐

  1. 第一章 第一节:Python基础_认识Python

    Python基础入门(全套保姆级教程) 第一章 第一节:Python基础_认识Python 1. 什么是编程 通俗易懂,编程就是用代码编写程序,编写程序有很多种办法,像c语言,javaPython语言 ...

  2. python 聚类_使用python+sklearn实现聚类性能评估中随机分配对聚类度量值的影响

    注意:单击此处https://urlify.cn/3iAzUr下载完整的示例代码,或通过Binder在浏览器中运行此示例 下图说明了聚类数量和样本数量对各种聚类性能评估度量指标的影响.未调整的度量指标 ...

  3. python声明_在Python中什么是全局声明?

    python中的每个"变量"都限于某个范围. python"文件"的范围是模块范围.考虑以下: #file test.py myvariable = 5 # m ...

  4. Python的Crypto模块使用:自动输入Shell中的密码

    概述: 现在我们已经越来越多地使用程序去代替人工执行一些操作(比如说,安装一些软件.登录一些服务等等),可是这些操作又有很多的情况是要和人之间进行互动(比如说输入一些yes or no.输入密码.输入 ...

  5. java执行python脚本_使用Runtime.getRuntime().exec()在java中调用python脚本

    举例有一个Python脚本叫test.py,现在想要在Java里调用这个脚本.假定这个test.py里面使用了拓展的包,使得pythoninterpreter之类内嵌的编译器无法使用,那么只能采用ja ...

  6. python 示例_在Python中带有示例的while关键字

    python 示例 关键字的Python (Python for keyword) while is a keyword (case-sensitive) in python, it is used ...

  7. shell运行python文件_在python shell中运行python文件的实现

    在python shell中运行python文件的实现 最近在学习flask开发,写好程序后需要在python shell中运行测试功能.专门抽时间研究了下,总结以防止以后遗忘. 这是测试文件的结构, ...

  8. svd降维 python案例_菜菜的机器学习sklearn实战-----sklearn中的降维算法PCA和SVD

    菜菜的机器学习sklearn实战-----sklearn中的降维算法PCA和SVD 概述 从什么叫维度说开来 简单讲,shape中返回了几个数字就是几维. 一张表最多就是一维 当一个数组中存在2张3行 ...

  9. 树莓派智能小车python论文_基于树莓派的自动驾驶小车,利用树莓派和tensorflow实现小车在赛道的自动驾驶...

    self_drive 基于树莓派的人工智能自动驾驶小车 Artificial intelligence automatic driving car based on raspberry pie git ...

最新文章

  1. C盘下什么文件能删除?
  2. Vue实现仿音乐播放器12-实现歌手页面效果
  3. Debug Tensorflow: Object was never used (type <class ‘tensorflow.python.ops.tensor_array_ops.TensorA
  4. 每天学点Python之collections
  5. oracle 会话实例,返璞归真:Oracle实例级别和会话级别的参数设置辨析
  6. 文件的输入/输出操作
  7. (转)代理模式(Proxy)
  8. C++primer第八章 IO库 8.2 文件输入输出
  9. (王道408考研数据结构)第六章图-第四节6:拓扑排序(AOV网、代码、排序规则)
  10. 求最大公约数和最小公倍数简洁写法的注意事项
  11. conda: command not found
  12. 推荐系统的主要算法(1)
  13. 消费者生产者问题,哲学家问题
  14. 仿网易严选Flutter项目
  15. c语言如何添加程序图标,如何给C控制台程序添加图标
  16. JAVA-CPU飙高问题排查
  17. Windows10系统如何多开微信程序(上班划水必备)
  18. 树莓4派开机动画_最贵的树莓派单板计算机!8GB内存单板树莓派4上市,售价532元...
  19. android定位二(百度定位SDK)
  20. 【网络教程】群晖安装甜糖最新教程,手把手教您在Docker中安装官方甜糖

热门文章

  1. matlab设计译码器,基于MATLAB的循环码编译码器设计与仿真.doc
  2. uniformRowHeights属性
  3. python 获取向上两级路径_全国计算机二级Python真题解析-1
  4. linux进程通信ips,Cisco IPS 分析引擎拒绝服务漏洞(CVE-2014-0718)
  5. nginx通过lua从日志中获得请求响应体
  6. 2017年哪些网络安全威胁不容忽视?
  7. ( ̄▽ ̄) 关于河北ETC记账卡的默认密码
  8. 看完这些福利才知道,为什么说双12一定要出去浪
  9. CSS拉伸resize
  10. 【资料整理】一些英语面试题整理