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:
measure the height and width of an object

Subject: measure the height and width of an object

From: ng hu

Date: 9 Nov, 2004 03:45:31

Message: 1 of 7

how can I use the matlab to estimate the height & width of a object (
that took from the digital camera in jpeg format).

thank you

Subject: measure the height and width of an object

From: Brett Shoelson

Date: 9 Nov, 2004 12:18:42

Message: 2 of 7


"ng hu" <nghu@mmu.edu.my> wrote in message
news:eef1bf4.-1@webx.raydaftYaTP...
> how can I use the matlab to estimate the height & width of a object (
> that took from the digital camera in jpeg format).
>
> thank you

Take a look at REGIONPROPS. (Assuming you have the IPToolbox, of course.)
Brett

Subject: measure the height and width of an object

From: ng hu

Date: 10 Nov, 2004 03:01:23

Message: 3 of 7

dear brett,

Thank You. i will try it out.

cheers
nghu

Brett Shoelson wrote:
>
>
>
> "ng hu" <nghu@mmu.edu.my> wrote in message
> news:eef1bf4.-1@webx.raydaftYaTP...
>> how can I use the matlab to estimate the height & width of a
> object (
>> that took from the digital camera in jpeg format).
>>
>> thank you
>
> Take a look at REGIONPROPS. (Assuming you have the IPToolbox, of
> course.)
> Brett
>
>
>

Subject: measure the height and width of an object

From: ng hu

Date: 6 Dec, 2004 02:52:45

Message: 4 of 7

Dear Brett,

                First, I would like to thank you for helping me to
find out the
command "regionprops" to find the width and height of an object in a
picture.

                however, i did try the command in two short programs.
and facing some
errors.

1) measure the width / height of an box that appear in picture two
(box.jpg) after subtrating it from picture one (open1.jpg).

The matlab gave me an error message as below:

Error in ==> e:\MATLAB6p1\work\tong_cop4.m
On line 36 ==> stats(23)

??? Index exceeds matrix dimensions.

t1 = imread('e:\\open1.jpg');
t2 = imread('e:\\box2.jpg');
f1 = im2double(t1);
f2 = im2double(t2);
height=size(f1,1);
width= size(f1,2);
motion = zeros(height, width);
result = ones(height, width);
for h = 140:height,
        for w = 250:420,
              sub = abs(f2(h,w) - f1(h,w));
                 if (sub>0.001);
                      motion(h,w) = 1;
                      result(h,w) = f2(h,w);
                 end
        end
end

figure, imshow(motion);
figure, imshow(result);
L = bwlabel(motion);

stats = regionprops(L,'all');

stats(23)

I would be appreciated if you prompt out my mistake.

2) measure the width / height of a human that appear in picture two
(ong1.jpg) after subtrating it from picture one (open1.jpg).

t1 = imread('e:\\open1.jpg');
t2 = imread('e:\\tong1.jpg');
f1 = im2double(t1);
f2 = im2double(t2);
height=size(f1,1);
width= size(f1,2);
motion = zeros(height, width);
result = ones(height, width);
for h = 140:height,
        for w = 250:420,
              sub = abs(f2(h,w) - f1(h,w));
                 if (sub>0.160)
                      motion(h,w) = 1;
                      result(h,w) = f2(h,w);
                 end
        end
end
figure, imshow(motion);
figure, imshow(result);

L = bwlabel(motion);

stats = regionprops(L,'all');

stats(23)

I can manage to get the data as show below, however, i do not know
how
to figure out the width or height of the human from the data. Please
help.
                        
ans =
               Area: 2
           Centroid: [314 360.5000]
        BoundingBox: [313.5000 359.5000 1 2]
        SubarrayIdx: {[360 361] [314]}
    MajorAxisLength: 2.3094
    MinorAxisLength: 1.1547
       Eccentricity: 0.8660
        Orientation: 90
         ConvexHull: [7x2 double]
        ConvexImage: [2x1 uint8]
         ConvexArea: 2
              Image: [2x1 uint8]
        FilledImage: [2x1 uint8]
         FilledArea: 2
        EulerNumber: 1
            Extrema: [8x2 double]
      EquivDiameter: 1.5958
           Solidity: 1
             Extent: 1
       PixelIdxList: [2x1 double]
          PixelList: [2x2 double]

                I will be apprecaited if you can help on my problems.
