Skocz do zawartości

Algorytmy odszumiania obrazka


Recommended Posts

Witam, dopiero zaczynam sudia na grafice komputerowej i o programowaniu pojęcie mam prawie żadne. Za zadanie mam zrobić dokumentację na temat programu do odszumiania obrazków. Czy byłby ktoś na tyle wielkoduszny aby wyjaśnić poniższy kod? Z góry ogromnie dziękuję!

 

 

 

 

01 public static PGM ApplyMeanFilter(PGM inputImage, int iterationCount)
02 {
03	 PGM outputImage = new PGM(inputImage.Size.Width, inputImage.Size.Height);
04	 
05	 for (int iteration = 0; iteration < iterationCount; iteration++)
06	 {
07		 for (int x = 0; x < inputImage.Size.Width - 1; x++)
08		 {
09			 for (int y = 0; y < inputImage.Size.Height - 1; y++)
10			 {
11				 //find average intensity of neighbors of current-pixel
12				 List<int> validNeighbors = inputImage.GetAllNeighbors(x, y);
13				 double averageIntensity = validNeighbors.Average();
14				 
15				 //set average as new intensity of current-pixel
16				 outputImage.Pixels[x, y] = (short)averageIntensity;
17			 }
18		 }
19		 
20		 //set input to next iteration
21		 inputImage = outputImage.Clone();
22	 }
23	 
24	 return (outputImage);
25 }

 

 

oraz drugi:

 

 

 

 

01 public static PGM ApplyMedianFilter(PGM inputImage, int iterationCount)
02 {
03	 PGM outputImage = new PGM(inputImage.Size.Width, inputImage.Size.Height);
04	 
05	 for (int iteration = 0; iteration < iterationCount; iteration++)
06	 {
07		 for (int x = 0; x < inputImage.Size.Width - 1; x++)
08		 {
09			 for (int y = 0; y < inputImage.Size.Height - 1; y++)
10			 {
11				 //get all neighbors of current-pixel
12				 List<int> validNeighbors = inputImage.GetAllNeighbors(x, y);
13				 
14				 //sort and find middle intensity value from all neighbors
15				 validNeighbors.Sort();
16				 int medianIndex = validNeighbors.Count / 2;
17				 short medianPixel = (short)validNeighbors[medianIndex];
18				 
19				 //set median-pixel as intensity of current-pixel
20				 outputImage.Pixels[x, y] = medianPixel;
21			 }
22		 }
23		 
24		 //set input to next iteration
25		 inputImage = outputImage.Clone();
26	 }
27	 
28	 return (outputImage);
29 }
Link to post
Share on other sites

Podany kod jest częścią jakiś bibliotek. Jedyne co mogę stwierdzić z powyżsszego kodu to że:

 

1. Chodzisz po sąsiednich pixelach i robisz średnia z sąsiednich pixeli, przypuszczam że używana jest maska 3x3.

2. To samo tylko jest robiona mediana.

  • Popieram 1
Link to post
Share on other sites

Dołącz do dyskusji

Możesz dodać zawartość już teraz a zarejestrować się później. Jeśli posiadasz już konto, zaloguj się aby dodać zawartość za jego pomocą.

Gość
Odpowiedz w tym wątku...

×   Wklejono zawartość z formatowaniem.   Usuń formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Odnośnik został automatycznie osadzony.   Przywróć wyświetlanie jako odnośnik

×   Przywrócono poprzednią zawartość.   Wyczyść edytor

×   Nie możesz bezpośrednio wkleić grafiki. Dodaj lub załącz grafiki z adresu URL.

  • Ostatnio przeglądający   0 użytkowników

    Brak zarejestrowanych użytkowników przeglądających tę stronę.

×
×
  • Dodaj nową pozycję...