Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Automatic Crop [The Hand Only]

Subject: Automatic Crop [The Hand Only]

From: Nehal

Date: 2 Jul, 2010 05:59:05

Message: 1 of 20

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... :)

Subject: Automatic Crop [The Hand Only]

From: Jan Simon

Date: 2 Jul, 2010 07:11:05

Message: 2 of 20

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

Subject: Automatic Crop [The Hand Only]

From: Christopher

Date: 2 Jul, 2010 07:24:10

Message: 3 of 20

"Nehal " <arnab620@yahoo.com> wrote in message <i0jv79$mtq$1@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

Subject: Automatic Crop [The Hand Only]

From: Jan Simon

Date: 2 Jul, 2010 07:42:07

Message: 4 of 20

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

Subject: Automatic Crop [The Hand Only]

From: Nehal

Date: 2 Jul, 2010 13:09:04

Message: 5 of 20

"Christopher " <christopher.badman@au.saabgroup.com> wrote in message <i0k46q$9vt$1@fred.mathworks.com>...
> "Nehal " <arnab620@yahoo.com> wrote in message <i0jv79$mtq$1@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.

Subject: Automatic Crop [The Hand Only]

From: Nehal

Date: 2 Jul, 2010 13:55:19

Message: 6 of 20

"Nehal " <arnab620@yahoo.com> wrote in message <i0kodg$104$1@fred.mathworks.com>...
> "Christopher " <christopher.badman@au.saabgroup.com> wrote in message <i0k46q$9vt$1@fred.mathworks.com>...
> > "Nehal " <arnab620@yahoo.com> wrote in message <i0jv79$mtq$1@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 have tried...
BW=imread (the image);
then executed all the code line by line provided by you... then when i try to see the "croppedIm"... it shows nothing... what am I doing wrong...?

Subject: Automatic Crop [The Hand Only]

From: Image Analyst

Date: 2 Jul, 2010 16:56:04

Message: 7 of 20

Maybe it's displaying it in the range 0-255. did you try to display it like this:
imshow(croppedIm, []); % Note the use of [] to scale for display.

Subject: Automatic Crop [The Hand Only]

From: Nehal

Date: 2 Jul, 2010 17:11:04

Message: 8 of 20

"Image Analyst" <imageanalyst@mailinator.com> wrote in message <i0l5n4$dd4$1@fred.mathworks.com>...
> Maybe it's displaying it in the range 0-255. did you try to display it like this:
> imshow(croppedIm, []); % Note the use of [] to scale for display.

OKey... i am posting what i have done and what it's saying....

clear all
 BW=imread('sample_tif.tif');
 % 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) = elements(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));
Warning: Integer operands are required for colon operator when used as index
Warning: Integer operands are required for colon operator when used as index

there r 2 warnings... what does it mean...?

and...
imshow(croppedIm, []);
what value should i use in []..? i hav tried some.. bt still not working.

Subject: Automatic Crop [The Hand Only]

From: ImageAnalyst

Date: 2 Jul, 2010 21:12:30

Message: 9 of 20

You need to round the bounding box coordinates - it's giving you non-
integer values (long story...). That's why I didn't mention that
method. I was going to suggest using any() in each direction and then
using find() to find the first and last index in each direction. If
you want to try it that way, and can't figure it out on your own, let
me know.

You don't put anything in the [] and then it will find the min and max
itself and map the min to 0 and the max to 255. For the binary image
you have, it will leave 0 as 0 and make all the 1's 255 so you can
then see them.

Subject: Automatic Crop [The Hand Only]

From: Nehal

Date: 3 Jul, 2010 04:55:04

Message: 10 of 20

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <bbdeaa8e-e6fe-4c8c-a606-b28478fe3836@d8g2000yqf.googlegroups.com>...
> You need to round the bounding box coordinates - it's giving you non-
> integer values (long story...). That's why I didn't mention that
> method. I was going to suggest using any() in each direction and then
> using find() to find the first and last index in each direction. If
> you want to try it that way, and can't figure it out on your own, let
> me know.
>
> You don't put anything in the [] and then it will find the min and max
> itself and map the min to 0 and the max to 255. For the binary image
> you have, it will leave 0 as 0 and make all the 1's 255 so you can
> then see them.

