14755

ФИЛЬТРАЦИЯ ИЗОБРАЖЕНИЯ ОТ ИМПУЛЬСНЫХ ПОМЕХ

Лабораторная работа

Информатика, кибернетика и программирование

Лабораторная лабота №3 фильтрация изображения от импульсных помех Цель работы: фильтрация изображения от импульсных помех. Задание: Составить программу выполняющую фильтрацию изображения от импульсных помех методами функции рассеяния точки H1 H4 Код про...

Русский

2013-06-09

716.04 KB

5 чел.

Лабораторная лабота №3

"фильтрация изображения от импульсных помех"

Цель работы: фильтрация изображения от импульсных помех.

Задание:

Составить программу, выполняющую фильтрацию изображения от импульсных помех методами функции рассеяния точки (H1 – H4)

Код программы: 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

namespace lab3

{

   public partial class Form1 : Form

   {

       public Form1()

       {

           InitializeComponent();

       }

       

       public int[,] h1 = new int[,] { { 1, 1, 1 }, { 1, 2, 1 }, { 1, 1, 1 } };

       public int[,] h2 = new int[,] { { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 } };

       public int[,] h3 = new int[,] { { 1, 2, 1 }, { 2, 4, 2 }, { 1, 2, 1 } };

       public int[,] h4 = new int[,] { { 2, 1, 2 }, { 1, 2, 1 }, { 2, 1, 2 } };

       public int k1 = 10, k2 = 9, k3 = 16, k4 = 14;

       public string path;

       public Bitmap bmpOrig, bmpNoised, bmpH1, bmpH2, bmpH3, bmpH4;

       public Color[,] clr = new Color[3, 3];

       public int r1,r2,r3,r4,g1,g2,g3,g4,b1,b2,b3,b4;

       private void Form1_Load(object sender, EventArgs e)

       {

           

       }

       //

       //

       private void DPF()

