필터 지우기
필터 지우기

How to save the cropped image as a RGB image?

조회 수: 1 (최근 30일)
sudha
sudha 2013년 8월 3일
This is the pgm for face detection...
% set mex file path for this platform ...
addpath(lower(computer));
% call without arguments to display help text ...
fprintf('\n--- fdlibmex help text ---\n');
fdlibmex
% load an example image
I = imread('foodcourt.jpg');
figure, imshow(I);
Img = rgb2gray(I);
% bw = im2bw(Img);
Image = im2uint8(Img);
figure, imshow(Image);
% run the detector
pos = fdlibmex(Image);
% display the image
figure, imagesc(Image)
colormap gray
axis image
axis off
% draw red boxes around the detected faces
hold on
for i=1:size(pos,1)
r = [pos(i,1)-pos(i,3)/2,pos(i,2)-pos(i,3)/2,pos(i,3),pos(i,3)];
display(r);
r(1) = r(1)- 10;
r(2) = r(2)- 20;
r(3) = r(3)+ 60;
r(4) = r(4)+ 70;
r = [r(1) r(2) r(3) r(4)];
rectangle('Position', r, 'EdgeColor', [1,0,0], 'linewidth', 2);
r = imcrop(Image,[r(1) r(2) r(3) r(4)]);
figure, imshow(r);
imsave;
end
hold off
% show stats
fprintf('\n--- fdlibmex example ---\n');
fprintf('\n\t%d faces detected in \''%s\'' (see figure 1)\n\n', ...
size(pos,1), imgfilename);
Using the values stored in 'r', i have cut out the detected faces individually from some rgb images, and i am getting all faces in grayscale which is obvious because of the rgb2gray function i have used.. But is there any way to get those cut out faces in rgb ?? How to retain its original rgb composition after running the fdlibmex ?? Can anyone plz help me out..

채택된 답변

Image Analyst
Image Analyst 2013년 8월 5일
Just use the original (badly-named) I instead of the version of it you converted to gray scale, (the also very badly-named) Image:
r = imcrop(I,[r(1) r(2) r(3) r(4)]);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Color Space Formatting and Conversions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by