【发布时间】:2016-03-17 14:23:37
【问题描述】:
我正在使用 skimage.transform.resize 调整图像大小,但我得到了一个非常奇怪的输出,我不知道为什么。有人可以帮忙吗?
这是我的代码:
import matplotlib.pyplot as plt
import skimage.transform
plt.imshow(y)
h,w,c = y.shape
x = skimage.transform.resize(y, (256, (w*256)/h), preserve_range=True)
plt.imshow(x)
这是我的输入图像 y (240, 320, 3):
这是我的输出图像 x (256, 341, 3):
编辑:
好的,如果我更改 preserve_range=False,它似乎工作正常。但为什么它不允许我保持当前范围?
编辑: 我正在使用 OpenCV 从视频中随机抽样帧。这是从我传递给它的视频路径返回一帧的函数。
def read_random_frames(vid_file):
vid = cv2.VideoCapture(vid_file)
# get the number of frames
num_frames = vid.get(cv2.CAP_PROP_FRAME_COUNT)
# randomly select frame
p_frame = random.randint(0, (num_frames-1))
# get frame
vid.set(cv2.CAP_PROP_POS_FRAMES, p_frame)
ret, frame = vid.read()
# convert from BGR to RGB
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
return frame
我有一个视频路径列表,我使用 map 函数检索帧,然后将输出的列表转换为 numpy 数组:
batch_frames = map(lambda vid: read_random_frames(vid), train_vids_batch)
frame_tensor = np.asarray(batch_frames)
y = frame_tensor[0]
【问题讨论】:
标签: python matplotlib scikit-image