finding mean minimum and maximum values

This is a discussion on finding mean minimum and maximum values within the C Programming forums, part of the General Programming Boards category; I am trying to write a function that finds the mean maximum and minimum values for an image yes an ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    43

    finding mean minimum and maximum values

    I am trying to write a function that finds the mean maximum and minimum values for an image yes an image, Which is nothing to extraordinarily because it is just a two d matrix of pixel values. So here it was i have so far two for loops that go through the row and column coordinates of the for loop what i am confused on is how to get the mean min and maxium value i know kind of how to do it in words but now so much code

    so here are the for loops

    for(r=0; r < no_of_rows; r++) {
    for(c=0; c < no_of_cols; c++) {

    }
    }

    these will cycle through the row and collum coordinates but how i find the values of the maximum and minim i do not know

    please hlep

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,211
    I am assuming you have a 2D array named data declared as something like;
    Code:
        whatever_data_type  data[no_of_rows][no_of_cols];
    and populated with a set of values before your loop.

    Before the loop, declare variables named maximum and minimum, and set both of them to data[0][0].

    In the body of the loop, compare data[r][c] with minimum and maximum. It is a nobrainer that, if data[r][c] is less than minimum, the value of minimum needs to be updated and that if data[r][c] is greater than maximum, the value of maximum needs to be updated.

    This approach works regardless of the actual data type (whatever_data_type can be int, float, double, .....) as long as it is possible to compare values.
    Right 98% of the time, and don't care about the other 3%.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Invalid Output of Minimum and Maximum Value in Array
    By georgio777 in forum C Programming
    Replies: 10
    Last Post: 09-19-2009, 03:17 AM
  2. Replies: 2
    Last Post: 02-08-2009, 08:26 PM
  3. Displaying Minimum and Maximum values from input
    By mgardnertech in forum C Programming
    Replies: 1
    Last Post: 06-29-2008, 08:47 PM
  4. Maximum and Minimum Values
    By swaugh in forum C Programming
    Replies: 7
    Last Post: 12-16-2006, 08:43 PM
  5. Replies: 2
    Last Post: 10-31-2002, 06:27 PM

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