Accepted Answer

Image Analyst
Image Analyst on 29 Aug 2017
To draw a rectangle, you can use rectangle(), plot(), line(), rbbox(), or imrect() depending on what you mean by "draw a rectangle".
You might also be interested in bwareafilt() to extract blobs of certain areas (like only the largest blob), and imfill() to fill in black islands in the white blobs.

6 Comments

I want to find the potential face region, using a whites pixels.
The problem of using bwareafilt () is that my image is not binary, it is the Cr component (YCbCr model) since it is easier to detect the human skin in this model.
Ok, I made the binary image, I'll see if it works with bwareafilt (), I'll tell you something.
Many thanks for your help, now the next step is to find the dots to draw a rectangle.
The reason for this, I am working on a script that detects the face.
What "dots" are you talking about? And exactly what does "find" mean to you? Do you mean you want the (x,y) coordinates of the "dots" for some reason? Or do you want the bounding box of the blob?
It's done! I wanted to find the bounding box of the blob and I did it using regionprops, thanks for your help.
Glad I could help - thanks for accepting. For any others looking at this, to get the bounding box:
labeledImage = bwlabel(binaryImage);
props = regionprops(labeledImage, 'BoundingBox');
boundingBox = props.BoundingBox;
% Display it.
hold on;
rectangle('Position', boundingBox, 'EdgeColor', 'r');

Sign in to comment.

More Answers (2)

Total white area within the image
%
nWhite_pixels=sum(face_image(:));
[rows columns depth]=size(face_image);
percentage_of_white_area=(nWhite_pixels/(rows*columns))*100;
disp(percentage_of_white_area);
%

2 Comments

what is face_image(:) and what is the function of this line.. can anyone explaining about it..
In that code, face_image is the binary image mask, where it's true if the pixel is considered a face pixel, and false if the pixel is not a face pixel.

Sign in to comment.

Shahid Mandokhail
Shahid Mandokhail on 18 Mar 2019
bro how you get this result of face which you uploaded?

3 Comments

Probably did it with color segmentation.
See the Color Thresholder app on the apps tab of the tool ribbon.
Okay Thaks sir.
I got the image with a gabor filter, this is not the exact function but it works.
Regards :)
function [ output_args ] = GaborFiltering( image )
%GABORFILTERING Summary of this function goes here
% Detailed explanation goes here
%vid = videoinput('winvideo', 1, 'YUY2_640x480');
%Read the original RGB input image
%image=getsnapshot(vid);;
%convert it to gray scale
image_gray=rgb2gray(image);
%show the image
figure(1);
imshow(image_gray);
title('Input Image');
face_image=im2double(image_gray);
%Gabor filter size 7x7 and orientation 90 degree
%declare the variables
gamma=0.5; %aspect ratio
theta=90; %orientation
bw=1.5; %bandwidth or effective width
lambda=3.5; % wavelength
pi=180;
for x=1:size(face_image,1)
for y=1:size(face_image,2)
x_theta=face_image(x,y)*cos(theta)+face_image(x,y)*sin(theta);
y_theta=-face_image(x,y)*sin(theta)+face_image(x,y)*cos(theta);
gb(x,y)= exp(-pi*(x_theta.^2/2*bw^2+ gamma^2*y_theta.^2/2*bw^2))*cos(2*pi/lambda*x_theta);
end
end
BImage = ~imbinarize(gb);
figure(2);
imshow(BImage);
title('filtered image');
end

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!