Pyro
Pyro

Reputation: 17

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.

Is there any other function or method that I can use?

Upvotes: 0

Views: 319

Answers (2)

NKN
NKN

Reputation: 6434

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. However, you can copy it to another variable or write it as an image using 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

Upvotes: 1

Santhan Salai
Santhan Salai

Reputation: 3898

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.

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. You should avoid doing this.

Upvotes: 3

Related Questions