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:
weight vector

Subject: weight vector

From: ramjitha shine

Date: 13 Dec, 2010 18:38:05

Message: 1 of 15

We want the code for finding mean and varience of a 3 dimensional image. Also we want to know about weight vector.And how it can be find out?

Subject: weight vector

From: Sean de

Date: 13 Dec, 2010 18:48:05

Message: 2 of 15

"ramjitha shine" <ramjishine@yahoo.com> wrote in message <ie5p6d$jug$1@fred.mathworks.com>...
> We want the code for finding mean and varience of a 3 dimensional image. Also we want to know about weight vector.And how it can be find out?

doc convn
doc stdfilt


What do you want to know about a weight vector? Here's a weight vector
weigth_vector = 1:10;

Subject: weight vector

From: ImageAnalyst

Date: 13 Dec, 2010 23:32:19

Message: 3 of 15

On Dec 13, 1:38 pm, "ramjitha shine" <ramjish...@yahoo.com> wrote:
> We want the code for finding mean and varience of a 3 dimensional image. Also we want to know about weight vector.And how it can be find out?

--------------------------------------------------------------------
Did you look up mean and variance in the help? There are functions
for that believe it or not. Here is some sample code:

a=rand(3,4,5) % Sample image

meanOfA = mean(a(:))
varOfA = var(a(:))

Subject: weight vector

From: ramjitha shine

Date: 14 Dec, 2010 15:47:22

Message: 4 of 15

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <304b7c29-7fc2-4b9a-af27-ab97a25cf0f1@b25g2000vbz.googlegroups.com>...
> On Dec 13, 1:38 pm, "ramjitha shine" <ramjish...@yahoo.com> wrote:
> > We want the code for finding mean and varience of a 3 dimensional image. Also we want to know about weight vector.And how it can be find out?
>
> --------------------------------------------------------------------
> Did you look up mean and variance in the help? There are functions
> for that believe it or not. Here is some sample code:
>
> a=rand(3,4,5) % Sample image
>
> meanOfA = mean(a(:))
> varOfA = var(a(:))
  


We know about the built in functions. We want code for finding mean and variance of an image.Actually we wrote a code for finding mean but it returns 0 as the mean value. What will be the mistake?


%mean of an image

img = imread('finger1.png');
s = size(img);
c=s(1)*s(2);
sum=0;
i = 1;
while(i<=s(1));
    j=1;
    while(j<=s(2));
        sum=sum+img(i,j);
        j=j+1;
    end
    i = i+1;
end
v=sum/c

Subject: weight vector

From: ImageAnalyst

Date: 14 Dec, 2010 16:03:13

Message: 5 of 15

Because you are summing uint8 values, so anytime you'd want to go past
255, you can't. You'd have to do something like
sum=sum + double(img(i,j));
if you wanted to use that primitive, inefficient, slow way.

Subject: weight vector

From: ramjitha shine

Date: 14 Dec, 2010 17:00:22

Message: 6 of 15

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <90a04221-621c-4207-9619-a9f92845f92f@g25g2000yqn.googlegroups.com>...
> Because you are summing uint8 values, so anytime you'd want to go past
> 255, you can't. You'd have to do something like
> sum=sum + double(img(i,j));
> if you wanted to use that primitive, inefficient, slow way.



Thank you so much sir. We got the value of mean. But when we calculate variance using the following code , the re sult obtained like

varn =
 2.8821e+003
the code is..../
varn =img = imread('finger1.png'); %reading an image
s = size(img); %size of an image
c=s(1)*s(2); % finding total number of elements in that matrix
%mean
sum=0;
i = 1;
while(i<=s(1)) %loop for adding each element in the matrix
    j=1;
    while(j<=s(2))
        sum=sum+double(img(i,j));
        j=j+1;
    end
    i = i+1;
end
meanm = sum/c % finding mean as sum / total number

%variance
c=s(1)*s(2);
sum=0;
i = 1;
while(i<=s(1)) % loop for finding variance as (i-mean)2
    j=1;
    while(j<=s(2))
        sum=sum+(((double(img(i,j)))-meanm)*((double(img(i,j)))-meanm));
        j=j+1;
    end
    i = i+1;
