how i can crop faces from image and save them in sub images ? any body can help me please.....
Show older comments
%% 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
Accepted Answer
More Answers (0)
Categories
Find more on Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!