filter.cpp

来自「the code environment s C++. it is in ima」· C++ 代码 · 共 85 行

CPP
85
字号
// Filter.cpp: implementation of the CFilter class.
//
//////////////////////////////////////////////////////////////////////

#include "Filter.h"
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFilter::CFilter()
{

}

CFilter::~CFilter()
{

}




void CFilter::MedianFilterClassical(float *InputImage, float *OutputImage, int NBL, int NBC)
{
    //void Sorting1Darray(float[], int);
	int n, i, j, k, l, counter=0;
	float vecx=0;
    
    cout<<"please enter the size of window :";
	cin >> n;
	while( n%2==0)
	{
     cout<<"Please enter a odd size for window :";
	 cin>>n;
	}

    float *vec;
    vec=(float *)malloc((n*n+1)*sizeof(float));

	//-----median filter--------
	for (i=n/2; i<NBL-n/2; i++)
		for (j=n/2; j<NBC-n/2; j++)
		{
			counter=0;
			for (k=i-n/2; k<=i+n/2; k++)
				for(l=j-n/2; l<=j+n/2; l++)
				{
					vec[counter]=InputImage[l+k*NBC];
					++counter;
				} 
				Sorting1Darray(vec, n);
				OutputImage[j+i*NBC]=vec[((n*n)/2)];
		}



      free(vec);

}






void CFilter::Sorting1Darray(float vec[], int n)
{
	float vecx;
	for (int w=0;w<(n*n);w++) 
		for(int g=0;g<(n*n);g++)
			if (vec[g]>vec[g+1])
			{
				vecx=vec[g];
				vec[g]=vec[g+1];
				vec[g+1]=vecx;
			}


}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?