how to program median-filter processing on 24 bitmap instead of 8 bitmap?

This is a discussion on how to program median-filter processing on 24 bitmap instead of 8 bitmap? within the Game Programming forums, part of the General Programming Boards category; Hi,guys! i have done a little change to the code snippets from some website capable of doing median-filter processing on ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Location
    china
    Posts
    16

    how to program median-filter processing on 24 bitmap instead of 8 bitmap?

    Hi,guys!
    i have done a little change to the code snippets from some website capable of doing median-filter processing on 24 bitmap,such code as following:

    Code:
    	typedef struct element{
    		UCHAR b;
    		UCHAR g;
    		UCHAR r;
    	}element;
    
    void CIMGutility::_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].b < window[min].b)
    						min = l;
    				//   Put found minimum element in its place
    				byte temp = window[j].b;
    				window[j].b = window[min].b;
    				window[min].b = temp;
    
    
    				min = j;
    				for (int l = j + 1; l < 9; ++l)
    					if (window[l].g < window[min].g)
    						min = l;
    				//   Put found minimum element in its place
    				temp = window[j].g;
    				window[j].g = window[min].g;
    				window[min].g = temp;
    
    
    				min = j;
    				for (int l = j + 1; l < 9; ++l)
    					if (window[l].r < window[min].r)
    						min = l;
    				//   Put found minimum element in its place
    				temp = window[j].r;
    				window[j].r = window[min].r;
    				window[min].r = temp;
    			}
    			//   Get result - the middle element
    
    			result[(m - 1) * (N - 2) + n - 1] = window[4];
    		}
    }
    but final output image doesn't seem to be correct result. so anything wrong with the above code.thank you !
    Last edited by haochao; 03-16-2012 at 11:17 AM. Reason: post detailly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Processing Bitmap Data (part deux)
    By bartus0 in forum Windows Programming
    Replies: 2
    Last Post: 12-10-2010, 01:36 AM
  2. Median filter help
    By JTEK24 in forum Tech Board
    Replies: 10
    Last Post: 07-16-2009, 07:05 PM
  3. Bitmap Program Help
    By The Brain in forum Windows Programming
    Replies: 4
    Last Post: 03-14-2009, 01:14 AM
  4. Processing Bitmap Data
    By w4ck0z in forum Windows Programming
    Replies: 4
    Last Post: 04-12-2005, 07:19 AM
  5. regarding bitmap size thru a program
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-24-2001, 04:42 AM

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