Is it possible to convert RGB image to RGB+NIR image?
Asked
Active
Viewed 331 times
-3
-
Does this help? https://stackoverflow.com/a/58900493/2681662 – MSH Oct 30 '21 at 19:00
-
Please provide enough code so others can better understand or reproduce the problem. – Community Oct 31 '21 at 03:44
1 Answers
1
You can use OpenCV like this:
import cv2
fourChannel = cv2.cvtColor(threeChannel, cv2.COLOR_RGB2RGBA)
Or you can use Numpy to make a new, empty channel of same size and type as your original, and stack it onto your 3 channel image:
import numpy as np
newEmpty = np.zeros_like(threeChannel[...,0])
fourChannel = np.dstack((threeChannel, newEmpty))

Mark Setchell
- 191,897
- 31
- 273
- 432
-
The Second Method you shared worked for me, At least my code is accepting the images i converted from 3 channel to 4 channel. can you explain what is the 4th channel in your method, Is it all zeros? – Muhammad Salman Nov 01 '21 at 09:36
-
Yes ,the fourth channel is all zeroes. You can add 255 to it if you want to fill it with that value. – Mark Setchell Nov 01 '21 at 10:38
-
if i want to fill the new channel with any other value in float or double the ho can i do that? – Muhammad Salman Nov 01 '21 at 16:41
-
You can use `fourChannel[..., 3] = 127` to fill the new channel with the value 127. – Mark Setchell Nov 01 '21 at 17:28