用python将红外图像转换为RGB

问题描述 投票:0回答:1

下面的代码旨在将红外图像(B&W)转换为RGB。它成功地做到了这一点,但有明显的噪音。我加入了一些降噪的行,但似乎没有帮助。我已经包括了下面的起始resulting照片。欢迎任何建议和更正,并提前感谢你!

from skimage import io
import numpy as np
import glob, os
from tkinter import Tk
from tkinter.filedialog import askdirectory
import cv2

path = askdirectory(title='Select PNG Folder') # shows dialog box and return the path
outpath = askdirectory(title='Select SAVE Folder') 

# wavelength in microns
MWIR = 4.5

R = .642
G = .532
B = .44

vector = [R, G, B]
vectorsum = np.sum(vector)
vector = vector / vectorsum #normalize
vector = vector*255 / MWIR #changing this value changes the outcome significantly so I 
#have been messing with it in the hopes of fixing it but no luck so far.
vector = np.power(vector, 4)

for file in os.listdir(path):
  if file.endswith(".png"):
    imIn = io.imread(os.path.join(path, file))
    imOut = imIn * vector
    ret,thresh = cv2.threshold(imOut,64,255,cv2.THRESH_BINARY)
    kernel = np.ones((5, 5), np.uint8)
    erode = cv2.erode(thresh, kernel, iterations = 1)
    result = cv2.bitwise_or(imOut, erode)
    io.imsave(os.path.join(outpath, file) + '_RGB.png',imOut.astype(np.uint8))

starting imageresult image

python numpy opencv tkinter scikit-image
1个回答
0
投票

如果噪声来自传感器本身,如颗粒状的噪声,你将需要研究去噪算法。scikit-imageopencv 提供了一些去噪算法,你可以试试。也许你可以看看 这个这个.


0
投票

你的噪声看起来像完全随机的值,所以我怀疑你在转换从 floatuint8. 但与其自己滚动一切,为什么不直接使用。

  imOut = cv2.cvtColor(imIn,cv2.COLOR_GRAY2BGR)

0
投票

这里是PythonOpenCV中的一种方法。

你的问题可能是你的通道值超过了8位范围。

对不起,我不明白你的R,G,B权重和MWIR之间的关系。如果您的权重已经正确地归一化,除以 MWIR 将毫无作用。

输入。

enter image description here

import cv2
import numpy as np

# read image
img = cv2.imread('car.jpg')

# convert to gray
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# make color channels
red = gray.copy()
green = gray.copy()
blue = gray.copy()

# set weights
R = .642
G = .532
B = .44

MWIR = 4.5

# get sum of weights and normalize them by the sum
R = R**4
G = G**4
B = B**4
sum = R + G + B
R = R/sum
G = G/sum
B = B/sum
print(R,G,B)

# combine channels with weights
red = (R*red)
green = (G*green)
blue = (B*blue)
result = cv2.merge([red,green,blue])

# scale by ratio of 255/max to increase to fully dynamic range
max=np.amax(result)
result = ((255/max)*result).clip(0,255).astype(np.uint8)

# write result to disk
cv2.imwrite("car_colored.png", result)

# display it
cv2.imshow("RESULT", result)
cv2.waitKey(0)

结果

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.