sorry..didn't understand the method... either way.. i need it to be done... so it would be a great help if you could fix the 1st code or help me with the process that you mentioned in your last post...

NB: i am a beginner. that's why i think i am not understanding most of the things you r saying... sorry... :)

Subject: Automatic Crop [The Hand Only]

From: ImageAnalyst

Date: 3 Jul, 2010 14:25:46

Message: 11 of 20

Nehal:
All right, here is a demo for you using your image. Note that this
demo is many, many times longer than the handful of lines it takes to
actually do the work because I had to fix up the image you posted to
binarize it and get rid of the white border. There are also many
lines in there strictly for illustrative demo purposes to display
results and help you understand it better. The actual code would
actually be only about 4 or 5 lines. (And I give credit to Walter
Roberson for the tip about using the any() function.)
-ImageAnalyst

clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;

% Read in a user's hand.
folder = 'C:\Documents and Settings\userName\My Documents\Temporary
stuff';
baseFileName = 'samplekl.png';
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
% Display the original gray scale image.
subplot(2, 3, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.

% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
    % The user posted a color image, so convert it to monochrome;
    grayImage = rgb2gray(grayImage);
end
% The user has a white border around the image, let's crop it
grayImage2 = imcrop(grayImage, [83 31 639 479]);
% Create a binary image.
binaryImage = grayImage2 > 0;
% Display the original gray scale image.
subplot(2, 3, 2);
imshow(binaryImage, []);
title('Cropped Binary Image', 'FontSize', fontSize);

% Finally, now we have the image that the user should have posted to
begin with.


horizontal = any(grayImage2, 1);
subplot(2, 3, 3);
bar(horizontal);
title('Pixels in Columns', 'FontSize', fontSize);

vertical = any(grayImage2, 2);
subplot(2, 3, 4);
bar(vertical);
title('Pixels in Rows', 'FontSize', fontSize);

% Find the first and last columns and rows.
column1 = find(horizontal, 1, 'first');
column2 = find(horizontal, 1, 'last');
row1 = find(vertical, 1, 'first');
row2 = find(vertical, 1, 'last');

% Display the rectangle over the original image.
subplot(2, 3, 5);
imshow(binaryImage, []);
hold on;
xBox = [column1 column2 column2 column1 column1];
yBox = [row1 row1 row2 row2 row1];
plot(xBox, yBox);
title('Bounding rectangle', 'FontSize', fontSize);

% Crop the image
croppedImage = binaryImage(row1:row2, column1:column2);
subplot(2, 3, 6);
imshow(croppedImage, []);
title('cropped image', 'FontSize', fontSize);

Subject: Automatic Crop [The Hand Only]

From: Nehal

Date: 3 Jul, 2010 17:55:13

Message: 12 of 20

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <281f274d-f45d-479a-9b8d-9759651a37c1@z10g2000yqb.googlegroups.com>...
> Nehal:
> All right, here is a demo for you using your image. Note that this
> demo is many, many times longer than the handful of lines it takes to
> actually do the work because I had to fix up the image you posted to
> binarize it and get rid of the white border. There are also many
> lines in there strictly for illustrative demo purposes to display
> results and help you understand it better. The actual code would
> actually be only about 4 or 5 lines. (And I give credit to Walter
> Roberson for the tip about using the any() function.)
> -ImageAnalyst

thanks a lot... the code is working... but i need to make clear something...

1. the image was taken by a faulty webcam... i'll try to collect some good samples... and i'll again check and post here if it's working.

2. the image was already converted to binary... i've converted it and then posted it... so why i am converting it grb2gray again in the code...?
I mean the image is already converted rgb2gray and then gray2binary... so why i am assuming that the image is in rgb and then again going though the conversion precess..?

3. after sub-plotting the converted binary image... i am getting the same image except the white border... but isn't it me who is creating the white border in the 1st place...? can't i do it without doing that...?
I mean i am creating the white border then cropping out the image with the black background only... but the image was already there without the white border... so why can't i use that...?

i'll take some samples with a good web-cam hopefully within 24hrs... and then i'll again post here...

and i am really really grateful for your help... thanks you very much.. :)

