1

I was wondering if anyone could help me vectorize these for loops I have attempt a few time but have not been able to thanks in advance.

pixel_depth = 16; 
pixel_range = 2^pixel_depth -1;

for i=1:height

    for j=1:width

        for k=1:gaussianComponents

           mean(i,j,k) = rand*pixel_range; 

           weights(i,j,k) = 1/gaussianComponents; 

           pixelDeviation(i,j,k) = diviationNew; 

       end

    end

 end

Thank you for any help....

1 Answer 1

5
mean = rand(height, width, gaussianComponents) * pixel_range;

weights = 1/gaussianComponents * ones(height, width, gaussianComponents);

pixelDeviation = diviationNew * ones(height, width, gaussianComponents);

Note that mean is a bad name for a variable, as it will hide the mean function.

Sign up to request clarification or add additional context in comments.

6 Comments

I am quite new to matlab so this may be a simple error, thank you for your answer I added this into matlab but it gives me an error saying repmat could have to many arguments, could you help with the error?
It seems to mee you want to assign every entry of weight the same value, which weight=ones(height,width,gaussianComponents)*value will do (like for pixelDeviation). Note also that mean in the answer above is not yet scaled by pixelRange.
@arne: You are absolutely right. Thank you. I've now fixed my answer (hopefully).
thank you that has fixed that, I still have a little problem I think it is from this line of code mean = rand(height, width, gaussianComponents); this does not seem to work I am not sure why I am finding it hard to debug compared to the original line as it is so different. I just wanted to check that it is doing the same idea? thank you again.
thanks arne.b I think the scaling issue it my current problem do you know how I could scale the mean by pixel range without a four loop? thank you.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.