I can forwarded
the jpg pictures to you if you want.

thank you.

cheers
nghu

>> "ng hu" <nghu@mmu.edu.my> wrote in message
>> news:eef1bf4.-1@webx.raydaftYaTP...
>>> how can I use the matlab to estimate the height & width of
a
>> object (
>>> that took from the digital camera in jpeg format).
>>>
>>> thank you
>>
>> Take a look at REGIONPROPS. (Assuming you have the IPToolbox,
of
>> course.)
>> Brett
>>
>>
>>

Subject: measure the height and width of an object

From: Brett Shoelson

Date: 6 Dec, 2004 11:09:06

Message: 5 of 7


"ng hu" <nghu@mmu.edu.my> wrote in message
news:eef1bf4.2@webx.raydaftYaTP...
> Dear Brett,
>
> First, I would like to thank you for helping me to
> find out the
> command "regionprops" to find the width and height of an object in a
> picture.
>
> however, i did try the command in two short programs.
> and facing some
> errors.
>
> 1) measure the width / height of an box that appear in picture two
> (box.jpg) after subtrating it from picture one (open1.jpg).
>
> The matlab gave me an error message as below:
>
> Error in ==> e:\MATLAB6p1\work\tong_cop4.m
> On line 36 ==> stats(23)
>
> ??? Index exceeds matrix dimensions.
>
> t1 = imread('e:\\open1.jpg');
> t2 = imread('e:\\box2.jpg');
> f1 = im2double(t1);
> f2 = im2double(t2);
> height=size(f1,1);
> width= size(f1,2);
> motion = zeros(height, width);
> result = ones(height, width);
> for h = 140:height,
> for w = 250:420,
> sub = abs(f2(h,w) - f1(h,w));
> if (sub>0.001);
> motion(h,w) = 1;
> result(h,w) = f2(h,w);
> end
> end
> end
>
> figure, imshow(motion);
> figure, imshow(result);
> L = bwlabel(motion);
>
> stats = regionprops(L,'all');
>
> stats(23)
>
> I would be appreciated if you prompt out my mistake.
>
> 2) measure the width / height of a human that appear in picture two
> (ong1.jpg) after subtrating it from picture one (open1.jpg).
>
> t1 = imread('e:\\open1.jpg');
> t2 = imread('e:\\tong1.jpg');
> f1 = im2double(t1);
> f2 = im2double(t2);
> height=size(f1,1);
> width= size(f1,2);
> motion = zeros(height, width);
> result = ones(height, width);
> for h = 140:height,
> for w = 250:420,
> sub = abs(f2(h,w) - f1(h,w));
> if (sub>0.160)
> motion(h,w) = 1;
> result(h,w) = f2(h,w);
> end
> end
> end
> figure, imshow(motion);
> figure, imshow(result);
>
> L = bwlabel(motion);
>
> stats = regionprops(L,'all');
>
> stats(23)
>
> I can manage to get the data as show below, however, i do not know
> how
> to figure out the width or height of the human from the data. Please
> help.
>
> ans =
> Area: 2
> Centroid: [314 360.5000]
> BoundingBox: [313.5000 359.5000 1 2]
> SubarrayIdx: {[360 361] [314]}
> MajorAxisLength: 2.3094
> MinorAxisLength: 1.1547
> Eccentricity: 0.8660
> Orientation: 90
> ConvexHull: [7x2 double]
> ConvexImage: [2x1 uint8]
> ConvexArea: 2
> Image: [2x1 uint8]
> FilledImage: [2x1 uint8]
> FilledArea: 2
> EulerNumber: 1
> Extrema: [8x2 double]
> EquivDiameter: 1.5958
> Solidity: 1
> Extent: 1
> PixelIdxList: [2x1 double]
> PixelList: [2x2 double]
>
> I will be apprecaited if you can help on my problems.
> I can forwarded
> the jpg pictures to you if you want.
>
> thank you.
>
> cheers
> nghu
>
>>> "ng hu" <nghu@mmu.edu.my> wrote in message
>>> news:eef1bf4.-1@webx.raydaftYaTP...
>>>> how can I use the matlab to estimate the height & width of
> a
>>> object (
>>>> that took from the digital camera in jpeg format).
>>>>
>>>> thank you
>>>
>>> Take a look at REGIONPROPS. (Assuming you have the IPToolbox,
> of
>>> course.)
>>> Brett
>>>
>>>
>>>

