//     image  - input image
//     result - output image
//     N      - width of the image
//     M      - height of the image
void _medianfilter(const element* image, element* result, int N, int M)
{
   //   Move window through all elements of the image
   for (int m = 1; m < M - 1; ++m)
      for (int n = 1; n < N - 1; ++n)
      {
         //   Pick up window elements
         int k = 0;
         element window[9];
         for (int j = m - 1; j < m + 2; ++j)
            for (int i = n - 1; i < n + 2; ++i)
               window[k++] = image[j * N + i];
         //   Order elements (only half of them)
         for (int j = 0; j < 5; ++j)
         {
            //   Find position of minimum element
            int min = j;
            for (int l = j + 1; l < 9; ++l)
            if (window[l] < window[min])
               min = l;
            //   Put found minimum element in its place
            const element temp = window[j];
            window[j] = window[min];
            window[min] = temp;
         }
         //   Get result - the middle element
         result[(m - 1) * (N - 2) + n - 1] = window[4];
      }
}


void medianfilter(element* image, element* result, int N, int M)
{
   //   Check arguments
   if (!image || N < 1 || M < 1)
      return;
   //   Allocate memory for signal extension
   element* extension = new element[(N + 2) * (M + 2)];
   //   Check memory allocation
   if (!extension)
      return;
   //   Create image extension
   for (int i = 0; i < M; ++i)
   {
      memcpy(extension + (N + 2) * (i + 1) + 1, image + N * i, N * sizeof(element));
      extension[(N + 2) * (i + 1)] = image[N * i];
      extension[(N + 2) * (i + 2) - 1] = image[N * (i + 1) - 1];
   }
   //   Fill first line of image extension
   memcpy(extension, extension + N + 2, (N + 2) * sizeof(element));
   //   Fill last line of image extension
   memcpy(extension + (N + 2) * (M + 1), extension + (N + 2) * M, (N + 2) * sizeof(element));
   //   Call median filter implementation
   _medianfilter(extension, result ? result : image, N + 2, M + 2);
   //   Free memory
   delete[] extension;
}

if anyone familiar with this bcb please lend me your hand...thank you so much!

What is the problem, exactly?

void _medianfilter(const..

Names with leading underscores are reserved by the C++ Standard article 17.4.3.1.2 for implementation-specific names in the global scope. It is not recommended to use names with leading underscores in any code that you write or use. If you need to "hide" a function, standard practice is to put it in a "detail" namespace, or append "_impl" to the end of the name.

For the rest, you haven't really asked a question, at least, not a specific one.

BTW: the code you posted is not specific to Borland C++Builder, it is just normal C++ code (well actually it's C-style code... only the new/delete thing is from C++, the rest is just C).

I'm sorry..the problem is the code cannot be implement in BCB right? coz the "element" does not exist in BCB...and also some of it..\
this code is to do the filtering using dev stdrd C++ compiler..but i want to use it in BCB..so which part from the code I need to modify??

Just change element to any type that makes sense (like unsigned char or float). And it should work.

how can I define this first code

void _medianfilter(const element* image, element* result, int N, int M)

and this second code

void medianfilter(element* image, element* result, int N, int M)

to actually working because this two codes is used inside another "void".
because what I am doing now is to do image processing after I click a button.

void __fastcall TForm1::filterClick(TObject *Sender)
{
//first code and 
//second code are applied here.
}

I hope someone understand my problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.