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

조회 수: 1 (최근 30일)
%% 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

채택된 답변

Image Analyst
Image Analyst 2013년 5월 1일
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
Image Analyst
Image Analyst 2013년 5월 1일
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);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by