日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2023/12/15 python 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python热成像_在python中自动从图像中移除热/死像素 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

基本上,我認為處理熱像素的最快方法就是使用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中自动从图像中移除热/死像素的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。