       {

           bmpH1 = new Bitmap(bmpNoised);

           bmpH2 = new Bitmap(bmpNoised);

           bmpH3 = new Bitmap(bmpNoised);

           bmpH4 = new Bitmap(bmpNoised);

           for( int x = 1; x < bmpNoised.Width - 1; x++)

               for (int y = 1; y < bmpNoised.Height - 1; y++)

               {

                   clr[0,0] = bmpNoised.GetPixel(x - 1, y - 1);

                   clr[0,1] = bmpNoised.GetPixel(x - 1, y);

                   clr[0,2] = bmpNoised.GetPixel(x - 1, y + 1);

                   clr[1,0] = bmpNoised.GetPixel(x, y - 1);

                   clr[1,1] = bmpNoised.GetPixel(x, y);

                   clr[1,2] = bmpNoised.GetPixel(x, y + 1);

                   clr[2,0] = bmpNoised.GetPixel(x + 1, y - 1);

                   clr[2,1] = bmpNoised.GetPixel(x + 1, y);

                   clr[2,2] = bmpNoised.GetPixel(x + 1, y + 1);

                   r1 = (clr[0, 0].R * h1[0, 0] + clr[0,1].R * h1[0, 1] +

                       clr[0, 2].R * h1[0, 2] + clr[1, 0].R * h1[1, 0]+

                       clr[1, 1].R * h1[1, 1] + clr[1, 2].R * h1[1, 2]+

                       clr[2, 0].R * h1[2, 0] + clr[2, 1].R * h1[2, 1]+

                       clr[2, 2].R * h1[2, 2]) / k1;

                   g1 = (clr[0, 0].G * h1[0, 0] + clr[0, 1].G * h1[0, 1] +

                       clr[0, 2].G * h1[0, 2] + clr[1, 0].G * h1[1, 0] +

                       clr[1, 1].G * h1[1, 1] + clr[1, 2].G * h1[1, 2] +

                       clr[2, 0].G * h1[2, 0] + clr[2, 1].G * h1[2, 1] +

                       clr[2, 2].G * h1[2, 2]) / k1;

                   b1 = (clr[0, 0].B * h1[0, 0] + clr[0, 1].B * h1[0, 1] +

                       clr[0, 2].B * h1[0, 2] + clr[1, 0].B * h1[1, 0] +

                       clr[1, 1].B * h1[1, 1] + clr[1, 2].B * h1[1, 2] +

                       clr[2, 0].B * h1[2, 0] + clr[2, 1].B * h1[2, 1] +

                       clr[2, 2].B * h1[2, 2]) / k1;

                   

                   r2 = (clr[0, 0].R * h2[0, 0] + clr[0, 1].R * h2[0, 1] +

                       clr[0, 2].R * h2[0, 2] + clr[1, 0].R * h2[1, 0] +

                       clr[1, 1].R * h2[1, 1] + clr[1, 2].R * h2[1, 2] +

                       clr[2, 0].R * h2[2, 0] + clr[2, 1].R * h2[2, 1] +

                       clr[2, 2].R * h2[2, 2]) / k2;

                   g2 = (clr[0, 0].G * h2[0, 0] + clr[0, 1].G * h2[0, 1] +

                       clr[0, 2].G * h2[0, 2] + clr[1, 0].G * h2[1, 0] +

                       clr[1, 1].G * h2[1, 1] + clr[1, 2].G * h2[1, 2] +

                       clr[2, 0].G * h2[2, 0] + clr[2, 1].G * h2[2, 1] +

                       clr[2, 2].G * h2[2, 2]) / k2;

                   b2 = (clr[0, 0].B * h2[0, 0] + clr[0, 1].B * h2[0, 1] +

                       clr[0, 2].B * h2[0, 2] + clr[1, 0].B * h2[1, 0] +

                       clr[1, 1].B * h2[1, 1] + clr[1, 2].B * h2[1, 2] +

                       clr[2, 0].B * h2[2, 0] + clr[2, 1].B * h2[2, 1] +

                       clr[2, 2].B * h2[2, 2]) / k2;

                   r3 = (clr[0, 0].R * h3[0, 0] + clr[0, 1].R * h3[0, 1] +

                       clr[0, 2].R * h3[0, 2] + clr[1, 0].R * h3[1, 0] +

                       clr[1, 1].R * h3[1, 1] + clr[1, 2].R * h3[1, 2] +

                       clr[2, 0].R * h3[2, 0] + clr[2, 1].R * h3[2, 1] +

                       clr[2, 2].R * h3[2, 2]) / k3;

                   g3 = (clr[0, 0].G * h3[0, 0] + clr[0, 1].G * h3[0, 1] +

                       clr[0, 2].G * h3[0, 2] + clr[1, 0].G * h3[1, 0] +

                       clr[1, 1].G * h3[1, 1] + clr[1, 2].G * h3[1, 2] +

                       clr[2, 0].G * h3[2, 0] + clr[2, 1].G * h3[2, 1] +

                       clr[2, 2].G * h3[2, 2]) / k3;

                   b3 = (clr[0, 0].B * h3[0, 0] + clr[0, 1].B * h3[0, 1] +

                       clr[0, 2].B * h3[0, 2] + clr[1, 0].B * h3[1, 0] +

                       clr[1, 1].B * h3[1, 1] + clr[1, 2].B * h3[1, 2] +

                       clr[2, 0].B * h3[2, 0] + clr[2, 1].B * h3[2, 1] +

                       clr[2, 2].B * h3[2, 2]) / k3;

                  

                   r4 = (clr[0, 0].R * h4[0, 0] + clr[0, 1].R * h4[0, 1] +

                       clr[0, 2].R * h4[0, 2] + clr[1, 0].R * h4[1, 0] +

                       clr[1, 1].R * h4[1, 1] + clr[1, 2].R * h4[1, 2] +

                       clr[2, 0].R * h4[2, 0] + clr[2, 1].R * h4[2, 1] +

                       clr[2, 2].R * h4[2, 2]) / k4;

                   g4 = (clr[0, 0].G * h4[0, 0] + clr[0, 1].G * h4[0, 1] +

                       clr[0, 2].G * h4[0, 2] + clr[1, 0].G * h4[1, 0] +

                       clr[1, 1].G * h4[1, 1] + clr[1, 2].G * h4[1, 2] +

                       clr[2, 0].G * h4[2, 0] + clr[2, 1].G * h4[2, 1] +

                       clr[2, 2].G * h4[2, 2]) / k4;

                   b4 = (clr[0, 0].B * h4[0, 0] + clr[0, 1].B * h4[0, 1] +

                       clr[0, 2].B * h4[0, 2] + clr[1, 0].B * h4[1, 0] +

                       clr[1, 1].B * h4[1, 1] + clr[1, 2].B * h4[1, 2] +

                       clr[2, 0].B * h4[2, 0] + clr[2, 1].B * h4[2, 1] +

                       clr[2, 2].B * h4[2, 2]) / k4;

                   bmpH1.SetPixel(x, y, Color.FromArgb(r1, g1, b1));

                   bmpH2.SetPixel(x, y, Color.FromArgb(r2, g2, b2));

                   bmpH3.SetPixel(x, y, Color.FromArgb(r3, g3, b3));

                   bmpH4.SetPixel(x, y, Color.FromArgb(r4, g4, b4));

               }

       }

