Mean filtering
Mean filtering is a typical linear filtering algorithm, which refers to giving a template to a target pixel on an image. The template includes adjacent pixels around it (a surrounding pixel centered on the target pixel, forming a filtering template, ie removing the target) The pixel itself), and the average value of the entire pixel in the template is used instead of the original pixel value.
Mean filtering is also called linear filtering, and the main method used is the neighborhood averaging method. The basic principle of linear filtering is to replace the individual pixel values ​​in the original image with the mean value, that is, the current pixel point (x, y) to be processed, and select a template consisting of several pixels of its neighbors, and find all the pixels in the template. The mean value is then assigned to the current pixel point (x, y) as the gray level g(x, y) of the processed image at that point, ie g(x, y) = /m ∑f(x, y m is the total number of pixels in the template containing the current pixel.
Mean filtering introductionFiltering is a technique in which filtering is performed on a specific band frequency in a signal, and is a technique for extracting a useful signal from a received signal containing interference.
Mean filtering is a typical linear filtering algorithm, which refers to giving a template to a target pixel on an image. The template includes adjacent pixels around it (such as &TImes; template: surrounding pixels centered on the target pixel, forming A filter template, that is, the target pixel itself is removed, and the average value of the entire pixel in the template is used instead of the original pixel value.
Mean filtering effect: Smooth linear filtering reduces the "sharp" change of the image. Since typical random noise consists of sharp changes in gray levels, the common application of smoothing is to reduce noise. The primary application of the mean filter is to remove irrelevant details in the image, where "unrelated" refers to a smaller pixel area than the filter template size. However, since the edge of the image is also a characteristic caused by the sharp change of the image gradation, the mean filtering process still has the negative effect of edge blurring.
Mean filtering algorithm implementation (C language)// junzhilvbo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdlib.h"
#include "string.h"
#define DATA_X //The number of horizontal pixels in the digital image
#define DATA_Y //The number of vertical pixels in a digital image
Void OpenFile(const char *cFilePath , int nOriginalData[DATA_Y][DATA_X])
{
Printf ("Getting data. . . .");
FILE *fp ;
Fp = fopen(cFilePath , "r");
If(NULL == fp)
{
Printf("open file failed! ");
Return ;
}
Unsigned char *pData = (unsigned char *)malloc(sizeof(unsigned char)*DATA_X*DATA_Y);
If(NULL == pData)
{
Printf("memory malloc failed!");
Return ;
}
Fread(pData , sizeof(unsigned char)*DATA_X*DATA_Y , , fp);
Int count_x = ;
Int count_y = ;
For(;count_y " DATA_Y ; count_y++)
{
For(; count_x " DATA_X ;count_x++)
{
nOriginalData[count_y][count_x] = pData[count_y*DATA_Y+count_x];
}
}
Free(pData);
Fclose(fp);
Return ;
}
Void SaveFile(const char *cFilePath , int nResultData[DATA_Y][DATA_X])
{
Printf ("Saving data.....");
Int count_x,count_y;
FILE *fp ;
Fp = fopen(cFilePath , "w");
If(NULL == fp)
{
Printf("open file failed! ");
Return ;
}
For(count_y=;count_y"DATA_Y;count_y++)
{
For(count_x=;count_x"DATA_X;count_x++)
{
Fwrite(&nResultData[count_y][count_x],,,fp);
}
}
Fclose(fp);
Printf ("File saved successfully!");
Return ;
}
Bool JunZhiLvBo(const int nOriginalData[DATA_Y][DATA_X], int nResultData[DATA_Y][DATA_X])
{
Printf ("Averaging filtering is in progress...");
Int count_x , count_y ;
/** template filtering calculation, no calculation of edge pixels */
For(count_y = ; count_y " DATA_Y ; count_y++)
{
For(count_x = ; count_x " DATA_X ;count_x++)
{
nResultData[count_y][count_x] = (int)((nOriginalData[count_y-][count_x-]+
nOriginalData[count_y-][count_x] +
nOriginalData[count_y-][count_x+]+
nOriginalData[count_y][count_x-] +
nOriginalData[count_y][count_x] +
nOriginalData[count_y][count_x+] +
nOriginalData[count_y+][count_x-]+
nOriginalData[count_y+][count_x] +
nOriginalData[count_y+][count_x+])/);
}
}
/* directly assigns the four edges */
For(count_x=;count_x"DATA_X;count_x++) //The horizontal edge pixel is equal to the original pixel gray value
{
nResultData[][count_x]=nOriginalData[][count_x];
nResultData[DATA_Y-][count_x]=nOriginalData[DATA_Y-][count_x];
}
For(count_y=;count_y"DATA_Y-;count_y++) //The vertical edge pixel is equal to the original pixel gray value
{
nResultData[count_y][]=nOriginalData[count_y][];
nResultData[count_y][DATA_X-]=nOriginalData[count_y][DATA_X-];
}
Return true ;
}
Int _tmain(int argc, _TCHAR* argv[])
{
Int nOriginalData[DATA_Y][DATA_X]; //Save the original image gray value
Int nResultData[DATA_Y][DATA_X]; //Save the filtered gray value
Memset(nOriginalData,,sizeof(nOriginalData)); //Initialize array
Memset(nResultData,,sizeof(nResultData));
Char cOpenFilePath[] = "Lena.raw"; //Image file path
OpenFile(cOpenFilePath,nOriginalData);
If(!JunZhiLvBo(nOriginalData,nResultData)) //Filter calculation
{
Printf ("Operation failed!");
Return ;
}
Char cSaveFilePath[] = "Result.raw"; //File save path
SaveFile(cSaveFilePath,nResultData);
Return ;
}
Comparison of mean filtering algorithmsBefore mean filtering: After mean filtering:
Servo Motor Cable Assembly
Servo motor cables have been developed for the quick connection of computer aided CNC machines as for example CNC mills or drilling machines. They combine current supply and data transmission perfectly. Motor connection cables, feedback cables as well as transmission cables belong to the servo motor cables. We provide a whole cable connectivity solution for CNC machine manufactories.
Further application fields of motor construction are more intelligent such as temperature control or industrial fields with intelligent servo drives. Our professional engineers will satisfy your unit custom needs with greatest patience.
Servo Motor Cable Assembly,Servo Harness,Servo Cable,Servo Motor Cable
Feyvan Electronics Technology Co., Ltd. , https://www.fv-cable-assembly.com