end
varn=sum/c

 

Subject: weight vector

From: ImageAnalyst

Date: 14 Dec, 2010 17:04:01

Message: 7 of 15

So? What's the problem?
Does it not agree with the way I said to do it (using the var()
function)?

Subject: weight vector

From: ramjitha shine

Date: 14 Dec, 2010 17:14:07

Message: 8 of 15

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <bc349d57-63aa-4354-9760-4fb4a12c1cf2@y31g2000vbt.googlegroups.com>...
> So? What's the problem?
> Does it not agree with the way I said to do it (using the var()
> function)?


Thank u sir.... We got the two values mean and varience correctly..

Subject: weight vector

From: ramjitha shine

Date: 14 Dec, 2010 18:03:05

Message: 9 of 15

"ramjitha shine" <ramjishine@yahoo.com> wrote in message <ie88kv$fnp$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <bc349d57-63aa-4354-9760-4fb4a12c1cf2@y31g2000vbt.googlegroups.com>...
> > So? What's the problem?
> > Does it not agree with the way I said to do it (using the var()
> > function)?
>
>
> Thank u sir.... We got the two values mean and varience correctly..


Did u know about weight vector w =[ w1 w2 w3 w4]??????/

Subject: weight vector

From: Steven_Lord

Date: 14 Dec, 2010 18:31:23

Message: 10 of 15



"ramjitha shine" <ramjishine@yahoo.com> wrote in message
news:ie8bgp$csq$1@fred.mathworks.com...
> "ramjitha shine" <ramjishine@yahoo.com> wrote in message
> <ie88kv$fnp$1@fred.mathworks.com>...
>> ImageAnalyst <imageanalyst@mailinator.com> wrote in message
>> <bc349d57-63aa-4354-9760-4fb4a12c1cf2@y31g2000vbt.googlegroups.com>...
>> > So? What's the problem?
>> > Does it not agree with the way I said to do it (using the var()
>> > function)?
>>
>>
>> Thank u sir.... We got the two values mean and varience correctly..
>
>
> Did u know about weight vector w =[ w1 w2 w3 w4]??????/

What about it?

You're going to need to give a whole lot more explanation of what EXACTLY
you are trying to do with weight vectors before anyone can offer any
constructive advice.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlab.wikia.com/wiki/FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: weight vector

From: ImageAnalyst

Date: 14 Dec, 2010 18:33:26

Message: 11 of 15

On Dec 14, 1:03 pm, "ramjitha shine" <ramjish...@yahoo.com> wrote:
> Did u know about weight vector w =[ w1 w2 w3 w4]??????/
---------------------------------------------------------------------------------------

No, I have no idea what that's about.
What is getting weighted?

Subject: weight vector

From: ramjitha shine

Date: 16 Dec, 2010 15:04:20

Message: 12 of 15

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ie5pp5$1ei$1@fred.mathworks.com>...
> "ramjitha shine" <ramjishine@yahoo.com> wrote in message <ie5p6d$jug$1@fred.mathworks.com>...
> > We want the code for finding mean and varience of a 3 dimensional image. Also we want to know about weight vector.And how it can be find out?
>
> doc convn
> doc stdfilt
>
>
> What do you want to know about a weight vector? Here's a weight vector
> weigth_vector = 1:10;

Did you know about weight of an image. it is given as w=[w1 w2 w3 w4].. how can we find it out?

Subject: weight vector

From: Sean de

Date: 16 Dec, 2010 15:51:08

Message: 13 of 15

"ramjitha shine" <ramjishine@yahoo.com> wrote in message
> Did you know about weight of an image. it is given as w=[w1 w2 w3 w4].. how can we find it out?

Of course! Here's a tutorial for calculating image weight:

%% Personal Camera
clc
fprintf('Weight of Image from my Personal Canon SD1100 Point & Shoot Camera:\n');
imgSize = 3.2*10^6; %Image Size, in Bytes (3.2MB)
HDSize = 500*10^9; %External Hard Drive Size in Bytes (500GB)
HDWeight = 0.4; %External Hard Drive Weight (lbf) (pound-force)

