"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(f2f1),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
