有没有人有一种在Python中导入每通道16位,3通道TIFF图像的方法?
我还没有找到一种方法,在处理TIFF格式时会保留每个通道的16位深度.我希望一些有用的灵魂能有解决方案.
以下列出了迄今为止我没有成功的尝试和结果:
import numpy as np
import PIL.Image as Image
import libtiff
import cv2
im = Image.open('a.tif')
# IOError: cannot identify image file
tif = libtiff.TIFF.open('a.tif')
im = tif.read_image()
# im only contains one of the three channels. im.dtype is uint16 as desired.
im = []
for i in tif.iter_images():
# still only returns one channel
im = np.array(cv2.imread('a.tif'))
# im.dtype is uint8 and not uint16 as desired.
# specifying dtype as uint16 does not correct this
Run Code Online (Sandbox Code Playgroud)
到目前为止,我找到的唯一解决方案是使用ImageMagick将图像转换为PNG.然后沼泽标准matplotlib.pyplot.imread …
我有下面的数字向量模板类(用于数值计算的向量).我正在努力编写D=A+B+C
所有变量都是Vector
对象的地方.A
,B
并且C
不应该修改.我的想法是使用,Vector operator+(Vector&& B)
以便在(希望)Vector
返回Rvalue之后B+C
,所有后续添加都存储在该对象中,即为所有后续添加窃取Rvalue的存储.这是为了消除新对象的创建和所需的存储.
我的问题是,我可以从调用的每个函数的输出语句中看到,Vector operator+(Vector&& B)
从未调用过.我不明白为什么,因为,如果我有一个重载虚拟函数foo(Vector& B)
与foo(Vector&& B)
和尝试foo(A+B+C)
,那么第二个功能是完全相同称为我所希望的.
很抱歉这个冗长的问题,但这是我在这里的第一个问题,我想尽量保持清醒.
关于我明显做错了什么或为什么我不应该尝试这个的任何建议,将不胜感激.
template <typename T>
class Vector
{
int n;
T* v;
Vector();
~Vector();
Vector(const Vector& B);
Vector(Vector&& B);
inline Vector operator+(const Vector& B) const;
inline Vector operator+(Vector&& B) const;
};
template <typename T>
Vector<T>::Vector(const Vector<T>& B)
{
...
}
template <typename T>
Vector<T>::Vector(Vector<T>&& B)
{
...
} …
Run Code Online (Sandbox Code Playgroud)