img_weight = (imgSize/HDSize)*HDWeight;
fprintf('The image weighs: %d lbf\n\n',img_weight);

%% X-CMT Images
fprintf('Weight of X-CMT Images for Work:\n');
imgSize = 800*10^6; %Image Size, in Bytes (800MB)

img_weight = (imgSize/HDSize)*HDWeight;
fprintf('The image weighs: %d lbf\n',img_weight);


%Sean

Subject: weight vector

From: Walter Roberson

Date: 16 Dec, 2010 16:13:05

Message: 14 of 15

On 16/12/10 9:51 AM, Sean de wrote:

> Of course! Here's a tutorial for calculating image weight:
>
> %% Personal Camera
> clc
> fprintf('Weight of Image from my Personal Canon SD1100 Point & Shoot
> Camera:\n');
> imgSize = 3.2*10^6; %Image Size, in Bytes (3.2MB)
> HDSize = 500*10^9; %External Hard Drive Size in Bytes (500GB)

Bug! A 3.2MB image is 3.2 * 2^20 bytes, whereas a 500 GB hard drive is
500 * 10^9 bytes. Your calculation is thus off by 2^20/10^6.

> HDWeight = 0.4; %External Hard Drive Weight (lbf) (pound-force)
>
> img_weight = (imgSize/HDSize)*HDWeight;
> fprintf('The image weighs: %d lbf\n\n',img_weight);

Do some numerical analysis, Sean! Is the image weight going to be an
integer? Clearly not! So you should be using a %f or %g format!

Your calculation is also only valid under the assumption that the hard
drive is stationary. When the drive is spinning, there are additional
forces acting on the platter that would change the weight of the image.
In particular, if the platters are vertical, the turning of the platters
would substantially exceed the acceleration due to gravity, and would
thus change the weight greatly.

;-)

Subject: weight vector

From: Sean de

Date: 16 Dec, 2010 16:32:05

Message: 15 of 15

Walter Roberson <roberson@hushmail.com> wrote in message <lUqOo.11662$Zf2.3114@newsfe17.iad>...
> On 16/12/10 9:51 AM, Sean de wrote:
>
> > Of course! Here's a tutorial for calculating image weight:
> >
> > %% Personal Camera
> > clc
> > fprintf('Weight of Image from my Personal Canon SD1100 Point & Shoot
> > Camera:\n');
> > imgSize = 3.2*10^6; %Image Size, in Bytes (3.2MB)
> > HDSize = 500*10^9; %External Hard Drive Size in Bytes (500GB)
>
> Bug! A 3.2MB image is 3.2 * 2^20 bytes, whereas a 500 GB hard drive is
> 500 * 10^9 bytes. Your calculation is thus off by 2^20/10^6.
>
> > HDWeight = 0.4; %External Hard Drive Weight (lbf) (pound-force)
> >
> > img_weight = (imgSize/HDSize)*HDWeight;
> > fprintf('The image weighs: %d lbf\n\n',img_weight);
>
> Do some numerical analysis, Sean! Is the image weight going to be an
> integer? Clearly not! So you should be using a %f or %g format!
>
> Your calculation is also only valid under the assumption that the hard
> drive is stationary. When the drive is spinning, there are additional
> forces acting on the platter that would change the weight of the image.
> In particular, if the platters are vertical, the turning of the platters
> would substantially exceed the acceleration due to gravity, and would
> thus change the weight greatly.
>
> ;-)

Arghh, you win!
The hard drive typically lies flat (rounded edges) so any rotational inertial effects should be negligible. However, you are right: as a structural engineer we want to design around the worst load case scenario, and thus: the hard drive, standing vertically, in full action, should be the winner. We probably should also account for at least a few inches of the fire-wire or usb cable, since the connection is in the middle of the side. I.e. when the hard drive is vertical it will be bearing some weight from the cable. I guess my image weight demo sucked since it was highly nonconservative; though it did present the general algorithm.

And yes, my chosen format was wrong too. For some stupid reason I was thinking %d was double, oops! Thanks for the correction.

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