If ever a code needed vectorizing!!! You don't have to threshold your image
pixel by pixel. So let's start there:
Are the images the same size?

f1 = im2double(imread('e:\\open1.jpg'));
f2 = im2double(imread('e:\\tong1.jpg'));
[height,width] = size(f1);
% NOTE: No savings from preallocation here!
% If size(f1)==size(f2), use the following. OTHERWISE, do the same with
subimages of equal size
motion = im2bw(abs(f2-f1),0.160);
stats = regionprops(bwlabel(motion), 'all');

MUCH better!

Now, where did the line "stats(23)" come from? The error message is very
clear here: "??? Index exceeds matrix dimensions."
Type: whos stats
(or equivalent) to see what the variable contains. Is length(stats) >= 23?
If not, stats(23) will produce an error.
But note once you appropriately index your regions, you can look at the
major and minor axes lengths.
Does that set you on the right path?
Cheers,
Brett

Subject: measure the height and width of an object

From: ng hu

Date: 8 Dec, 2004 00:49:40

Message: 6 of 7

Dear Brett,
 
            Thank You for your guide, no more error found for the
"stats". and the regionprops provide the data for the actual width
and height for the box.

However, I am not really understand on the statement that
"appropriately index your regions" , as currently , the data from
"major and minor axes lengths" and the BoundingBox: [265.5000
251.5000 24 10] only refer to part of the hand of the human and not
the entire human body. I guest it may be caused by broken edges /
links of line of the human body layout ( in bank and white).

my questions:
1) should I use segmentation methods to link up all the edges of the
human body layout prior the regionprops command ?
2) "index your regions " approriately will help on this, but how to
index the region ( the entire human body" approriately ?

Thank You.

cheers
nghu

> But note once you appropriately index your regions, you can look at
> the major and minor axes lengths.
> Does that set you on the right path?
> Cheers,
> Brett
>
>
>

Subject: measure the height and width of an object

From: Brett Shoelson

Date: 8 Dec, 2004 10:44:56

Message: 7 of 7


"ng hu" <nghu@mmu.edu.my> wrote in message
news:eef1bf4.4@webx.raydaftYaTP...
> Dear Brett,
>
> Thank You for your guide, no more error found for the
> "stats". and the regionprops provide the data for the actual width
> and height for the box.
>
> However, I am not really understand on the statement that
> "appropriately index your regions" , as currently , the data from
> "major and minor axes lengths" and the BoundingBox: [265.5000
> 251.5000 24 10] only refer to part of the hand of the human and not
> the entire human body. I guest it may be caused by broken edges /
> links of line of the human body layout ( in bank and white).
>
> my questions:
> 1) should I use segmentation methods to link up all the edges of the
> human body layout prior the regionprops command ?
> 2) "index your regions " approriately will help on this, but how to
> index the region ( the entire human body" approriately ?
>
> Thank You.
>
> cheers
> nghu
>
>> But note once you appropriately index your regions, you can look at
>> the major and minor axes lengths.
>> Does that set you on the right path?
>> Cheers,
>> Brett
>>
>>
>>

I presume you are using bwlabel? That function numbers the regions; I simply
meant that if you properly refer to the region (by number) corresponding to
the object of interest, you should have no problem getting the properties
for the region. I don't really follow your questions with regard to the
regions of the entire human body.
Brett

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