       //

       private void openFileToolStripMenuItem_Click(object sender, EventArgs e)

       {

           OpenFileDialog dialog = new OpenFileDialog();

           dialog.Filter = "bmp | *.bmp";

           if (dialog.ShowDialog() == DialogResult.OK)

           {

               this.path = dialog.FileName;

               bmpOrig = new Bitmap(this.path);

               pictureBox1.Image = bmpOrig;

           }

       }

       private void makeSomeNoiseToolStripMenuItem_Click(object sender, EventArgs e)

       {

           Random rand = new Random();

           bmpNoised = new Bitmap(bmpOrig);

           for (int i = 0; i < 2000; i++)

           {

               int rx = rand.Next(bmpNoised.Width);

               int ry = rand.Next(bmpNoised.Height);

               if ((rx != 0) && (rx != bmpNoised.Width-1) && (ry != 0) && (ry != bmpNoised.Height-1))

                   bmpNoised.SetPixel(rx, ry, Color.White);

               else

                   i--;

           }

           pictureBox2.Image = bmpNoised;

           pictureBox2.Refresh();

       }

       private void filterItToolStripMenuItem_Click(object sender, EventArgs e)

       {

           DPF();

           pictureBox3.Image = bmpH1;

           pictureBox3.Refresh();

           pictureBox4.Image = bmpH2;

           pictureBox4.Refresh();

           pictureBox5.Image = bmpH3;

           pictureBox5.Refresh();

           pictureBox6.Image = bmpH4;

           pictureBox6.Refresh();

       }

   }

}

Работа программы:

Вывод: я научился зашумлению изображения и последующей его фильтрации и удалению шумов.


 

А также другие работы, которые могут Вас заинтересовать

80747. The semantic structure and semantic changes of English words 28.43 KB
  Meaning can be described as a component of the word through which a concept is communicated. The complex relationships between referent (object, denoted by the word), concept and word are represented by a triangle: No immediate relation between word and referent it is established only through the concept.
80748. Word-building. Principle ways of word formation 30.03 KB
  The branch of lex-ly that studies word-building patterns is known as word-building or word formation. There are several types of Modern Eng. Word-building: Affixation consists in coining a new word by adding an affix or several affixes to some root morphemes. From the etymological O A are class-d into native and borrowed.
80749. Stylistics of the text 31.44 KB
  But there may be rearrangement of the plot structure. Two literary kinds of technique are used in presenting plot development: 1) retardation – withholding of the information until the appropriate time; 2) forshadowing – a look towards the future, a hint, a remark: The plot is simple (complicated), intricate...
80750. Adjective.Semantic and structural classification 28.26 KB
  In the sentence the adj. performs the function of an atribute and a predicative. As for morphological features, the Eng. Adj. having lost all its forms of gram. Argument with the noun, is distinguished only by the category of comparison. All the adj. are devided into 2 groups: qualitative and relative.
80752. The Periods in the History of English 26.74 KB
  The evolution of English in the 1,500 years of its existence in England has been an unbroken one. Within this development, however, it is possible to recognize three main periods. Like all divisions in history, the periods of the English language are matters of convenience and the dividing lines between them purely arbitrary.
80753. The Origin and Position of English 27.12 KB
  The English language of today is the language that has resulted from the history of the dialects spoken by the Germanic tribes who came to England in the manner described. It is impossible to say how much the speech of the Angles differed from that of the Saxons or that of the Jutes. The differences were certainly slight.
80754. The Verb. The Old English verb 28.59 KB
  The inflection of the verb in the Germanic languages is much simpler than it was in Indo-European times. A comparison of the Old English verb with the verbal inflection of Greek or Latin will show how much has been lost. Old English distinguished only two simple tenses by inflection a present and a past, and, except for one word...
80755. Methods of sentence analysis. Subordination grammar and constitutional grammar 26.75 KB
  The nominative parts of the simple sentence, subject, predicate, object, adverbial, attribute parenthetical enclosure addressing enclosure. The parts are arranged in a hierarchy. The ultimate and highest of this integral modification is the scheme as a whole.