如何将使用 imcrop 裁剪的图像导入变量?

How can I imread the image that I cropped with imcrop into a variable?

我试过了,但失败了;

Face = imcrop(I, bboxes(1,:));
TestImage = imread(Face);

这是错误。

Error using imread>parse_inputs (line 457).The filename or url argument must be a string.

还有其他功能或方法可以使用吗?

为了读取图像,它应该以图像文件的形式存在。为此,首先,您应该使用 imwrite 将图像矩阵保存到图像文件中,然后您可以使用 imread.

试试这个:

Face = imcrop(I, bboxes(1,:));      %// Your code
imwrite(Face,'Face.jpg');           %// saving in default path
TestImage = imread('Face.jpg');     %// reading with same filename & default path

另请注意,这样做是没有意义的,因为 FaceTestImage 具有相同的值。你应该避免这样做。

你试图做的事情没有意义,因为你已经把图片读入了Face变量,你不需要再读一遍。但是,您可以将其复制到另一个变量或使用 imwrite.

将其作为图像写入
Face = imread('circuit.tif');            % read the file into the face variable
croppedFace = imcrop(I,[75 68 130 112]); % crop the image and save it in a new variable