searching images

This is a discussion on searching images within the C Programming forums, part of the General Programming Boards category; I have many functions which require searching through images, i.e. Code: for(y = 0; y < h; y++) { for(x ...

  1. #1
    Registered User joed's Avatar
    Join Date
    Mar 2004
    Posts
    59

    searching images

    I have many functions which require searching through images, i.e.

    Code:
    for(y = 0; y < h; y++) {
      for(x = 0; x < w; x++) {
        do_whatever(x, y);
      }
    }
    I would like to do something cleaner, like:

    int max = w * h;
    int count = 0;

    Code:
    while(count < max) {
      int y = count / w;
      int x = count % w;  
      do_whatever(x, y);
      count++;
    }
    (Assume the / and % are replaced with fast methods, such as shifts...)

    Is there a better way, performance is important since each pixel is visited seperately.

    I'm mainly only trying to clean up my code before my project gets too large. The nested loops are too deep. Thanks,

    -Joe

  2. #2
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    I don't find the while() loop cleaner. It's harder to read. I doubt you're saving anything by using calculations insted of increments.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  3. #3
    Registered User joed's Avatar
    Join Date
    Mar 2004
    Posts
    59
    My solution was to not worry about the smaller functions, and split the larger ones into pieces. That took care of most of the ugly nesting. Your right, the other idea was counter-intuitive.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 06:20 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  3. Visual C++ 2005 linking and file sizes
    By Rune Hunter in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2005, 10:41 PM
  4. Searching and matching strings: segmentation fault
    By Smola in forum C Programming
    Replies: 18
    Last Post: 07-11-2005, 01:25 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21