简体   繁体   English

如何将用裁剪裁剪的图像读入变量?

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

I've tried this but it failed; 我已经尝试过了,但是失败了。

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

This is the error. 这是错误。

Error using imread>parse_inputs (line 457).The filename or url argument must be a string. 使用imread> parse_inputs时出错(第457行)。filename或url参数必须为字符串。

Is there any other function or method that I can use? 还有其他可以使用的功能或方法吗?

In order to read an image, it should be present as an image file. 为了读取图像,它应该作为图像文件存在。 For that, first, you should use imwrite to save your image matrix into an image file, then you could use imread . 为此,首先,应使用imwrite将图像矩阵保存到图像文件中,然后可以使用imread

Try this: 尝试这个:

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

Also note that doing this is meaningless because, both Face and TestImage have the same values. 还要注意,这样做是没有意义的,因为FaceTestImage都具有相同的值。 You should avoid doing this. 您应该避免这样做。

What you are trying to do has no meaning, because you have already read the image into the Face variable, and you do not need to read it again. 您尝试执行的操作没有任何意义,因为您已经将图像读入Face变量,并且无需再次读取。 However, you can copy it to another variable or write it as an image using imwrite . 但是,您可以将其复制到另一个变量,或使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM