convert IR image to RGB with python
Your noise looks like completely random values, so I suspect you have an error in your conversion from float
to uint8
. But instead of rolling everything for yourself, why don't you just use:
imOut = cv2.cvtColor(imIn,cv2.COLOR_GRAY2BGR)
Here is one way to do that in Python/OpenCV.
Your issue is likely that your channel values are exceeding the 8-bit range.
Sorry, I do not understand the relationship between your R,G,B weights and your MWIR. Dividing by MWIR will do nothing if your weights are properly normalized.
Input:
import cv2import numpy as np# read imageimg = cv2.imread('car.jpg')# convert to graygray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)# make color channelsred = gray.copy()green = gray.copy()blue = gray.copy()# set weightsR = .642G = .532B = .44MWIR = 4.5# get sum of weights and normalize them by the sumR = R**4G = G**4B = B**4sum = R + G + BR = R/sumG = G/sumB = B/sumprint(R,G,B)# combine channels with weightsred = (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 rangemax=np.amax(result)result = ((255/max)*result).clip(0,255).astype(np.uint8)# write result to diskcv2.imwrite("car_colored.png", result)# display itcv2.imshow("RESULT", result)cv2.waitKey(0)
Result