Graphics - Noise Reduction Technology-2 Dimensional Filtering

xiaoxiao2021-03-06  40

During the image acquisition, due to the instability of the electronic device, such as burrs, electromagnetic interference, etc.) generate some effects on the acquired image, this impact is called noise, noise reduction technology is to eliminate this noise effect in image processing. technology. Two-dimensional median filtering is one of the methods. Medium value filtering is a local image smoothing technology that belongs to nonlinear filters, which may be 1-dimensional or 2D because the image is a 2-dimensional pixel matrix, so use 2 dimensional medium value filtering. The 2 dimensional medium value filtering algorithm is: for a pixel matrix of an image, take a sub-matrix window in the target pixel, this window can be 3 * 3, 5 * 5, etc., according to the needs, in the window Pixel grayscale sorting, take a new gray value of the intermediate as the target pixel. Window examples, such as the OOOXOOOOOO, the target pixel, and the surrounding O composition 3 * 3 matrix Array, then sort the grayscale of the 9 elements, to sort the new grayscale value of X after sorting In this way, the median filtering of pixel X is completed, and then iterates to filter other pixels. The following is based on this theory with BCB6 to achieve median filtering algorithm // ------------------------------ BCB6 program #include < vcl.h> #pragma hdrstop # include #include "unit1.h" #include "file1.h"

#pragma pack (1)

/ * Program: graphics - median filtering of: sboom (Lingch) Date: December 26 * /// BMP file header struct BITMAPFILEHEADER_ {short type; int bfSize; short re1, re2; int Offbits;}; // BMP Information Head Struct BitmapInfo_ {Long Size; Long Width, Height; Short Planes, Bitcount; Long Comp, SizeImg; Long Xpels, Ypels; Long Used, Important;}; // BMP Color Table Item Struct Color_ {char Blue, Green, Red;}; // ------ Correct the data of the BMP color table to BCB TColor. TColor * SwitchColor (unsigned char r, unsigned char g, unsigned char b) {tcolor * re = new tcolor; * re = (r | g << 8 | b << 16); * RE = * RE & 0x00FFFFFFFFFFff; Return RE;}

Void xxx () {file * f = fopen ("f: //7.bmp", "rb"); if (f == null) / * Judgment file is open success * / {showMessage ("File Open Error" Return;}

FSeek (f, 0, 0); // move to the beginning

// ---------- Read BMP file head BitmapFileHeader_ * bmph = new bitmapfileHeader_ (); if (FREAD ((Char *) BMPH, SIZEOF (BitmapFileHeader_), 1, f) == null) {showMessage ("File read error"); return;} // ----------- Read BMP information head bitmapinfo_ * bmpi = new bitmapinfo_ (); if (FREAD ((char *) BMPI, SIZEOF (BitmapInfo_ ), 1, f) == null) {ShowMessage ("file read error2"); return;} fseek (f, bmph-> offbits, 0); // ---------- Display some information Form1-> edit1-> text = INTSTR (BMPH-> bfsize); Form1-> edit2-> text = INTTOSTR (bmpi-> width); form1-> edit3-> text = INTTOSTR (bmpi-> height); Form1- > Edit4-> text = INTOSTR (bmpi-> comp); form1-> edit5-> text = INTOSTR (BMPI-> USED);

INT I, J, K, L, WC, POS; long n = bmph-> bfsize- bmph-> offbits; // Pixel total color_ * Image = new color_ [n]; // bit map matrix color_ * newimage = New color_ [n]; // Filtering bitmap matrix

Fread (image, n * 3, 1, f); // read bitmap matrix

// -------- First COPY does not process the original image first line, because the first line cannot take the window Memcpy (void *), (void *) Image, (BMPI-> Width 1 ) * 3);

// - !!!!!!!!!!!!!! The following start window is 3 × 3 median filter !!!!!!!!!!!!!!!! Int ns = bmpi-> Width 1; // Start processing starting point int ne = n-bmpi-> width-2; // start processing endpoint unsigned char * psr = new unsigned char [9]; // Red window unsigned char * psg = new Unsigned char [9]; // Green window unsigned char * psb = new unsigned char [9]; // Blue window unsigned char TEMP;

Color_ cc; for (i = ns; i <= ne; i ) {// --------- Red window // - 3 * 3 window matrix first line PSR [0] = image [ I-bmpi-> width 1] .red; psr [1] = image [i-bmpi-> width 1] .red; psr [2] = image [i-bmpi-> width 1] .red; // --- 3 * 3 Window matrix second line PSR [3] = image [i-1] .red; psr [4] = image [i] .red; psr [5] = image [i 1] .red; // --- 3 * 3 Window matrix third line PSR [6] = image [i bmpi-> width-1] .red; psr [7] = image [i bmpi-> width]. Red; psr [8] = image [i bmpi-> width 1] .red; // --------- Green window // --- 3 * 3 window matrix first bank PSG [0 ] = Image [i-bmpi-> width 1] .Green; psg [1] = image [i-bmpi-> width 1] .green; psg [2] = image [i-bmpi-> width 1 ] .green; // --- 3 * 3 Window matrix second line PSG [3] = image [i-1] .green; psg [4] = image [i] .green; psg [5] = image [ i 1] .green; // --- 3 * 3 Window matrix third line PSG [6] = image [i bmpi-> width-1] .Green; psg [7] = image [i BMPI-> width] .Green; psg [8] = image [i bmpi-> width 1] .green

// --------- Blue window // - 3 * 3 Window matrix first line PSB [0] = image [i-bmpi-> width 1] .bo; psb [1] = Image [i-bmpi-> width 1] .bo; psb [2] = image [i-bmpi-> width 1] .boe; // --- 3 * 3 window matrix second line PSB [3 ] = image [i-1] .bo; psb [4] = image [i] .bo; psb [5] = image [i 1] .boe; // --- 3 * 3 Window matrix third line PSB [6] = image [i bmpi-> width-1] .bo; psb [7] = image [i bmpi-> width] .bo; psb [8] = image [i bmpi-> width 1] .bo

// -------- Select sort for (j = 0; j <9; j ) {// ----------- red sort POS = J; for (k = j; K <9; k ) {IF (PSR [K] Width 1) * 3); // ------ Display Graphic Color_ Color; Tcolor * Tc; IF (BMPI-> Width% 4 == 0) // ----------- Because BMP images 4 byte align wc = bmpi-> width / 4 * 4; ELSE WC = (BMPI-> Width / 4 1 ) * 4;

转载请注明原文地址:https://www.9cbs.com/read-76469.html

New Post(0)