how i can crop faces from image and save them in sub images ? any body can help me please.....

Asked by moniba qureshi about 23 hours ago
Latest activity Commented on by Image Analyst about 10 hours ago

%% Step1: Equalization clear all; clc; rgbInputImage = imread('image2.jpg'); % rgbInputImage=getsnapshot(rgbInputImage); labInputImage = applycform(rgbInputImage,makecform('srgb2lab')); Lbpdfhe = fcnBPDFHE(labInputImage(:,:,1)); labOutputImage = cat(3,Lbpdfhe,labInputImage(:,:,2),labInputImage(:,:,3)); rgbOutputImage = applycform(labOutputImage,makecform('lab2srgb')); figure, imshow(rgbInputImage); %image1 figure, imshow(rgbOutputImage); %image2 img = rgbOutputImage; final_image = zeros(size(img,1), size(img,2));

%% Step2: Skin Detection if(size(img, 3) > 1) for i = 1:size(img,1) for j = 1:size(img,2) R = img(i,j,1); G = img(i,j,2); B = img(i,j,3); if(R > 92 && G > 40 && B > 20) v = [R,G,B]; if((max(v) - min(v)) > 15) if(abs(R-G) > 15 && R > G && R > B) %it is a skin final_image(i,j) = 1; end end end end end end figure, imshow(final_image); %image3

%% Step3: Grayscale To Binary. binaryImage=im2bw(final_image,0.6); figure, imshow(binaryImage); %image4

% Filling The Holes. binaryImage = imfill(binaryImage, 'holes'); figure, imshow(binaryImage); %image5

%% Step 4 binaryImage = bwareaopen(binaryImage,1890); figure,imshow(binaryImage); %image6 se = strel('disk', 100, 8); %se = strel('arbitrary', NHOOD); %se = strel('ball',1,1); binaryImage1 = imdilate(binaryImage,se); %imshow(bw), title('Original') figure, imshow(binaryImage1), title('Dilated'); %binaryImage=imdilate(binaryImage,se); %figure,imshow(binaryImage); %image7

labeledImage = bwlabel(binaryImage, 8); blobMeasurements = regionprops(labeledImage, final_image, 'all'); numberOfPeople = size(blobMeasurements, 1); imagesc(rgbInputImage); title('Outlines, from bwboundaries()'); %axis square;

hold on;

%imagesc(rgbInputImage); title('Original with bounding boxes'); fprintf(1,'Blob # x1 x2 y1 y2\n'); for k = 1 : numberOfPeople % Loop through all blobs. % Find the mean of each blob. (R2008a has a better way where you can pass the original image % directly into regionprops. The way below works for all versionsincluding earlier versions.) thisBlobsBox = blobMeasurements(k).BoundingBox; % Get list of pixels in current blob. x1 = thisBlobsBox(1); y1 = thisBlobsBox(2); x2 = x1 + thisBlobsBox(3); y2 = y1 + thisBlobsBox(4);

    % fprintf(1,'#%d %.1f %.1f %.1f %.1f\n', k, x1, x2, y1, y2);
    x = [x1 x2 x2 x1 x1];
    y = [y1 y1 y2 y2 y1];
    %subplot(3,4,2);
    plot(x, y, 'LineWidth',2 ,'color', 'green');
    figure, imshow(imcrop(final_image,[x1,y1,x2,y2]));
end

0 Comments

moniba qureshi

Tags

No tags are associated with this question.

1 Answer

Answer by Image Analyst about 21 hours ago

Looks like you know about imcrop(). So all you have to do is to save that cropped image and call imwrite, so instead of

imshow(imcrop(final_image,[x1,y1,x2,y2]));

You do this:

croppedImage = imcrop(final_image,[x1,y1,x2,y2]));
imwrite(fullFileName, croppedImage);

2 Comments

moniba qureshi about 13 hours ago

im not clear about fullFileName...... ?

Image Analyst about 10 hours ago

It's the full file name of the file on disk where you want to store it. That's the folder plus basefilename plus extension. Let's say that you wanted the file to be called "output image.png" and wanted it to be in folder c:\users\moniba\documents\images, you'd do

baseFileName = 'output image.png';
folder = 'c:\users\moniba\documents\images';
fullFileName = fullfile(folder, baseFileName);
imwrite(fullFileName, croppedImage);

Or of course you could just hard code it in:

imwrite('c:\users\moniba\documents\images\output image.png', croppedImage);
Image Analyst

Contact us