Subject: Automatic Crop [The Hand Only]

From: ImageAnalyst

Date: 3 Jul, 2010 18:33:22

Message: 13 of 20

I don't know how it came to be a 24 bit RGB image with a white
border. Possibly you saved out the figure, not the image array, and
the figure is a color figure by default so whatever function you used
to save it saved it as a 24 bit BMP format. That may also explain the
white border. If you have access to the original binary image, then
you don't have to worry about all that code and can just start using
the original binary image immediately. I HAD to do all that because
you didn't provide me with the original binary image.

You shouldn't get the same image except for the white border. It
should be cropped in close to the hand. Try downloading your image
from the web site (like I did) and trying it with that and you'll
see. Otherwise look at the horizontal and vertical arrays and look at
the first few elements, then try to figure out why they are not zero.
If they're not zero, then there must be some non-zero pixels near the
top or left edge of your image.

Subject: Automatic Crop [The Hand Only]

From: Nehal

Date: 4 Jul, 2010 15:08:06

Message: 14 of 20

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <65818ceb-c0eb-4dd6-9fa2-99e4fde5f43d@x27g2000yqb.googlegroups.com>...
> I don't know how it came to be a 24 bit RGB image with a white
> border. Possibly you saved out the figure, not the image array, and
> the figure is a color figure by default so whatever function you used
> to save it saved it as a 24 bit BMP format. That may also explain the
> white border. If you have access to the original binary image, then
> you don't have to worry about all that code and can just start using
> the original binary image immediately. I HAD to do all that because
> you didn't provide me with the original binary image.
>
> You shouldn't get the same image except for the white border. It
> should be cropped in close to the hand. Try downloading your image
> from the web site (like I did) and trying it with that and you'll
> see. Otherwise look at the horizontal and vertical arrays and look at
> the first few elements, then try to figure out why they are not zero.
> If they're not zero, then there must be some non-zero pixels near the
> top or left edge of your image.

i think the image was converted automatically when i was uploading it in imageshack web site...
anywaz... i have taken some samples today with a new web cam... but your code is not working... i tried the code line by line from the top... but didn't work... then i tried to do from the line...
"% Finally, now we have the image that the user should have posted to begin with."
with declaring the grayImage & binaryImage variable properly... but it still doesn't work...

after putting the following command... it shows a blank sub-plot space...

% Create a binary image.
binaryImage = grayImage2 > 0;
% Display the original gray scale image.
subplot(2, 3, 2);
imshow(binaryImage, []);

but no binary image... can you plz help me...?

and i am sharing the new sample here: http://www.mediafire.com/?tolmjzyiuzn
i have uploaded it to a file sharing site so that the image does not change and i have posted the original grb image.

the image i posted above has zero in the first few horizontal and vertical arrays...

so plz can u help me now...? how to crop this image...?

Subject: Automatic Crop [The Hand Only]

From: ImageAnalyst

Date: 4 Jul, 2010 15:20:12

Message: 15 of 20

Because you're starting with a totally different type of image it of
course required some slight modifications:

clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;

% Read in a user's hand.
folder = 'C:\Documents and Settings\tk2013\My Documents\Temporary
stuff';
baseFileName = 'sample.tif';
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
% Display the original gray scale image.
subplot(2, 3, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.

% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
    % The user posted a color image, so convert it to monochrome;
    grayImage = rgb2gray(grayImage);
end
% The user has a white border around the image, let's crop it
% grayImage = imcrop(grayImage, [83 31 639 479]);
% Create a binary image.
binaryImage = grayImage == 255;
% Display the original gray scale image.
subplot(2, 3, 2);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);

horizontal = any(binaryImage, 1);
subplot(2, 3, 3);
plot(horizontal, 'ro-');
title('Pixels in Columns', 'FontSize', fontSize);

vertical = any(binaryImage, 2);
subplot(2, 3, 4);
plot(vertical, 'ro-');
title('Pixels in Rows', 'FontSize', fontSize);

