From: Nehal on
http://img10.imageshack.us/img10/9923/samplekl.png

I have been trying to automatically crop the hand in my image... i have converted the image rgb2gray... thn im2bw to detect the hand... now i want to crop only the hand automatically...

i am working on my sign language project... so i have almost 1000 pictures like this...

so is there any way i can do it automatically in matlab...?

plz help me... :)
From: Jan Simon on
Dear Nehal,

> I have been trying to automatically crop the hand in my image... i have converted the image rgb2gray... thn im2bw to detect the hand... now i want to crop only the hand automatically...
>
> i am working on my sign language project... so i have almost 1000 pictures like this...
>
> so is there any way i can do it automatically in matlab...?

I see on the processed picture a white hand on black background. So far everything seems ok.
What exactly is missing? You just want to crop the image now? So you need to determine the minimal and maximal coordinates of white pixels??

Jan
From: Christopher on
"Nehal " <arnab620(a)yahoo.com> wrote in message <i0jv79$mtq$1(a)fred.mathworks.com>...
> http://img10.imageshack.us/img10/9923/samplekl.png
>
> I have been trying to automatically crop the hand in my image... i have converted the image rgb2gray... thn im2bw to detect the hand... now i want to crop only the hand automatically...
>
> i am working on my sign language project... so i have almost 1000 pictures like this...
>
> so is there any way i can do it automatically in matlab...?
>
> plz help me... :)

When you say 'crop', do you mean that you want to minimise the image frame so that only the white hand remains? Or do you want to retrieve the hand from the original image and leave the background black?

For the first solution, use regionprops():

% black and white image named BW
elements = regionprops(BW,'Area','BoundingBox');

% possible that more than one element exists, if this is the case, assume hand is the
% largest
areaArray = zeros(1,length(elements));
for i = 1:length(elements)
areaArray(i) = element(i).Area;
end

% index will point to your hand object
[maxArea, index] = max(areaArray);

% now get the bounding box of the hand
boxParams = elements(index).BoundingBox;

% now crop according to your parameters!
croppedIm = BW(boxParams(1):boxParams(1)+boxParams(3), boxParams(2):boxParams(2)+boxParams(4));

For the second problem, simply use your result as a mask:

croppedIm = zeros(size(originalIm));
for i = 1:size(originalIm,1)
for j = 1:size(originalIm,2)
if ~BW(i,j)
croppedIm(i,j) = 0; % black
else
croppedIm(i,j) = originalIm(i,j); % retain original value
end
end
end

Chris
From: Jan Simon on
Dear Christopher,

> For the second problem, simply use your result as a mask:
>
> croppedIm = zeros(size(originalIm));
> for i = 1:size(originalIm,1)
> for j = 1:size(originalIm,2)
> if ~BW(i,j)
> croppedIm(i,j) = 0; % black
> else
> croppedIm(i,j) = originalIm(i,j); % retain original value
> end
> end
> end

Or simpler:
croppedIm = zeros(size(origialIm));
croppedIm(~BW) = originalIm(~BW);

Jan
From: Nehal on
"Christopher " <christopher.badman(a)au.saabgroup.com> wrote in message <i0k46q$9vt$1(a)fred.mathworks.com>...
> "Nehal " <arnab620(a)yahoo.com> wrote in message <i0jv79$mtq$1(a)fred.mathworks.com>...
>
> When you say 'crop', do you mean that you want to minimise the image frame so that only the white hand remains? Or do you want to retrieve the hand from the original image and leave the background black?
>
> For the first solution, use regionprops():
>
> % black and white image named BW
> elements = regionprops(BW,'Area','BoundingBox');
>
> % possible that more than one element exists, if this is the case, assume hand is the
> % largest
> areaArray = zeros(1,length(elements));
> for i = 1:length(elements)
> areaArray(i) = element(i).Area;
> end
>
> % index will point to your hand object
> [maxArea, index] = max(areaArray);
>
> % now get the bounding box of the hand
> boxParams = elements(index).BoundingBox;
>
> % now crop according to your parameters!
> croppedIm = BW(boxParams(1):boxParams(1)+boxParams(3), boxParams(2):boxParams(2)+boxParams(4));
>
>
> Chris

i need to crop the image so that only the hand is there in the image reducing the black background as much as possible... i think your above quoted code will do the work... if it is the code to my job... can you explain the code to me plz...?

what does it mean "elements = regionprops(BW,'Area','BoundingBox');"
bw = image name
Area = ? (do i need to calculate the area ?)
BoundingBox = ?

Thanks in advance.