在 Python 中调用来自 (488, 648, 300) <类"元组">的一个图像



我对在Python中从图像集合中调用图像有一点怀疑。

这个想法就像我们如何加载'。matlab中的Mat文件和通过matlab中的简单命令行调用一个图像(如下示例):

load('psi0V.mat');
imagedat=psi;
imagedat=squeeze(imagedat);
I = imagedat(:, :, 1);
imagesc(I)

我正在Python中尝试类似的东西,但我无法从所有图像中调用一个图像。我尝试了所有的可能性,但都没有成功。

Python代码:

import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
from scipy.io import loadmat
data = loadmat(r"F:second_yearCodePython_pixelinfopsi0V.mat")
imagedata = data["psi"]
image = np.squeeze(imagedata)
image = np.shape(image)
I = image[:, :, 1]
print(image)
print(type(image))

错误:

============ RESTART: F:second_yearCodePython_pixelinfopixel.py ============
(488, 648, 300)
<class 'tuple'>
============ RESTART: F:second_yearCodePython_pixelinfopixel.py ============
Traceback (most recent call last):
File "F:second_yearCodePython_pixelinfopixel.py", line 11, in <module>
I = image[:, :, 1]
TypeError: tuple indices must be integers or slices, not tuple

请建议。谢谢。

错误是由于这一行。

image = np.shape(image)

您正在将image的值更改为与其形状相同的tuple

并与Matlab进行比较代码,我认为它甚至不应该在那里。

最新更新