% Find the first and last columns and rows.
column1 = find(horizontal, 1, 'first');
column2 = find(horizontal, 1, 'last');
row1 = find(vertical, 1, 'first');
row2 = find(vertical, 1, 'last');

% Display the rectangle over the original image.
subplot(2, 3, 5);
imshow(binaryImage, []);
hold on;
xBox = [column1 column2 column2 column1 column1];
yBox = [row1 row1 row2 row2 row1];
plot(xBox, yBox);
title('Bounding rectangle', 'FontSize', fontSize);

% Crop the image
croppedImage = binaryImage(row1:row2, column1:column2);
subplot(2, 3, 6);
imshow(croppedImage, []);
title('cropped image', 'FontSize', fontSize);

Subject: Automatic Crop [The Hand Only]

From: Nehal

Date: 4 Jul, 2010 16:14:06

Message: 16 of 20

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <4647ad4b-9804-422a-b3da-f70812f0d775@d16g2000yqb.googlegroups.com>...
> Because you're starting with a totally different type of image it of
> course required some slight modifications:

wow... it works in this image.... i'll try it with the other images i have for my project... and i'll post here if those works properly or i face any problem...

this was a big help... many many many thanks... :D

Subject: Automatic Crop [The Hand Only]

From: Christopher

Date: 4 Jul, 2010 23:52:16

Message: 17 of 20

"Nehal " <arnab620@yahoo.com> wrote in message <i0qc0d$6ms$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <4647ad4b-9804-422a-b3da-f70812f0d775@d16g2000yqb.googlegroups.com>...
> > Because you're starting with a totally different type of image it of
> > course required some slight modifications:
>
> wow... it works in this image.... i'll try it with the other images i have for my project... and i'll post here if those works properly or i face any problem...
>
> this was a big help... many many many thanks... :D

A logical solution... but just remember that not all images will be ideal, and depending on how you arrived upon your logical mask you may return regions of white (i.e. identified foreground) that aren't part of the intended object of interest (i.e. your hand). This can commonly occur due to noise and external objects. It seems that the solution proposed will crop according to the minimum/maximum rows and columns containing ANY white pixel and will therefore be inclusive of any noise included.

Again.. this is perfectly fine if you ensure that your images are clearly defined with no background objects. My original solution attempted to determine which white object was the object of interest by assuming it was the largest. The problem you had when attempting to execute was correctly identified that the 'BoundingBox' parameter returns fractional bounds and any indexing must be integer. So then, you simply round it - I would suggest rounding the left and top parameters up (pushing rightward and down) and rounding the right and bottom parameters down (pushing leftward and up). The resulting loss is that of less that a pixel around the border - not really a large quantity assuming your hand would be on the order of 100 pixels wide itself.

croppedIm = originalImage(ceil(boxParams(1)):floor(boxParams(1)+boxParams(3)),ceil(boxParams(2)):floor(boxParams(2)+boxParams(4)));

Chris

Subject: Automatic Crop [The Hand Only]

From: Nehal

Date: 6 Jul, 2010 13:37:03

Message: 18 of 20

"Christopher " <christopher.badman@au.saabgroup.com> wrote in message <i0r6rg$3fp$1@fred.mathworks.com>...
> "Nehal " <arnab620@yahoo.com> wrote in message <i0qc0d$6ms$1@fred.mathworks.com>...
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <4647ad4b-9804-422a-b3da-f70812f0d775@d16g2000yqb.googlegroups.com>...
> > > Because you're starting with a totally different type of image it of
> > > course required some slight modifications:
> >
> > wow... it works in this image.... i'll try it with the other images i have for my project... and i'll post here if those works properly or i face any problem...
> >
> > this was a big help... many many many thanks... :D
>
> A logical solution... but just remember that not all images will be ideal, and depending on how you arrived upon your logical mask you may return regions of white (i.e. identified foreground) that aren't part of the intended object of interest (i.e. your hand). This can commonly occur due to noise and external objects. It seems that the solution proposed will crop according to the minimum/maximum rows and columns containing ANY white pixel and will therefore be inclusive of any noise included.
>
> Again.. this is perfectly fine if you ensure that your images are clearly defined with no background objects. My original solution attempted to determine which white object was the object of interest by assuming it was the largest. The problem you had when attempting to execute was correctly identified that the 'BoundingBox' parameter returns fractional bounds and any indexing must be integer. So then, you simply round it - I would suggest rounding the left and top parameters up (pushing rightward and down) and rounding the right and bottom parameters down (pushing leftward and up). The resulting loss is that of less that a pixel around the border - not really a large quantity assuming your hand would be on the order of 100 pixels wide itself.
>
> croppedIm = originalImage(ceil(boxParams(1)):floor(boxParams(1)+boxParams(3)),ceil(boxParams(2)):floor(boxParams(2)+boxParams(4)));
>
> Chris

