How to save the cropped image as a RGB image?

1 view (last 30 days)
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..

Accepted Answer

Image Analyst
Image Analyst on 5 Aug 2013
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)]);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!