Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Multiple cropping on the same image

Subject: Multiple cropping on the same image

From: Damien Gaillard

Date: 16 Mar, 2009 11:40:18

Message: 1 of 4

Hi!

I would like to create a code that opens all images from a file, show them one by one asking the user how many faces are visible and let him crop them manually before saving each cropped face in another file.

My problem is that as soon as I crop the first face, the image is closed by the left mouse double-click button even if I had specified that there were more than one face on this image.

Does anyone know how to keep the image open until the number of cropped faces correspond to the number entered in the interface?

Thanks a lot!

My Code is :

% Automatic opening of all images contained in the file
...

% "img" is the current image
% "faces" is the file containing all the images
% "Nom" is the name of the image

question = {'How many faces on this image ?'};
titre = 'Number of faces';
nb_ligne = 1;
defaut = {'1'};
image = inputdlg(question,titre,nb_ligne,defaut);
nb_vis = image{1};

for i=1:size(nb_vis)
    img2 = imcrop(img);
    imshow(img2);
    img3 = fullfile(faces,[Nom(1:end-4) '_' num2str(nb_vis) '.tif']);
    imwrite(img2,img3);
end

Subject: Multiple cropping on the same image

From: ImageAnalyst

Date: 16 Mar, 2009 12:42:50

Message: 2 of 4

Damien Gaillard:
You would have to create an image of zeros the same size as your
source image and then use the rect return value of imcrop. Then you'd
have to get the cropped image and then paste it in to the full size
image. When the last rectangle has been pasted in, then you'd find
the xmin, xmax, ymin, ymax (gotten from examining all the rect's that
were returned) to crop the full size image to the bounding box of the
multitide of the individual rectangles.
Regards,
ImageAnalyst

Subject: Multiple cropping on the same image

From: Damien Gaillard

Date: 16 Mar, 2009 14:12:13

Message: 3 of 4

> ImageAnalyst

Thanks for your answer, I'll try it A.S.A.P.

Regards,

Damien

Subject: Multiple cropping on the same image

From: Damien Gaillard

Date: 16 Mar, 2009 14:36:13

Message: 4 of 4

For those who'd be interested, I discovered the mistake in the code. It was simply to add i = str2num(interf), because the number entered was considered as a character and its lenght was always equals to 1.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us