sorry... i am not that advanced to understand this method. But yes, all the time, the images will not be ideal. For the time being, i am assuming the images are ideal and then working on it. I'll remember it and try to do something more with it.

and it would be a help if u could post some more details.

Thanks.

Subject: Automatic Crop [The Hand Only]

From: Nehal

Date: 6 Jul, 2010 14:02:07

Message: 19 of 20

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <4647ad4b-9804-422a-b3da-f70812f0d775@d16g2000yqb.googlegroups.com>...
> Because you're starting with a totally different type of image it of
> course required some slight modifications:
>

I have 15 signs (sign language signs) captured in video (avi format) with 200 frames each. I extracted each frames from each of the videos using a function. Then I have cropped it with the code you have provided. But as I have 15x200=3,000 images, i want to do it automatically. Like I want matlab to:

1. Read a video with my command.
2. It will read the 1st frame from that video.
3. Then it will save the 1st frame as a TIF image in a folder called “Frames”
4. It will read the saved image.
5. Crop the hand from the image (i do not need to see the intermediate stages)
6. Convert it to a 20x30 image (column 20 : row 30)
7. Save it to an another folder named “Cropped”
8. Then it will read the 2nd frame from the video again.
9. Then go through all the process of saving the frame, cropping the hand and saving it to the folder “Cropped”.
10. This process will go through all the frames that the video contains. That mean all the 200 frames.

or
It will extract all the frames and save it as image. Then read the images one by one, crop the hand and save it to another folder.

I have the code for extracting the frames. I am posting it here:
% the function to extract the frames as TIF from a video file
function avi2image(aviname)

mov = aviread(aviname);
info=aviinfo(aviname);

[m,n]=size(mov);
[c,d]=size(aviname);

for j = 1:info.NumFrames
   
    if j<10
        imwrite(mov(1,j).cdata, strcat(aviname(1,1:d-4),'01_00',int2str(j),'.tif'));
    elseif j<100
       imwrite(mov(1,j).cdata, strcat(aviname(1,1:d-4),'01_0',int2str(j),'.tif'));
   else
       imwrite(mov(1,j).cdata, strcat(aviname(1,1:d-4),'01_',int2str(j),'.tif'));
   end
   
 end
% end of the function

now if I want to do the frame extraction and cropping all together, what should I do? I was trying to create a function using a loop that will extract the frames and then crop the hand one by one from each image. But I am confused how to make matlab read the images one by one automatically where all the images have different names (increasing order).

I am sharing 1 video file here: http://www.4shared.com/file/QgSCEI4I/sample.html

Could you plz help me..?

Subject: Automatic Crop [The Hand Only]

From: Nehal

Date: 9 Jul, 2010 14:14:04

Message: 20 of 20

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <4647ad4b-9804-422a-b3da-f70812f0d775@d16g2000yqb.googlegroups.com>...
> Because you're starting with a totally different type of image it of
> course required some slight modifications:
>

I do not need all the steps I've posted in my last post here.
I was trying to crop multiple image with the code you have provided... I wrote a function to do that... but it's not working... giving some errors...cannot find a variable... could u plz look at it...? plz... ?
I have posted my problem here: http://www.mathworks.com/matlabcentral/newsreader/view_thread/286532

Thanks.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us