Need help combining two 3 channel images into 6 channel image Python

2024/11/17 16:42:15

I am trying to combine two different RGB images into a single 6 channel image (Tiff is best) using nothing but Python.

What I have is an RGB image taken from a normal camera as well as another RGB image that is a normal map based on a SfM reconstruction. The images have identical dimensions and I simply need to overlay one image on the other so that I can run an image classification based on the combined channel information.

I've been looking into using openCV for this, but I'm getting hung up on the documentation. I'm a geologist, not a programmer so my math skills and programming knowledge is mediocre at best.

I've been doing some digging and what I've tried so far is using OpenCV to create an array for each image, then using numpy to concatenate the resulting matrices and using PIL to put them together into an image. Trouble is the image shows both images side by side or on top of one-another rather than as a 6 channel image.

I don't think PIL can do what I need it to do, but I'm not sure how to use the openCV mixChannels function or how to even create a MAT in Python as the Mat::create documentation is entirely in C++.

RGB Image

Normals Image

I've come across another thread on this site, but they weren't really answered either as far as I can tell:

See here

Answer

NumPy has you covered.

Your inputs are probably both shape (1200, 900, 3) (check with .shape), and you want (1200, 900, 6) as output - this is asking to concatenate the two arrays along the third axis. Therefore

np.concatenate((im1, im2), axis=2) # axes are 0-indexed, i.e. 0, 1, 2

will do precisely what you want.

https://en.xdnf.cn/q/71197.html

Related Q&A

Komodo Edit disable autocomple

I am using Komodo Edit 8 and its autocomplete feature is totally annoying. As soon as I type "for i" , it autofills in this:for i in range:codeNow i have to delete it manually to continue typ…

Python WeakKeyDictionary for unhashable types

As raised in cpython issue 88306, python WeakKeyDictionary fails for non hashable types. According to the discussion in the python issue above, this is an unnecessary restriction, using ids of the keys…

Django MPTT efficiently serializing relational data with DRF

I have a Category model that is a MPTT model. It is m2m to Group and I need to serialize the tree with related counts, imagine my Category tree is this:Root (related to 1 group)- Branch (related to 2 g…

Psycopg2: module object has no attribute connect [duplicate]

This question already has answers here:Importing a library from (or near) a script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError(4 answers…

matplotlib text not clipped

When drawing text in matplotlib with text(), and then interactively panning the image, the resulting drawn text is not clipped to the data window. This is counter to how plotting data or drawing text …

how to make child class call parent class __init__ automatically?

i had a class called CacheObject,and many class extend from it.now i need to add something common on all classes from this class so i write thisclass CacheObject(object):def __init__(self):self.updated…

Creating a dataframe in pandas by multiplying two series together

Say I have two series in pandas, series A and series B. How do I create a dataframe in which all of those values are multiplied together, i.e. with series A down the left hand side and series B along t…

UnicodeDecodeError in PyCharm debugger

Its a reference to UnicodeDecodeError while using cyryllic .I have same problem with Python 3.3 and Pycharm 2.7.2 Tryed to hardcode encoding in code, manually specifying encoding in Pycharm options, bu…

Scipy griddata with linear and cubic yields nan

the following code should produce griddata. But in case I choose as interpolation type cubic or linear I am getting nans in the z grid. Wen im choosing nearest everything is running fine. Here is an ex…

Clone a module and make changes to the copy

Is it possible to copy a module, and then make changes to the copy? To phrase another way, can I inherit from a module, and then override or modify parts of it?