我正在尝试skimage.io.imread()
一张先前写入tempfile.TemporaryFile()
的图片(比如一个tiff文件,具体而言)。但是,skimage
抱怨说
ValueError: Cannot determine type of file b'<_io.BufferedRandom name=6>'
我这样做是因为另一个程序将图像写入标准输出。
我用subprocess.check_output
收集它并将其写入临时文件,从而避免将图像保存到磁盘。
有谁知道如何实现这一目标,或者更好地了解如何将图像从stdout传输到python图像,最终被视为numpy.ndarray
?
答案 0 :(得分:0)
解决方案如下
clear
clc
close all
xyloObj = VideoReader('xylophone.mp4');
imageData = read(xyloObj);
%// Open writer object
writerObj = VideoWriter('NewVideo.avi');
open(writerObj);
%// Show 1st frame
hIm = imshow(imageData(:,:,:,1));
for k = 1:size(imageData,4)
%// Change pixel values
imageData(1:200,1:200,:,k) = uint8(0);
%// Refresh cdata property. Faster than calling repetitevely imshow
set(hIm,'CData',imageData(:,:,:,k));
drawnow
frame = getframe;
%// Write to video file
writeVideo(writerObj,frame);
end
close(writerObj);
或者,可以用with NamedTemporaryFile() as f:
skimage.io.imread(f.name, plugin="tifffile")
替换freeimage
。
之前我传递的是文件对象,但tifffile
实际上想要一个文件名。