Got something to write about? Check out our Article Builder.

Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 630
Number of posts: 1070

This Forum Only
Post New Thread

Report
For Loop , Need Help Posted by manojnK1979 on 26 Oct 2009 at 7:56 PM
Hi

I try to use a block operation in a image 400x400. It works fine . Now if i use different image this code does not work. So please any one tell me how to add padding zeros using the for loop.

We have a function in matlab, but i want to use in this for loop same thing , please any one tell me how to do that . my code


I  = imread('5.jpg');
Block size (bk) = 50;
  for j = 1:bk:size(rgb,2)
         for i = 1:bk:size(rgb,1)
         block = gray(i:(i+(bk-1)), j:(j+(bk-1)));

/// do some operation 

      end
  end
 figure,imshow(z);


The above code works fine if the image size is divided by Block size, but if the image size if different , then there is a error like this


??? Index exceeds matrix dimensions.

Error in ==> block_gradient at 12
block = gray(i:(i+(bk-1)), j:(j+(bk-1)));

So please any one help me to fix this . How to add padding inside this loop, so that this will work for all image.

Thank You




 
Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2010 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
bootstrapLabs Logo A BootstrapLabs project.