Announcement

Collapse
No announcement yet.

C++ programing help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Ohhhhhh. ah-ha!! For the median, we can't use the function "median, medfilt2,..." etc. to find the actuall median. I remember reading something about (N+1)/2 where N is the number of items in the 3x3 which is (9+1)/2 which equals five so it will give the middle number. But how can we input the 9 inputs into the equation? we cant use the sort function either, we have to create that also. Just found out today.

    So we have to create: a median filter and a sorting code to put the matrix #'s in order from least to greatest.

    Im kinda getting it a little bit. Im just mad that we are learning a new language and expects us to be done in 3 weeks. I won't give up though, I just need a tutorial. Ive watched some youtube videos on Matlab but mostly they are using the built in functions.

    Thanks again Cam
    My CB For Sale

    Comment


      #17
      No worries man. I reackon your best bet for learning the language syntax is simply the matlab help files like TNwagon mentioned. The loop structures etc that you're used to from C++ are all there its just a matter of checking how they're done in matlab. Just like porting any language to any other.

      Yep, so once you have the 3x3 you need to sort them and grab the middle number. There are many sorting algorithms out there. The amount of items to be sorted isn't too great so I wouldn't worry too much about efficiency. Just google sorting algorithms. Then implement this in matlab. Once again these will involve nested loops.

      This is one of the simplest: http://en.wikipedia.org/wiki/Bubble_sort
      Members Ride Thread

      Comment


        #18
        Ok now Im lost all over again dude, I have no clue whats going on now, Im getting too stressed about something that I know I cant learn in a month, Im staying up to almost 4am and getting up for my classes from 8am-4pm everyday and Im getting nowhere fast since I have 4 other classes to do homework in also. I seriously need help because (help sort-Matlab) is not making sense. All I see is one for loop used in their sort and bubble sort has nested loops with if, while, and for.

        I am trying my hardest to help myself reading and trying to understand, its all foreign...Im not trying to make excuses, I WONT QUIT. I just need help besides just clues...like some type of example with comments to explain it. I can google search all day and read through page after page and still wont get it.
        My CB For Sale

        Comment


          #19
          Originally posted by Cam View Post
          You're on the wrong track a little bit. That bit I put with the x-1,y etc are the matrix indeces that you want to pull the numbers from to form the 3 x 3 window that you will then perform the median function on. So if you had the start of the picture as:

          0 0 0 0
          0 1 3 2
          0 4 5 3
          0 6 3 2

          You would run the window over the whole picture starting at index x=2, y=2. So to extract your 3 x 3 window you need to grab the number from indeces originalPicture(x-1,y-1), originalPicture(x-1, y), .....etc like above.

          That will give you a 3 x 3 of:

          0 0 0
          0 1 3
          0 4 5

          Then you get the median of this and put it into position (x,y) in a whole new matrix of the same size as the original.

          Then you do all this again for position (2,3)....extract the window, get the median, put it in the new matrix etc...
          Do you have to put zero padding around the matrix or will matlab accept it?
          My CB For Sale

          Comment


            #20
            I don't have MATLAB installed anywhere anymore so I can't really help with exact code. But a bubble sort algorithm might go something like this:

            Code:
            while (numSwaps != 0)
              numSwaps = 0
              for (i=1 to 8)
                if (window(i) > window(i+1))
                  temp = window(i)
                  window(i) = window(i+1)
                  window(i+1) = temp
                  numSwaps++
                endif
              endfor
            endwhile
            If you don't put zero pading around it then you'll end up with a slightly smaller image than the one you started with. You still need to start at index 2,2 though so that you can extract the 3 x 3 window from around that number.
            Last edited by Cam; 07-09-2009, 01:18 AM.
            Members Ride Thread

            Comment


              #21
              Did you have a hand in creating Matlab? lol
              I wish I had the background you have, thats a gift in itself.

              This is what we have so far to try to get the median without zero padding(which we need) and we cant get it to slide through the entire matrix to get all the medians.


              M=magic(5);% random matrix
              m=5;n=5;
              for i =2:1:m
              for j =2:1:n

              k = M(1:3,1:3);% kernel,gives you the 3x3 matrix
              v = k(;%turns matrix into (v)ector
              l2g=sort(v);% sorts numbers from least to greatest
              med=l2g(5);

              end
              end
              My CB For Sale

              Comment


                #22
                PM'd you
                Members Ride Thread

                Comment

                Working...
                X